2016-09-13 5 views
-1

私はGLSceneViewer1.Buffer.GetPickedObject(x、y)を使用して、pickデモごとにGLViewerMouseDownイベントでGLsceneオブジェクトを選択しています。私は、オブジェクトを選択し、左のマウスクリックで色を変更し、別の左のマウスクリックで選択を解除し、別のオブジェクトが選択されていない場合は選択を解除する必要があります。 TGLSceneObjectには、これを実現するために私がIsPicked:booleanプロパティを必要とするようです。 GLSceneを修正することで誰かがこれをやっていることを知っていれば、クールだ。ここで私はそれを書いたコードは作品の並べ替えの並べ替えはありません。 SetSelected(Selected、SelectedColor)は、選択したオブジェクトの色を変更するだけです。私にGLScene picking

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; 

答えて

0

いくつかは、私が「didnのこれ、ソースコードを配布する必要が必要となるソースコードを修正することで、私のGLSceneライブラリを壊す必要があるかどうかで議論した後、私にとって理想的なように思えますが、私は私の問題に対する答えとして次のコードを考え出しました。答えは、私がCurrentSelectionという名前のTGLSceneObjectバッファオブジェクトを維持することでした。

procedure TForm32.GLSceneViewer1MouseDown(Sender : TObject; Button : TMouseButton; Shift : TShiftState; X, Y : Integer); 
    //CurrentSelection : TGLSceneObject; //TForm private declaration 
    //Selected : TGLSceneObject; //TForm private declaration 
    begin 
    Selected := (GLSceneViewer1.Buffer.GetPickedObject(x, y) as TGLSceneObject); 
     if(Selected <> nil) then //Avoid access violation error 
     begin 
      if(Assigned(CurrentSelection)) then //If CurrentSelection is not nil deselect it 
      SetSelectedColor(CurrentSelection, UnSelectedColor); 

      if(Selected = CurrentSelection) then 
      begin 
       //has the same object been clicked then deselect it and clear the buffer object 
       SetSelectedColor(Selected, UnSelectedColor); 
       CurrentSelection := nil; 
      end 
      else 
      begin 
       //if no object is selected select an object, set the color and assign the object to the buffer 
       SetSelectedColor(Selected, SelectedColor); 
       CurrentSelection := Selected; 
      end; 
     end; 
    end; 

は、上記のコードが使用されているマウスボタンをチェックしませんTGLSceneObject

procedure TForm32.SetSelectedColor(Selected : TGLSceneObject; Color : TColorVector); 
    begin 
    Selected.Material.FrontProperties.Ambient.Color := Color; 
    Selected.Material.FrontProperties.Diffuse.Color := Color; 
    Selected.Material.FrontProperties.Emission.Color:= clrBlack; 
    end; 

の色を設定したが、別のオブジェクトが選択された場合、私は、オブジェクトを選択オブジェクトの選択を解除することができ現在のオブジェクトの選択を解除します。

私はそれを修正して、選択解除されたオブジェクトを元の色/マテリアルに設定する必要がありますが、それは比較的単純である必要があります。

乾杯:

関連する問題