Changeset 9110 in orxonox.OLD for trunk/src/world_entities/space_ships/spacecraft_2d.cc
- Timestamp:
- Jul 4, 2006, 11:18:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/space_ships/spacecraft_2d.cc
r9061 r9110 25 25 26 26 #include "util/loading/factory.h" 27 #include "util/loading/load_param.h" 27 28 #include "key_mapper.h" 28 29 #include "state.h" … … 36 37 CREATE_FACTORY(Spacecraft2D, CL_SPACECRAFT_2D); 37 38 39 /** 40 * destructs the spacecraft_2d, deletes alocated memory 41 */ 42 Spacecraft2D::~Spacecraft2D () 43 { 44 this->setPlayer(NULL); 45 delete this->toTravelHeight; 46 } 38 47 39 48 /** … … 86 95 87 96 /** 88 * destructs the spacecraft_2d, deletes alocated memory89 */90 Spacecraft2D::~Spacecraft2D ()91 {92 this->setPlayer(NULL);93 }94 95 /**96 97 * @brief initializes a Spacecraft2D 97 98 */ … … 101 102 this->setClassID(CL_SPACECRAFT_2D, "Spacecraft2D"); 102 103 103 this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal); 104 104 this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal ); 105 105 106 106 bForward = bBackward = bLeft = bRight = false; … … 110 110 this->rotation = 0.0f; 111 111 this->acceleration = 10.0f; 112 this->altitude = 0.0f; 112 this->airFriction = 2.0f; 113 113 114 114 115 this->setHealthMax(100); … … 116 117 117 118 119 /// 2D-MODE 120 this->toTravelHeight = NULL; 121 this->travelSpeed = 0.0f; 122 this->travelNode = new PNode(); 123 124 118 125 // camera - issue 119 this->travelNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 126 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 127 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 120 128 //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); 121 129 //this->cameraNode.setParent(this); 122 130 123 // rotors124 131 // PARTICLES 125 132 this->burstEmitter = new DotEmitter(200, 5.0, .01); 126 133 this->burstEmitter->setParent(this); 127 134 this->burstEmitter->setRelCoor(0, -0.7, 0); 128 this->burstEmitter->setRelDir(Quaternion(-M_PI _2, Vector(0,0,1)));135 this->burstEmitter->setRelDir(Quaternion(-M_PI, Vector(0,0,1))); 129 136 this->burstEmitter->setName("Spacecraft2D_Burst_emitter_Left"); 130 131 137 132 138 this->burstSystem = new SpriteParticles(1000); … … 150 156 this->registerEvent(KeyMapper::PEV_LEFT); 151 157 this->registerEvent(KeyMapper::PEV_RIGHT); 152 this->registerEvent(KeyMapper::PEV_UP);153 this->registerEvent(KeyMapper::PEV_DOWN);154 158 this->registerEvent(KeyMapper::PEV_FIRE1); 155 159 this->registerEvent(KeyMapper::PEV_NEXT_WEAPON); … … 178 182 this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0))); 179 183 180 this-> travelNode.setRelCoor(0,0,0);181 //this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);182 //this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);184 this->cameraNode.setRelCoor(1,5,0); 185 this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); 186 this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); 183 187 184 188 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); … … 198 202 { 199 203 Playable::loadParams(root); 204 205 LoadParam(root, "travel-speed", this, Spacecraft2D, setTravelSpeed); 206 LoadParam(root, "travel-height", this, Spacecraft2D, setTravelHeight); 207 LoadParam(root, "travel-distance", this, Spacecraft2D, setTravelDistance); 200 208 } 201 209 … … 205 213 } 206 214 207 void Spacecraft2D::setTravelDirecton(const Quaternion& rot, float speed)208 {209 this->setPlayDirection(rot, speed);210 }211 212 215 void Spacecraft2D::setTravelSpeed(float travelSpeed) 213 216 { … … 216 219 217 220 221 void Spacecraft2D::setTravelHeight(float travelHeight) 222 { 223 if (this->toTravelHeight == NULL) 224 this->toTravelHeight = new float; 225 *this->toTravelHeight = travelHeight; 226 } 227 228 229 void Spacecraft2D::setTravelDistance(const Vector2D& distance) 230 { 231 this->travelDistance = distance; 232 } 233 234 void Spacecraft2D::setTravelDistance(float x, float y) 235 { 236 this->setTravelDistance(Vector2D(x, y)); 237 } 238 239 218 240 219 241 void Spacecraft2D::enter() 220 242 { 221 243 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 } 244 this->setPlaymode(this->getPlaymode()); 229 245 } 230 246 … … 235 251 236 252 } 253 254 255 void Spacecraft2D::enterPlaymode(Playable::Playmode playmode) 256 { 257 switch(playmode) 258 { 259 case Playable::Full3D: 260 if (State::getCameraNode != NULL) 261 { 262 Vector absCoor = this->getAbsCoor(); 263 this->setParent(PNode::getNullParent()); 264 this->setAbsCoor(absCoor); 265 State::getCameraNode()->setParentSoft(&this->cameraNode); 266 State::getCameraNode()->setRelCoorSoft(-10, 0,0); 267 State::getCameraTargetNode()->setParentSoft(&this->cameraNode); 268 State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); 269 270 } 271 break; 272 273 274 case Playable::Horizontal: 275 if (State::getCameraNode != NULL) 276 { 277 this->debugNode(1); 278 this->travelNode->debugNode(1); 279 280 this->travelNode->setAbsCoor(this->getAbsCoor()); 281 this->travelNode->updateNode(0.01f); 282 283 this->setParent(this->travelNode); 284 this->setRelCoor(0,0,0); 285 286 State::getCameraNode()->setParentSoft(this->travelNode); 287 State::getCameraNode()->setRelCoorSoft(-3, 50,0); 288 State::getCameraTargetNode()->setParentSoft(this->travelNode); 289 State::getCameraTargetNode()->setRelCoorSoft(0,0,0); 290 291 292 this->debugNode(1); 293 this->travelNode->debugNode(1); 294 } 295 break; 296 297 default: 298 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName()); 299 } 300 } 301 237 302 238 303 … … 277 342 278 343 // 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);344 this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); 345 this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); 281 346 } 282 347 … … 307 372 accel += Vector(0, 0, this->acceleration); 308 373 } 309 310 374 311 375 switch(this->getPlaymode()) … … 316 380 317 381 // this is the air friction (necessary for a smooth control) 318 319 this->velocity += (accelerationDir)* dt; 382 Vector damping = (this->velocity * this->airFriction); 383 384 385 this->velocity += (accelerationDir - damping)* dt; 320 386 this->shiftCoor (this->velocity * dt); 321 387 … … 332 398 333 399 this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); 334 335 400 } 336 401 break; … … 338 403 case Playable::Horizontal: 339 404 { 405 406 if (this->toTravelHeight != NULL) 407 { 408 this->travelNode->shiftCoor(Vector(0, (*toTravelHeight - this->travelNode->getAbsCoor().y) * dt, 0)); 409 if (fabsf(this->travelNode->getAbsCoor().y - *this->toTravelHeight) < .1) 410 { 411 delete this->toTravelHeight; 412 this->toTravelHeight = NULL; 413 } 414 } 415 this->travelNode->shiftCoor(Vector(this->travelSpeed * dt, 0, 0)); 416 340 417 accel.y = 0.0; 341 418 Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); … … 343 420 344 421 // this is the air friction (necessary for a smooth control) 345 346 347 this->velocity += (accelerationDir )* dt; 422 Vector damping = (this->velocity * this->airFriction); 423 424 425 this->velocity += (accelerationDir - damping)* dt; 348 426 this->shiftCoor (this->velocity * dt); 349 350 // limit the maximum rotation speed. 351 if (this->rotation != 0.0f) 352 { 353 float maxRot = 10.0 * dt; 354 if (unlikely(this->rotation > 0.01 || this->rotation < 0.01)) this->rotation /=1.5; 355 this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); 356 357 this->rotation = 0.0f; 358 } 359 360 this->setRelDirSoft(this->direction, 5); 427 this->setRelDirSoft(Quaternion(0, Vector(0,0,0)), 1.0f); 361 428 } 362 429 break; 363 430 364 431 default: 365 PRINTF(2)("Playmode %s Not Implemented \n", Playable::playmodeToString(this->getPlaymode()).c_str());432 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName()); 366 433 } 367 434 } … … 390 457 else if( event.type == EV_MOUSE_MOTION) 391 458 { 392 float xMouse, yMouse; 393 xMouse = event.xRel*mouseSensitivity; 394 yMouse = event.yRel*mouseSensitivity; 395 396 // rotate the Player around the y-axis 459 460 461 397 462 if (this->getPlaymode() == Playable::Full3D) 463 { 464 float xMouse, yMouse; 465 xMouse = event.xRel*mouseSensitivity; 466 yMouse = event.yRel*mouseSensitivity; 467 468 // rotate the Player around the y-axis 398 469 this->rotation += xMouse; 399 470 400 this->cameraLook += yMouse; 401 // rotate the Camera around the z-axis 402 if (cameraLook > M_PI_4) 403 cameraLook = M_PI_4; 404 else if (cameraLook < -M_PI_4) 405 cameraLook = -M_PI_4; 406 //this->cameraNode.setRelDirSoft(this->direction,10); 407 } 408 } 471 this->cameraLook += yMouse; 472 // rotate the Camera around the z-axis 473 if (cameraLook > M_PI_4) 474 cameraLook = M_PI_4; 475 else if (cameraLook < -M_PI_4) 476 cameraLook = -M_PI_4; 477 //this->cameraNode.setRelDirSoft(this->direction,10); 478 } 479 } 480 }
Note: See TracChangeset
for help on using the changeset viewer.