我一直在使用GLSceneViewer1.Buffer.GetPickedObject(x,y)來選擇GLViewceneMouseDown事件中的GLscene對象。我需要選擇一個對象,改變顏色,用鼠標左鍵單擊,取消選擇另一個鼠標左鍵單擊,如果選擇了另一個對象,則取消選擇它。看來,TGLSceneObject需要一個屬性IsPicked:布爾值爲我能夠實現這一點。如果有人知道不用修改GLScene這樣做會很酷。這是我寫的那種作品的代碼,但有些沒有。 SetSelected(Selected,SelectedColor)僅更改所選對象的顏色。GLScene採摘
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;
對我來說這將是更容易:
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;