I have been using GLSceneViewer1.Buffer.GetPickedObject( x, y ) to pick GLscene objects in a GLViewerMouseDown event per the pick demo. I need to select an object, change the color, with a left mouse click and deselect with another left mouse click, and if another object is selected it is deselected. It seems that TGLSceneObject needs a property IsPicked : boolean for me to be able to achieve this. If someone knows away of doing this with out modifying GLScene would be cool. Here is the code I wrote it sort of works but sort of doesn't. SetSelected( Selected, SelectedColor ) just changes the color of the selected object.
procedure TForm32.GLSceneViewer1MouseDown( Sender : TObject; Button : TMouseButton; Shift : TShiftState; X, Y : Integer );
var
Selected : TGLSceneObject;
AButton : TGLMouseButton;
begin
AButton := TGLMouseButton( Button );
// if an object is picked...
Selected := ( GLSceneViewer1.Buffer.GetPickedObject( x, y ) as TGLSceneObject );
case AButton of
mbLeft:
begin
if( Selected <> UnSelected ) then
begin
if( Assigned( Selected ) ) then
begin
SetSelected( Selected, SelectedColor );
StatusBar1.Panels[0].Text := 'Selected';
UnSelected := Selected;
end
else
if( not Assigned( Selected ) ) then
begin
UnSelected.Material.FrontProperties.Emission.Color:= clrBlack;
UnSelected.Material.FrontProperties.Ambient.Color := clrGray20;
UnSelected.Material.FrontProperties.Diffuse.Color := clrGray80;
StatusBar1.Panels[0].Text := 'Unselected';
UnSelected := Selected;
end;
end;
end;
end;
end;
To me this would be easier:
procedure TForm32.GLSceneViewer1MouseDown( Sender : TObject; Button : TMouseButton; Shift : TShiftState; X, Y : Integer );
var
Selected : TGLSceneObject;
begin
Selected := ( GLSceneViewer1.Buffer.GetPickedObject( x, y ) as TGLSceneObject );
if( not Selected.IsPicked ) then
SetSelected( Selected, SelectedColor )
else
SetSelected( Selected, UnSelectedColor );
end;