I'm having trouble trying to make a kind of FPS in VTK. What I need is for the user to be able to move the camera with the mouse (without clicking any button) for pitch, yawn, etc, and to move forward, backward, left or right using the keyboard (your standard FPS). I though it will be easy using any of the interaction styles but its seems that none support this kind of functionality. Any ideas what I could use?
Thanks
There is the "flight" camera - vtkInteractorStyleFlight
If it does not suit you, you will probably have to make your own. However, it shouldn't be too difficult, just derive a new interactor from vtkInteractorStyle
, it already has all kinds of method like OnMouseMove
, OnKeyDown
etc. that you can override and fill with your camera movement (i.e. computing roll/pitch/yaw based on mouse movement). You can access the current camera by <your_vtkInteractorStyle_instance>->GetCurrentRenderer()->GetActiveCamera()
, it already has methods for yaw/pitch/roll.
Inside the vtkInteractorStyle, this->Interactor
will get you an instance of vtkRenderWindowInteractor
bound to the InteractorStyle, which has all the data about mouse and keyboard you need (current/last position of mouse, pressed keys etc.). Its events are caught by the vtkInteractorStyle
and trigger all the OnMouseMove
etc. already, so all you need to do is override and "fill" those.
One problem is that vtkInteractorStyle
already has some functionality bound to some of the keys, most notably to the 'W' key. You might either have to override the OnChar
method such that the keys are not processed in the way of the original vtkInteractorStyle
. Or you can derive your interactor directly from the abstract class vtkInteractorObserver
, but then you will have to do slightly more work as not all necessarry events have their callbacks defined.
I think the best is to simply look at the vtkInteractorStyle sources to see how it's implemented and do it similarly for your purposes.
BTW, some quick googling gave me this about 1st person camera in VTK, maybe it has some useful information for you as well.