00001 #include "RTSCameraUpdater.h"
00002
00003 #include "RTSCamera.h"
00004
00005 #include "OgreVector3.h"
00006 #include "OgreKeyEvent.h"
00007
00008 using Ogre::Vector3;
00009
00010
00011
00012 const float CAMERA_SPEED = 600.0f;
00013 const int SCROLL_HEIGHT = 15;
00014 const int SCROLL_WIDTH = 15;
00015 const float MOUSE_SPEED = 2.0f;
00016
00017
00018 namespace ASR
00019 {
00020
00021 RTSCameraUpdater::RTSCameraUpdater( RTSCamera* cam, CEGUI::Renderer* guiRenderer )
00022 : mGUIRenderer ( guiRenderer ),
00023 mCamera ( cam )
00024 {
00025 }
00026
00027
00028
00029 RTSCameraUpdater::~RTSCameraUpdater(void)
00030 {
00031 }
00032
00033
00034
00035 bool RTSCameraUpdater::updateBeforeFrame( const FrameEvent& e, const InputReader* inputDevice )
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
00045 if ( inputDevice->isKeyDown ( Ogre::KC_ESCAPE ) )
00046 return false;
00047
00048
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
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
00080 mCamera->translate ( Vector3 ( 0, -inputDevice->getMouseRelativeZ() * 0.5f, 0 ) );
00081
00082
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
00093 CEGUI::System::getSingleton().injectMousePosition( curX, curY );
00094
00095
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 }
00116
00117
00118
00119 bool RTSCameraUpdater::updateAfterFrame( const FrameEvent& e, const InputReader* inputDevice )
00120 {
00121 return true;
00122 }
00123 }