Changeset 8154 in orxonox.OLD
- Timestamp:
- Jun 5, 2006, 3:30:32 PM (18 years ago)
- Location:
- branches/network/src/world_entities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/spectator.cc
r8152 r8154 23 23 CREATE_FACTORY(Spectator, CL_SPECTATOR); 24 24 25 #if 0 26 /** 27 * constructor 28 */ 29 Spectator::Spectator( const TiXmlElement * root ) 30 { 25 26 using namespace std; 27 28 29 /** 30 * destructs the Spectator, deletes alocated memory 31 */ 32 Spectator::~Spectator () 33 { 34 this->setPlayer(NULL); 35 } 36 37 38 /** 39 * creates a new Spectator from Xml Data 40 * @param root the xml element containing Spectator data 41 42 @todo add more parameters to load 43 */ 44 Spectator::Spectator(const TiXmlElement* root) 45 { 46 this->init(); 47 if (root != NULL) 48 this->loadParams(root); 49 50 } 51 52 53 /** 54 * initializes a Spectator 55 */ 56 void Spectator::init() 57 { 58 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); 31 59 this->setClassID(CL_SPECTATOR, "Spectator"); 32 33 bool bLeft; 34 bool bRight; 35 bool bForward; 36 bool bBackward; 60 61 this->getWeaponManager().changeWeaponConfig(1); 37 62 38 63 this->bLeft = false; … … 42 67 this->xMouse = 0.0f; 43 68 this->yMouse = 0.0f; 44 45 registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ));46 registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ));47 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); 48 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ));49 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) ); 50 69 70 this->setHealthMax(100); 71 this->setHealth(80); 72 73 this->mouseDir = this->getAbsDir(); 74 75 //add events to the eventlist 51 76 registerEvent(KeyMapper::PEV_FORWARD); 52 77 registerEvent(KeyMapper::PEV_BACKWARD); … … 55 80 registerEvent(KeyMapper::PEV_FIRE1); 56 81 registerEvent(EV_MOUSE_MOTION); 57 } 58 59 /** 60 * destructor 61 */ 62 Spectator::~Spectator( ) 63 { 64 this->setPlayer(NULL); 65 } 66 67 void Spectator::setPlayDirection( const Quaternion & rot, float speed ) 68 { 69 this->mouseDir = rot; 70 this->angleY = rot.getHeading(); 71 this->angleX = rot.getAttitude(); 72 } 73 74 void Spectator::enter( ) 75 { 82 83 this->getWeaponManager().setSlotCount(0); 84 85 this->getWeaponManager().getFixedTarget()->setParent(this); 86 this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0); 87 88 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); 89 90 91 registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); 92 registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); 93 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); 94 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); 95 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) ); 96 } 97 98 99 /** 100 * loads the Settings of a Spectator from an XML-element. 101 * @param root the XML-element to load the Spaceship's properties from 102 */ 103 void Spectator::loadParams(const TiXmlElement* root) 104 { 105 Playable::loadParams(root); 106 } 107 108 void Spectator::setPlayDirection(const Quaternion& quat, float speed) 109 { 110 this->mouseDir = quat; 111 this->angleY = quat.getHeading(); 112 this->angleX = quat.getAttitude(); 113 } 114 115 116 void Spectator::reset() 117 { 118 this->bLeft = false; 119 this->bRight = false; 120 this->bForward = false; 121 this->bBackward = false; 122 this->xMouse = 0.0f; 123 this->yMouse = 0.0f; 124 125 this->setHealth(80); 126 } 127 128 129 void Spectator::enter() 130 { 131 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false ); 76 132 this->attachCamera(); 77 133 } 78 134 79 void Spectator::leave( ) 80 { 135 void Spectator::leave() 136 { 137 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); 81 138 this->detachCamera(); 82 139 } 83 140 84 /** 85 * collision handling 86 * @param entity other entity 87 * @param location 88 * @todo dont allow spectator to go through walls 89 */ 90 void Spectator::collidesWith( WorldEntity * entity, const Vector & location ) 91 { 92 } 93 94 void Spectator::tick( float time ) 141 142 /** 143 * this function is called, when two entities collide 144 * @param entity: the world entity with whom it collides 145 * 146 * Implement behaviour like damage application or other miscellaneous collision stuff in this function 147 * @todo dont let Spectator fly through walls 148 */ 149 void Spectator::collidesWith(WorldEntity* entity, const Vector& location) 150 { 151 } 152 153 154 155 /** 156 * the function called for each passing timeSnap 157 * @param time The timespan passed since last update 158 */ 159 void Spectator::tick (float time) 95 160 { 96 161 Playable::tick( time ); … … 144 209 } 145 210 146 void Spectator::process( const Event & event ) 211 /** 212 * @todo switch statement ?? 213 */ 214 void Spectator::process(const Event &event) 147 215 { 148 216 Playable::process(event); … … 162 230 } 163 231 } 164 #endif 165 166 167 #include "executor/executor.h" 168 169 #include "util/loading/resource_manager.h" 170 171 #include "weapons/test_gun.h" 172 #include "weapons/turret.h" 173 #include "weapons/cannon.h" 174 175 #include "dot_emitter.h" 176 #include "sprite_particles.h" 177 178 #include "util/loading/factory.h" 179 #include "key_mapper.h" 180 181 #include "network_game_manager.h" 182 183 #include "power_ups/weapon_power_up.h" 184 #include "power_ups/param_power_up.h" 185 186 #include "graphics_engine.h" 187 188 #include "plane.h" 189 190 #include "state.h" 191 #include "player.h" 192 193 #include "util/loading/load_param.h" 194 195 196 using namespace std; 197 198 199 /** 200 * destructs the spaceship, deletes alocated memory 201 */ 202 Spectator::~Spectator () 203 { 204 this->setPlayer(NULL); 205 } 206 207 /** 208 * loads a Spaceships information from a specified file. 209 * @param fileName the name of the File to load the spaceship from (absolute path) 210 */ 211 Spectator::Spectator(const std::string& fileName) 212 { 213 this->init(); 214 TiXmlDocument doc(fileName); 215 216 if(!doc.LoadFile()) 217 { 218 PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); 219 return; 220 } 221 222 this->loadParams(doc.RootElement()); 223 } 224 225 /** 226 * creates a new Spaceship from Xml Data 227 * @param root the xml element containing spaceship data 228 229 @todo add more parameters to load 230 */ 231 Spectator::Spectator(const TiXmlElement* root) 232 { 233 this->init(); 234 if (root != NULL) 235 this->loadParams(root); 236 237 } 238 239 240 /** 241 * initializes a Spaceship 242 */ 243 void Spectator::init() 244 { 245 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); 246 this->setClassID(CL_SPECTATOR, "Spectator"); 247 248 PRINTF(4)("SPACESHIP INIT\n"); 249 250 251 this->getWeaponManager().changeWeaponConfig(1); 252 253 this->bLeft = false; 254 this->bRight = false; 255 this->bForward = false; 256 this->bBackward = false; 257 this->xMouse = 0.0f; 258 this->yMouse = 0.0f; 259 260 this->setHealthMax(100); 261 this->setHealth(80); 262 263 this->mouseDir = this->getAbsDir(); 264 265 //add events to the eventlist 266 registerEvent(KeyMapper::PEV_FORWARD); 267 registerEvent(KeyMapper::PEV_BACKWARD); 268 registerEvent(KeyMapper::PEV_LEFT); 269 registerEvent(KeyMapper::PEV_RIGHT); 270 registerEvent(KeyMapper::PEV_FIRE1); 271 registerEvent(EV_MOUSE_MOTION); 272 273 this->getWeaponManager().setSlotCount(0); 274 275 this->getWeaponManager().getFixedTarget()->setParent(this); 276 this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0); 277 278 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); 279 280 281 registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); 282 registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); 283 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); 284 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); 285 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) ); 286 } 287 288 289 /** 290 * loads the Settings of a Spectator from an XML-element. 291 * @param root the XML-element to load the Spaceship's properties from 292 */ 293 void Spectator::loadParams(const TiXmlElement* root) 294 { 295 Playable::loadParams(root); 296 } 297 298 void Spectator::setPlayDirection(const Quaternion& quat, float speed) 299 { 300 this->mouseDir = quat; 301 this->angleY = quat.getHeading(); 302 this->angleX = quat.getAttitude(); 303 } 304 305 306 void Spectator::reset() 307 { 308 this->bLeft = false; 309 this->bRight = false; 310 this->bForward = false; 311 this->bBackward = false; 312 this->xMouse = 0.0f; 313 this->yMouse = 0.0f; 314 315 this->setHealth(80); 316 } 317 318 319 void Spectator::enter() 320 { 321 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); 322 this->attachCamera(); 323 } 324 325 void Spectator::leave() 326 { 327 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); 328 this->detachCamera(); 329 } 330 331 332 /** 333 * this function is called, when two entities collide 334 * @param entity: the world entity with whom it collides 335 * 336 * Implement behaviour like damage application or other miscellaneous collision stuff in this function 337 * @todo dont let Spectator fly through walls 338 */ 339 void Spectator::collidesWith(WorldEntity* entity, const Vector& location) 340 { 341 } 342 343 344 345 /** 346 * the function called for each passing timeSnap 347 * @param time The timespan passed since last update 348 */ 349 void Spectator::tick (float time) 350 { 351 Playable::tick( time ); 352 353 if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() ) 354 { 355 xMouse *= time / 10; 356 yMouse *= time / 10; 357 358 angleX -= xMouse; 359 angleY -= yMouse; 360 361 if ( angleY > 2.05 ) 362 angleY = 2.05; 363 364 if ( angleY < -1.15 ) 365 angleY = -1.15; 366 367 this->mouseDir = Quaternion( angleX, Vector( 0, 1, 0 ) ) * Quaternion( angleY, Vector( 0, 0, 1 ) ); 368 369 xMouse = yMouse = 0; 370 } 371 372 this->setAbsDir( this->mouseDir ); 373 374 Vector velocity; 375 376 if ( this->bForward ) 377 { 378 velocity += this->getAbsDirX(); 379 } 380 381 if ( this->bBackward ) 382 { 383 velocity -= this->getAbsDirX(); 384 } 385 386 if ( this->bRight ) 387 { 388 velocity += this->getAbsDirZ(); 389 } 390 391 if ( this->bLeft ) 392 { 393 velocity -= this->getAbsDirZ(); 394 } 395 396 velocity *= 100; 397 398 this->shiftCoor( velocity*time ); 399 } 400 401 /** 402 * @todo switch statement ?? 403 */ 404 void Spectator::process(const Event &event) 405 { 406 Playable::process(event); 407 408 if( event.type == KeyMapper::PEV_LEFT) 409 this->bLeft = event.bPressed; 410 else if( event.type == KeyMapper::PEV_RIGHT) 411 this->bRight = event.bPressed; 412 else if( event.type == KeyMapper::PEV_FORWARD) 413 this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); 414 else if( event.type == KeyMapper::PEV_BACKWARD) 415 this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); 416 else if( event.type == EV_MOUSE_MOTION) 417 { 418 this->xMouse += event.xRel; 419 this->yMouse += event.yRel; 420 } 421 } 422 423 424 425 232 233 234 235 -
branches/network/src/world_entities/spectator.h
r8152 r8154 9 9 #include "playable.h" 10 10 11 #if 012 class Spectator : public Playable13 {14 public:15 Spectator( const TiXmlElement* root = NULL );16 virtual ~Spectator();17 18 virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f);19 20 virtual void enter();21 virtual void leave();22 23 virtual void collidesWith(WorldEntity* entity, const Vector& location);24 virtual void tick(float time);25 26 virtual void process(const Event &event);27 28 private:29 bool bLeft;30 bool bRight;31 bool bForward;32 bool bBackward;33 34 float xMouse; //!< mouse moved in x-Direction35 float yMouse; //!< mouse moved in y-Direction36 Quaternion mouseDir; //!< the direction where the player wants to fly37 38 //Quaternion rotY;39 //Quaternion rotAxis;40 float angleX;41 float angleY;42 };43 #endif44 45 class Vector;46 class Event;47 class ParticleEmitter;48 class ParticleSystem;49 50 11 class Spectator : public Playable 51 12 { 52 13 53 14 public: 54 Spectator(const std::string& fileName);55 15 Spectator(const TiXmlElement* root = NULL); 56 16 virtual ~Spectator(); … … 82 42 Quaternion mouseDir; //!< the direction where the player wants to fly 83 43 84 //Quaternion rotY;85 //Quaternion rotAxis;86 44 float angleX; 87 45 float angleY;
Note: See TracChangeset
for help on using the changeset viewer.