2016-09-13 4 views
-1

GLSceneViewer1.Buffer.GetPickedObject (x, y)를 사용하여 선택 데모 당 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; 

의 색상을 설정하지만, 다른 개체가 선택 될 때 나는 개체를 선택 개체의 선택을 해제 할 수 있습니다 현재 오브젝트의 선택을 취소합니다.

선택 취소 된 개체를 원래 색/재료로 설정하려면 수정해야하지만 비교적 간단해야합니다.

건배 :)

관련 문제