00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00085
00086 break;
00087 case MM_TRANSLATE_INSTANCE:
00088
00089
00090 break;
00091 case MM_ROTATE_SCALE_INSTANCE:
00092
00093
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 };
00158 };
00159