Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

EventManager.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TSGL - Teddy Space Game Library
00004     Copyright (C) 2002 Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: EventManager.cpp,v 1.1 2002/01/08 20:47:05 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "config.h"
00026 #include "Teddy/SpaceGame/Root.h"
00027 #include "Teddy/SpaceGame/Simulated.h"
00028 #include "Teddy/Scenes/Camera.h"
00029 #include "Teddy/Scenes/Scene.h"
00030 using namespace Teddy::Scenes;
00031 
00032 
00033 namespace Teddy     {
00034 namespace SpaceGame {
00035 
00036 
00037 #define MM_CONTROL_CAMERA        1
00038 #define MM_TRANSLATE_INSTANCE    2
00039 #define MM_ROTATE_SCALE_INSTANCE 3
00040 
00041 #define TRANSLATE_SCALE   1.0f
00042 #define ROTATE_SCALE      0.3f
00043 #define distance_delta    0.01f
00044 #define SCALE             1.00f
00045 
00046 
00047 EventManager::EventManager( Root *root ){
00048     this->root = root;
00049 
00050     //  Initialize spectator camera control variables
00051     control_speed_more  = false;
00052     control_speed_less  = false;
00053     control_speed       = 0;
00054     control_heading     = 0;
00055     control_pitch       = 0;
00056     control_roll        = 0;
00057     control_last_button = 0;
00058     mouse_mode          = MM_CONTROL_CAMERA;
00059 }
00060 
00061 
00063 void EventManager::cameraRotate( const int x_delta, const int y_delta ){
00064     control_heading -= 0.1f * x_delta;
00065     control_pitch   -= 0.1f * y_delta;
00066 }
00067 
00068 
00070 void EventManager::cameraTranslate( const int x_delta, const int y_delta ){
00071     control_roll    += 0.1f * x_delta;
00072     control_speed   -= 0.1f * y_delta;
00073 }
00074 
00075 
00077 void EventManager::chooseMouseMode(){
00078     mouse_mode++;
00079     if( mouse_mode>2 ){
00080         mouse_mode = 0;
00081     }
00082     switch( mouse_mode ){
00083     case MM_CONTROL_CAMERA:
00084         //con << ": Drag Left Mouse Buttom down: Rotate camera" << endl;
00085         //con << ": Drag Right Mouse Button down: Move forward/backward" << endl;
00086         break;
00087     case MM_TRANSLATE_INSTANCE:
00088         //con << ": Drag Left Mouse Buttom down: Translate object X, Z" << endl;
00089         //con << ": Drag Right Mouse Button down: Translate object X, Y" << endl;
00090         break;
00091     case MM_ROTATE_SCALE_INSTANCE:
00092         //con << ": Drag Left Mouse Buttom down: Rotate object X, Y" << endl;
00093         //con << ": Drag Right Mouse Button down: Rotate object Z, Scale object" << endl;
00094         break;
00095     default:
00096         break;
00097     }
00098 }
00099 
00100 
00102 void EventManager::mouseMotion( const int b, const int x_delta, const int y_delta ){
00103     ActionManager *am = root->getActionManager();
00104     EventManager  *em = root->getEventManager ();
00105     ObjectManager *om = root->getObjectManager();
00106 
00107     switch( mouse_mode ){
00108     case MM_CONTROL_CAMERA: 
00109         switch( b ){
00110         case 1: em->cameraRotate   ( x_delta, y_delta ); break;
00111         case 2: em->cameraTranslate( x_delta, y_delta ); break;
00112         case 3: em->cameraTranslate( x_delta, y_delta ); break;
00113         default: break;
00114         }
00115         break;
00116     case MM_TRANSLATE_INSTANCE:
00117         switch( b ){
00118         case 1: om->instanceTranslateXZ( x_delta, y_delta ); break;
00119         case 2: om->instanceTranslateYZ( x_delta, y_delta ); break;
00120         case 3: om->instanceTranslateYZ( x_delta, y_delta ); break;
00121         default: break;
00122         }
00123         break;
00124     case MM_ROTATE_SCALE_INSTANCE:
00125         switch( b ){
00126         case 1: om->instanceRotate( x_delta, y_delta ); break;
00127         case 2: om->instanceScale ( x_delta, y_delta ); break;
00128         case 3: om->instanceScale ( x_delta, y_delta ); break;
00129         default: break;
00130         }
00131         break;
00132     default:
00133         break;
00134     }
00135 }
00136 
00137 
00139 void EventManager::applyControls(){
00140     Camera *camera = root->getObjectManager()->getCamera();
00141 
00142     camera->heading( control_heading );
00143     camera->pitch  ( control_pitch   );
00144     camera->roll   ( control_roll    );
00145 
00146     Vector delta = camera->getViewAxis() * control_speed;
00147     camera->translate( delta );
00148 
00149     control_heading *= 0.88f;
00150     control_pitch   *= 0.88f;
00151     control_roll    *= 0.88f;
00152     control_speed   *= 0.98f;
00153 }
00154 
00155 
00156 
00157 };  //  namespace SpaceGame
00158 };  //  namespace Teddy
00159