Changeset 9074 in orxonox.OLD for branches/presentation/src/world_entities/space_ships
- Timestamp:
- Jul 3, 2006, 11:55:31 PM (18 years ago)
- Location:
- branches/presentation/src/world_entities/space_ships
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/presentation/src/world_entities/space_ships/spacecraft_2d.cc
r9061 r9074 36 36 CREATE_FACTORY(Spacecraft2D, CL_SPACECRAFT_2D); 37 37 38 /** 39 * destructs the spacecraft_2d, deletes alocated memory 40 */ 41 Spacecraft2D::~Spacecraft2D () 42 { 43 this->setPlayer(NULL); 44 } 38 45 39 46 /** … … 86 93 87 94 /** 88 * destructs the spacecraft_2d, deletes alocated memory89 */90 Spacecraft2D::~Spacecraft2D ()91 {92 this->setPlayer(NULL);93 }94 95 /**96 95 * @brief initializes a Spacecraft2D 97 96 */ … … 101 100 this->setClassID(CL_SPACECRAFT_2D, "Spacecraft2D"); 102 101 103 this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal); 104 102 this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal ); 105 103 106 104 bForward = bBackward = bLeft = bRight = false; … … 110 108 this->rotation = 0.0f; 111 109 this->acceleration = 10.0f; 112 this->a ltitude = 0.0f;110 this->airFriction = 2.0f; 113 111 114 112 this->setHealthMax(100); 115 113 this->setHealth(100); 116 114 117 115 this->travelNode = new PNode(); 118 116 // camera - issue 119 this->travelNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 117 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 118 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 120 119 //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); 121 120 //this->cameraNode.setParent(this); 122 121 123 // rotors124 122 // PARTICLES 125 123 this->burstEmitter = new DotEmitter(200, 5.0, .01); … … 128 126 this->burstEmitter->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1))); 129 127 this->burstEmitter->setName("Spacecraft2D_Burst_emitter_Left"); 130 131 128 132 129 this->burstSystem = new SpriteParticles(1000); … … 150 147 this->registerEvent(KeyMapper::PEV_LEFT); 151 148 this->registerEvent(KeyMapper::PEV_RIGHT); 152 this->registerEvent(KeyMapper::PEV_UP);153 this->registerEvent(KeyMapper::PEV_DOWN);154 149 this->registerEvent(KeyMapper::PEV_FIRE1); 155 150 this->registerEvent(KeyMapper::PEV_NEXT_WEAPON); … … 178 173 this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0))); 179 174 180 this-> travelNode.setRelCoor(0,0,0);181 //this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);182 //this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);175 this->cameraNode.setRelCoor(1,5,0); 176 this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); 177 this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); 183 178 184 179 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); … … 205 200 } 206 201 207 void Spacecraft2D::setTravelDirecton(const Quaternion& rot, float speed)208 {209 this->setPlayDirection(rot, speed);210 }211 212 void Spacecraft2D::setTravelSpeed(float travelSpeed)213 {214 this->travelSpeed = travelSpeed;215 }216 217 218 219 202 void Spacecraft2D::enter() 220 203 { 221 204 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); 222 223 if (State::getCameraNode != NULL)224 {225 State::getCameraNode()->setParentSoft(&this->travelNode);226 State::getCameraNode()->setRelCoorSoft(-10, 50,0);227 State::getCameraTargetNode()->setParentSoft(&this->travelNode);228 }229 205 } 230 206 … … 235 211 236 212 } 213 214 215 void Spacecraft2D::enterPlaymode(Playable::Playmode playmode) 216 { 217 switch(playmode) 218 { 219 case Playable::Full3D: 220 if (State::getCameraNode != NULL) 221 { 222 State::getCameraNode()->setParentSoft(&this->cameraNode); 223 State::getCameraNode()->setRelCoorSoft(-10, 0,0); 224 State::getCameraTargetNode()->setParentSoft(&this->cameraNode); 225 } 226 break; 227 228 229 case Playable::Horizontal: 230 if (State::getCameraNode != NULL) 231 { 232 this->travelNode->setAbsCoor(this->getAbsCoor()); 233 this->travelNode->updateNode(0.01f); 234 this->setParentSoft(this->travelNode); 235 236 State::getCameraNode()->setParentSoft(this->travelNode); 237 State::getCameraNode()->setRelCoorSoft(-10, 50,0); 238 State::getCameraTargetNode()->setParentSoft(this->travelNode); 239 } 240 break; 241 242 default: 243 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName()); 244 } 245 } 246 237 247 238 248 … … 277 287 278 288 // TRYING TO FIX PNode. 279 //this->travelNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);280 //this->travelNode.setRelDirSoft(this->getAbsDir(), 30.0f);289 this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); 290 this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); 281 291 } 282 292 … … 307 317 accel += Vector(0, 0, this->acceleration); 308 318 } 309 310 319 311 320 switch(this->getPlaymode()) … … 316 325 317 326 // this is the air friction (necessary for a smooth control) 318 319 this->velocity += (accelerationDir)* dt; 327 Vector damping = (this->velocity * this->airFriction); 328 329 330 this->velocity += (accelerationDir - damping)* dt; 320 331 this->shiftCoor (this->velocity * dt); 321 332 … … 332 343 333 344 this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); 334 335 345 } 336 346 break; … … 343 353 344 354 // this is the air friction (necessary for a smooth control) 345 346 347 this->velocity += (accelerationDir )* dt; 355 Vector damping = (this->velocity * this->airFriction); 356 357 358 this->velocity += (accelerationDir - damping)* dt; 348 359 this->shiftCoor (this->velocity * dt); 349 360 … … 352 363 { 353 364 float maxRot = 10.0 * dt; 354 if (unlikely(this->rotation > 0.01 || this->rotation < 0.01)) this->rotation /=1.5; 365 if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; 366 if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; 355 367 this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); 356 368 … … 363 375 364 376 default: 365 PRINTF(2)("Playmode %s Not Implemented \n", Playable::playmodeToString(this->getPlaymode()).c_str());377 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName()); 366 378 } 367 379 } … … 395 407 396 408 // rotate the Player around the y-axis 397 if (this->getPlaymode() == Playable::Full3D) 398 this->rotation += xMouse; 409 this->rotation += xMouse; 399 410 400 411 this->cameraLook += yMouse; -
branches/presentation/src/world_entities/space_ships/spacecraft_2d.h
r9061 r9074 23 23 virtual void loadParams(const TiXmlElement* root); 24 24 virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f); 25 void setTravelDirecton(const Quaternion& rot, float speed = 0.0);26 void setTravelSpeed(float travelSpeed);27 28 25 virtual void enter(); 29 26 virtual void leave(); 30 31 32 27 33 28 virtual void postSpawn(); … … 39 34 40 35 virtual void process(const Event &event); 36 37 protected: 38 virtual void enterPlaymode(Playable::Playmode playmode); 41 39 42 40 private: … … 54 52 55 53 54 PNode* travelNode; 56 55 57 PNode travelNode; 58 float travelSpeed; 59 56 PNode cameraNode; 60 57 float cameraLook; 61 58 float rotation; … … 63 60 // Vector velocity; //!< the velocity of the Spacecraft2D. 64 61 Quaternion direction; //!< the direction of the Spacecraft2D. 62 float travelSpeed; //!< the current speed of the Hove (to make soft movement) 65 63 float acceleration; //!< the acceleration of the Spacecraft2D. 66 float maxSpeed; //!< The Maximal speed of the Spacecraft2D.64 float airFriction; //!< AirFriction. 67 65 68 float a ltitude; //!< The height in the Entity.66 float airViscosity; 69 67 70 68 ParticleEmitter* burstEmitter;
Note: See TracChangeset
for help on using the changeset viewer.