OMK::Inp::CameraOgreListener Class Reference
[User inputs]

Input listener to control the camera. More...

#include <OMKCameraOgreListener.h>

Inheritance diagram for OMK::Inp::CameraOgreListener:

Inheritance graph
[legend]
Collaboration diagram for OMK::Inp::CameraOgreListener:

Collaboration graph
[legend]
List of all members.

Protected Member Functions

virtual bool keyPressed (const OIS::KeyEvent &e)
 Dispatches key pressed event.
virtual bool keyReleased (const OIS::KeyEvent &e)
 Dispatches key released event.
virtual bool mouseMoved (const OIS::MouseEvent &e)
 Dispatches mouse moved event.
virtual bool mousePressed (const OIS::MouseEvent &e, OIS::MouseButtonID id)
 Dispatches mouse button pressed event.
virtual bool mouseReleased (const OIS::MouseEvent &e, OIS::MouseButtonID id)
 Dispatches mouse button released event.
void moveCamera ()

Protected Attributes

OMK::Vis::OgreVis_ogreVis
Ogre::SceneNode * _cameraNode
Ogre::Vector3 _translateVector
float _moveScale
float _rotScale
float _rotX
float _rotY
float _moveSpeed

Private Member Functions

 DECLARE_INPUT_LISTENER_FACTORY (CameraOgreListener)

Detailed Description

Input listener to control the camera.

Date:
2007-02-28
Author:
Benoît Chanclou
Module description :
Define a key and mouse listener which control the camera of a VisOgre object.

Definition at line 23 of file OMKCameraOgreListener.h.


Member Function Documentation

OMK::Inp::CameraOgreListener::DECLARE_INPUT_LISTENER_FACTORY ( CameraOgreListener   )  [private]

bool CameraOgreListener::keyPressed ( const OIS::KeyEvent &  e  )  [protected, virtual]

Dispatches key pressed event.

Definition at line 35 of file OMKCameraOgreListener.cpp.

References _moveScale, _moveSpeed, _rotScale, _rotX, _translateVector, and moveCamera().

00036 {
00037   bool cameraMove = false ;
00038   switch( e.key )
00039   {
00040   case OIS::KC_UP :
00041     _translateVector.z = -_moveScale;
00042     cameraMove = true ;
00043     break ;
00044   case OIS::KC_DOWN :
00045     _translateVector.z = _moveScale;
00046     cameraMove = true ;
00047     break ;
00048   case OIS::KC_RIGHT :
00049     _rotX = -_rotScale ;
00050     cameraMove = true ;
00051     break ;
00052   case OIS::KC_LEFT :
00053     _rotX = _rotScale ;
00054     cameraMove = true ;
00055     break ;
00056     // increase move speed
00057   case OIS::KC_ADD :
00058     _moveSpeed += 10;
00059     cameraMove = true ;
00060     break ;
00061     // decrease move speed
00062   case OIS::KC_SUBTRACT :
00063     _moveSpeed -= ( 0 < _moveSpeed - 10 ) ? 10 : 0 ;
00064     cameraMove = true ;
00065     break ;
00066   default :
00067     ;  
00068   }
00069   if( cameraMove )
00070   {
00071     moveCamera();
00072   }
00073   return true ;
00074 }

virtual bool OMK::Inp::CameraOgreListener::keyReleased ( const OIS::KeyEvent &  e  )  [inline, protected, virtual]

Dispatches key released event.

Definition at line 33 of file OMKCameraOgreListener.h.

00033 { return true ; }

bool CameraOgreListener::mouseMoved ( const OIS::MouseEvent &  e  )  [protected, virtual]

Dispatches mouse moved event.

Definition at line 76 of file OMKCameraOgreListener.cpp.

References _moveScale, _rotX, _rotY, _translateVector, and moveCamera().

00077 {
00078   if( 0 < e.state.Z.rel )
00079   {
00080     _translateVector.z = _moveScale * 8.0f ;
00081   }
00082   else if ( e.state.Z.rel < 0 )
00083   {
00084     _translateVector.z = -_moveScale * 8.0f ;
00085   }
00086 
00087   /* Rotation factors, may not be used if the second mouse button is pressed. */
00088   /* If the second mouse button is pressed, then the mouse movement results in 
00089      sliding the camera, otherwise we rotate. */
00090   if( e.state.buttonDown( OIS::MB_Right ) ) 
00091   {
00092     _translateVector.x += e.state.X.rel * 0.13f ;
00093     _translateVector.y -= e.state.Y.rel * 0.13f ;
00094   }
00095   else if( e.state.buttonDown( OIS::MB_Left ) ) 
00096   {
00097     _rotX = -e.state.X.rel * 0.13f ;
00098     _rotY = -e.state.Y.rel * 0.13f ;
00099   }
00100   moveCamera();
00101   return true ;
00102 }

virtual bool OMK::Inp::CameraOgreListener::mousePressed ( const OIS::MouseEvent &  e,
OIS::MouseButtonID  id 
) [inline, protected, virtual]

Dispatches mouse button pressed event.

Definition at line 37 of file OMKCameraOgreListener.h.

00037 { return true ; }

virtual bool OMK::Inp::CameraOgreListener::mouseReleased ( const OIS::MouseEvent &  e,
OIS::MouseButtonID  id 
) [inline, protected, virtual]

Dispatches mouse button released event.

Definition at line 39 of file OMKCameraOgreListener.h.

00039 { return true ; }

void CameraOgreListener::moveCamera (  )  [protected]

Definition at line 104 of file OMKCameraOgreListener.cpp.

References _cameraNode, _rotX, _rotY, and _translateVector.

Referenced by keyPressed(), and mouseMoved().

00105 {
00106   // Transform the axes of the relative vector by camera's local axes
00107   Ogre::Vector3 trans = _cameraNode->getOrientation() * _translateVector;
00108   _cameraNode->setPosition( _cameraNode->getPosition() + trans );
00109   _cameraNode->yaw( Angle( _rotX ) );
00110   _cameraNode->pitch( Angle( _rotY ) );
00111   _rotX = 0;
00112   _rotY = 0;
00113   _translateVector = Vector3::ZERO ;
00114 }


Member Data Documentation

OMK::Vis::OgreVis* OMK::Inp::CameraOgreListener::_ogreVis [protected]

Definition at line 44 of file OMKCameraOgreListener.h.

Ogre::SceneNode* OMK::Inp::CameraOgreListener::_cameraNode [protected]

Definition at line 45 of file OMKCameraOgreListener.h.

Referenced by moveCamera().

Ogre::Vector3 OMK::Inp::CameraOgreListener::_translateVector [protected]

Definition at line 46 of file OMKCameraOgreListener.h.

Referenced by keyPressed(), mouseMoved(), and moveCamera().

float OMK::Inp::CameraOgreListener::_moveScale [protected]

Definition at line 47 of file OMKCameraOgreListener.h.

Referenced by keyPressed(), and mouseMoved().

float OMK::Inp::CameraOgreListener::_rotScale [protected]

Definition at line 48 of file OMKCameraOgreListener.h.

Referenced by keyPressed().

float OMK::Inp::CameraOgreListener::_rotX [protected]

Definition at line 49 of file OMKCameraOgreListener.h.

Referenced by keyPressed(), mouseMoved(), and moveCamera().

float OMK::Inp::CameraOgreListener::_rotY [protected]

Definition at line 50 of file OMKCameraOgreListener.h.

Referenced by mouseMoved(), and moveCamera().

float OMK::Inp::CameraOgreListener::_moveSpeed [protected]

Definition at line 51 of file OMKCameraOgreListener.h.

Referenced by keyPressed().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:04 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007