Public
Authored by tonya2689

add keyboard events to vtk c++

hello,
please i need help i have a simple code vtk c++ witch shows an actor i want to control this actor by keyborad i tryed
this code but it not work i guess that there is something' s missing so please can any body help me ??

class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{      
  public:
    static KeyPressInteractorStyle* New();
    vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);
   

    virtual void OnKeyPress() 
    {
		double handpos[3]={0.7,0,2.6};
		//double *handpos= act->GetPosition();
		

		// Get the keypress
      vtkRenderWindowInteractor *rwi = this->Interactor;
	 // vtkRenderer *rend=new(vtkRenderer);
      std::string key = rwi->GetKeySym();
 
      // Output the key that was pressed
      std::cout << "Pressed " << key << std::endl;
 
      // Handle an arrow key
     if(key == "Up")
        { 
		
		myTrans->Translate(handpos[0]+1, handpos[1], handpos[2]);	
		handpos[0]++;
	    act->SetPosition(handpos[0], handpos[1], handpos[2]);
		renderer->Render();
		renderWindow->Render();
        }
   // Forward events
      vtkInteractorStyleTrackballCamera::OnKeyPress();
    }
 
};
vtkStandardNewMacro(KeyPressInteractorStyle);
30 Bytes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment