ASR::RTSCameraUpdater Class Reference

#include <RTSCameraUpdater.h>

Inheritance diagram for ASR::RTSCameraUpdater:

Inheritance graph
[legend]
Collaboration diagram for ASR::RTSCameraUpdater:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RTSCameraUpdater (RTSCamera *cam, CEGUI::Renderer *guiRenderer)
 ~RTSCameraUpdater (void)
bool updateBeforeFrame (const FrameEvent &e, const InputReader *inputDevice)
 Called each frame to perform the "update".
bool updateAfterFrame (const FrameEvent &e, const InputReader *inputDevice)

Private Attributes

RTSCameramCamera
CEGUI::Renderer * mGUIRenderer

Detailed Description

Definition at line 25 of file RTSCameraUpdater.h.


Constructor & Destructor Documentation

ASR::RTSCameraUpdater::RTSCameraUpdater ( RTSCamera cam,
CEGUI::Renderer *  guiRenderer 
)

Definition at line 21 of file RTSCameraUpdater.cpp.

00022                 : mGUIRenderer ( guiRenderer ),
00023                   mCamera ( cam )
00024         {
00025         }

ASR::RTSCameraUpdater::~RTSCameraUpdater ( void   ) 

Definition at line 29 of file RTSCameraUpdater.cpp.

00030         {
00031         }


Member Function Documentation

bool ASR::RTSCameraUpdater::updateAfterFrame ( const FrameEvent &  e,
const InputReader *  inputDevice 
) [virtual]

Implements ASR::Updater.

Definition at line 119 of file RTSCameraUpdater.cpp.

00120         {
00121                 return true;
00122         }

bool ASR::RTSCameraUpdater::updateBeforeFrame ( const FrameEvent &  e,
const InputReader *  inputDevice 
) [virtual]

Called each frame to perform the "update".

Return true if rendering should continue, false otherwise.

Implements ASR::Updater.

Definition at line 35 of file RTSCameraUpdater.cpp.

References CAMERA_SPEED, mCamera, mGUIRenderer, MOUSE_SPEED, SCROLL_HEIGHT, SCROLL_WIDTH, and ASR::RTSCamera::translate().

00036         {
00037                 const float fSpeed = 100.0f;
00038                 const float fPitch = 10.0f;
00039 
00040                 Vector3 trans = Vector3::ZERO;
00041                 Vector3 speed = Vector3( fSpeed, fSpeed, fSpeed );
00042                 speed *= e.timeSinceLastFrame;
00043 
00044                 // HACK: Move this into a general game updater with other hotkeys like F10 for menu
00045                 if ( inputDevice->isKeyDown ( Ogre::KC_ESCAPE ) )
00046                         return false;
00047 
00048                 // Right handed so back = +z-axis
00049                 if ( inputDevice->isKeyDown ( Ogre::KC_W ) )
00050                         trans.z -= speed.z;
00051 
00052                 if ( inputDevice->isKeyDown ( Ogre::KC_S ) )
00053                         trans.z += speed.z;
00054 
00055                 if ( inputDevice->isKeyDown ( Ogre::KC_A ) )
00056                         trans.x -= speed.x;
00057 
00058                 if ( inputDevice->isKeyDown ( Ogre::KC_D ) )
00059                         trans.x += speed.x;
00060 
00061                 if ( inputDevice->isKeyDown ( Ogre::KC_Q ) )
00062                         trans.y += speed.y;
00063 
00064                 if ( inputDevice->isKeyDown ( Ogre::KC_E ) )
00065                         trans.y -= speed.y;
00066 
00067                 //mCamera->pitch ( Ogre::Degree ( -inputDevice->getMouseRelativeY() * fPitch * e.timeSinceLastFrame ) );
00068 
00069                 mCamera->translate ( trans );
00070 
00071 
00072 
00073                 static int curX = mGUIRenderer->getWidth() / 2;
00074                 static int curY = mGUIRenderer->getHeight() / 2;
00075 
00076                 curX += ( inputDevice->getMouseRelativeX() * MOUSE_SPEED );
00077                 curY += ( inputDevice->getMouseRelativeY() * MOUSE_SPEED );
00078 
00079                 // Vertical movement (middle mouse)
00080                 mCamera->translate ( Vector3 ( 0, -inputDevice->getMouseRelativeZ() * 0.5f, 0 ) );
00081 
00082                 // Clamp
00083                 if ( curX < 0 )
00084                         curX = 0;
00085                 else if ( curX > mGUIRenderer->getWidth() )
00086                         curX = mGUIRenderer->getWidth();
00087                 if ( curY < 0 )
00088                         curY = 0;
00089                 else if ( curY > mGUIRenderer->getHeight() )
00090                         curY = mGUIRenderer->getHeight ();
00091 
00092                 // Update
00093                 CEGUI::System::getSingleton().injectMousePosition( curX, curY );
00094 
00095                 // Scrolling
00096                 if ( curX <= SCROLL_WIDTH )
00097                 {
00098                         mCamera->translate ( Vector3( -CAMERA_SPEED * e.timeSinceLastFrame, 0.0, 0.0 ) );
00099                 }
00100                 else if ( curX >= mGUIRenderer->getWidth() - SCROLL_WIDTH )
00101                 {
00102                         mCamera->translate ( Vector3( CAMERA_SPEED * e.timeSinceLastFrame, 0.0, 0.0 ) );
00103                 }
00104 
00105                 if ( curY <= SCROLL_HEIGHT )
00106                 {
00107                         mCamera->translate ( Vector3( 0.0f, 0.0f, -CAMERA_SPEED * e.timeSinceLastFrame ) );
00108                 }
00109                 else if ( curY >= mGUIRenderer->getHeight() - SCROLL_HEIGHT )
00110                 {
00111                         mCamera->translate ( Vector3( 0.0f, 0.0f, CAMERA_SPEED * e.timeSinceLastFrame ) );
00112                 }
00113 
00114                 return true;
00115         }


Member Data Documentation

RTSCamera* ASR::RTSCameraUpdater::mCamera [private]

Definition at line 30 of file RTSCameraUpdater.h.

Referenced by updateBeforeFrame().

CEGUI::Renderer* ASR::RTSCameraUpdater::mGUIRenderer [private]

Definition at line 31 of file RTSCameraUpdater.h.

Referenced by updateBeforeFrame().


The documentation for this class was generated from the following files:
Generated on Sun Jun 25 19:23:44 2006 for Valors End by  doxygen 1.4.7