- Timestamp:
- Jan 28, 2006, 12:20:58 PM (19 years ago)
- Location:
- trunk/src/world_entities/space_ships
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/space_ships/helicopter.cc
r6804 r6805 259 259 void Helicopter::collidesWith(WorldEntity* entity, const Vector& location) 260 260 { 261 if (entity->isA(CL_TURRET_POWER_UP))262 {263 this->ADDWEAPON();264 }265 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);266 261 } 267 262 … … 468 463 469 464 glPopMatrix (); 470 471 this->getWeaponManager()->draw();472 465 } 473 466 … … 515 508 } 516 509 } 517 518 #include "weapons/aiming_turret.h"519 // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG520 void Helicopter::ADDWEAPON()521 {522 Weapon* turret = NULL;523 524 if ((float)rand()/RAND_MAX < .1)525 {526 //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET))527 {528 turret = new Turret();529 this->addWeapon(turret, 2);530 this->getWeaponManager()->changeWeaponConfig(2);531 }532 }533 else534 {535 //if (this->getWeaponManager()->hasFreeSlot(3))536 {537 turret = new AimingTurret();538 this->addWeapon(turret, 3);539 540 this->getWeaponManager()->changeWeaponConfig(3);541 }542 }543 544 if(turret != NULL)545 {546 turret->setName("Turret");547 turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);548 }549 } -
trunk/src/world_entities/space_ships/helicopter.h
r6804 r6805 42 42 void calculateVelocity(float time); 43 43 44 // !! temporary !!45 void ADDWEAPON();46 47 44 bool bUp; //!< up button pressed. 48 45 bool bDown; //!< down button pressed. -
trunk/src/world_entities/space_ships/hover.cc
r6804 r6805 39 39 */ 40 40 Hover::~Hover () 41 { 42 } 41 {} 43 42 44 43 /** … … 97 96 void Hover::init() 98 97 { 99 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));98 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); 100 99 this->setClassID(CL_HOVER, "Hover"); 101 100 … … 106 105 EventHandler::getInstance()->grabEvents(true); 107 106 108 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; 109 bFire = false; 107 bForward = bBackward = bLeft = bRight = bAscend = bDescend = false; 110 108 xMouse = yMouse = 0; 111 109 mouseSensitivity = 0.05; … … 144 142 this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3); 145 143 this->loadModel("models/ships/hoverglider_rotor.obj", 1.0f, 4); 146 147 148 //travelSpeed = 15.0;149 this->velocity = Vector(0.0,0.0,0.0);150 this->velocityDir = Vector(1.0,0.0,0.0);151 144 152 145 //add events to the eventlist … … 243 236 void Hover::collidesWith(WorldEntity* entity, const Vector& location) 244 237 { 245 246 238 } 247 239 … … 257 249 258 250 if( xMouse != 0 || yMouse != 0) 259 251 { 260 252 if (xMouse > controlVelocityX) xMouse = controlVelocityX; 261 253 else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; … … 265 257 266 258 // spaceship controlled movement 267 this-> calculateVelocity(dt);259 this->movement(dt); 268 260 269 261 Vector move = (velocity)*dt; … … 271 263 // this is the air friction (necessary for a smooth control) 272 264 if(velocity.len() != 0) velocity -= velocity*0.1; 273 this->shiftCoor (move);265 this->shiftCoor (move); 274 266 275 267 } … … 279 271 * @param time the timeslice since the last frame 280 272 */ 281 void Hover:: calculateVelocity(float time)273 void Hover::movement (float time) 282 274 { 283 275 Vector accel(0.0, 0.0, 0.0); 284 float rotValX = 0.0; 285 float rotValZ = 0.0; 286 /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ 287 /* calculate the direction in which the craft is heading */ 288 289 if( this->bUp ) 290 { 291 //this->shiftCoor(this->getAbsDirX()); 292 //accel -= this->getAbsDirY(); 293 294 accel += Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); 295 if((this->getAbsDirX()).y >= -0.1) rotValZ -= time; 296 } 297 else 298 { 299 if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time, Vector(0,0,1))); 300 } 301 302 if( this->bDown ) 303 { 304 //this->shiftCoor((this->getAbsDirX())*-1); 305 //accel -= this->getAbsDirY(); 306 307 accel -= Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); 308 rotValZ += time; 309 } 310 else 311 { 312 if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time, Vector(0,0,1))); 313 } 314 315 if( this->bLeft /* > -this->getRelCoor().z*2*/) 316 { 317 //this->shiftDir(Quaternion(time, Vector(0,1,0))); 318 //accel -= this->getAbsDirY(); 319 //velocityDir.normalize(); 320 321 accel -= Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); 322 rotValX -= time; 323 } 324 else 325 { 326 if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time, Vector(1,0,0))); 327 } 328 329 if( this->bRight /* > this->getRelCoor().z*2*/) 330 { 331 //this->shiftDir(Quaternion(-time, Vector(0,1,0))); 332 //accel += this->getAbsDirY(); 333 //velocityDir.normalize(); 334 335 accel += Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); 336 rotValX += time; 337 } 338 else 339 { 340 if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time, Vector(1,0,0))); 341 } 342 343 if( this->bRollL /* > -this->getRelCoor().z*2*/) 344 { 345 this->shiftDir(Quaternion(-time, Vector(1,0,0))); 346 //accel -= rightDirection; 347 //velocityDir.normalize(); 348 //rot +=Vector(1,0,0); 349 //rotVal -= .4; 350 } 351 if( this->bRollR /* > this->getRelCoor().z*2*/) 352 { 353 this->shiftDir(Quaternion(time, Vector(1,0,0))); 354 355 //accel += rightDirection; 356 //velocityDir.normalize(); 357 //rot += Vector(1,0,0); 358 //rotVal += .4; 359 } 360 if (this->bAscend ) 361 { 362 //this->shiftDir(Quaternion(time, Vector(0,0,1))); 363 364 accel += this->getAbsDirY(); 365 //rotorspeed += 0.05; 366 //if (rotorspeed >= 2) rotorspeed = 2; 367 //velocityDir.normalize(); 368 //rot += Vector(0,0,1); 369 //rotVal += .4; 370 } 371 else 372 { 373 //if(rotorspeed >= 1.05) rotorspeed -= 0.05; 374 } 375 276 float rotVal = .3; 277 278 if( this->bForward ) { 279 accel += Vector(rotVal, 0, 0); 280 } 281 282 if( this->bBackward ) { 283 accel -= Vector(rotVal,0,0); 284 } 285 if( this->bLeft) { 286 accel -= Vector(0,0,rotVal); 287 } 288 if( this->bRight) { 289 accel += Vector(0,0,rotVal); 290 } 291 292 if (this->bAscend ) { 293 accel += Vector(0,rotVal,0); 294 } 376 295 if (this->bDescend ) 377 { 378 //this->shiftDir(Quaternion(-time, Vector(0,0,1))); 379 380 accel -= this->getAbsDirY(); 381 //rotorspeed -= 0.05; 382 //if (rotorspeed <= 0) rotorspeed = 0; 383 //velocityDir.normalize(); 384 //rot += Vector(0,0,1); 385 //rotVal -= .4; 386 } 387 else 388 { 389 //if(rotorspeed <= 0.05) rotorspeed += 0.05; 390 } 391 392 velocity += accel*3; 393 if((this->getAbsDirX()).y <= 0.3 && (this->getAbsDirX()).y >= -0.3) this->shiftDir(Quaternion(rotValZ, Vector(0,0,1))); 394 if((this->getAbsDirZ()).y <= 0.3 && (this->getAbsDirZ()).y >= -0.3) this->shiftDir(Quaternion(rotValX, Vector(1,0,0))); 296 accel -= Vector(0,rotVal,0); 297 298 velocity += accel * 3.0; 299 300 this->setRelDirSoft(this->direction * Quaternion(-accel.x, Vector(0,0,1)) * Quaternion(accel.z, Vector(1,0,0)), 5); 301 302 this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z, Vector(1,0,0)), 10); 303 this->rotorNodeLeft.setRelDirSoft(Quaternion(-2.0*accel.x, Vector(0,0,1)), 10); 304 305 this->wingNodeRight.setRelDirSoft(Quaternion(accel.z, Vector(1,0,0)), 10); 306 this->rotorNodeRight.setRelDirSoft(Quaternion(-2.0*accel.x, Vector(0,0,1)), 10); 395 307 } 396 308 … … 440 352 this->getModel(4)->draw(); 441 353 glPopMatrix (); 442 443 this->getWeaponManager()->draw();444 }445 446 447 /**448 * weapon manipulation by the player449 */450 void Hover::weaponAction()451 {452 if( this->bFire)453 {454 this->getWeaponManager()->fire();455 }456 354 } 457 355 … … 464 362 465 363 if( event.type == KeyMapper::PEV_LEFT) 466 364 this->bLeft = event.bPressed; 467 365 else if( event.type == KeyMapper::PEV_RIGHT) 468 366 this->bRight = event.bPressed; 469 367 else if( event.type == SDLK_e) 470 368 this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); … … 472 370 this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); 473 371 else if( event.type == KeyMapper::PEV_UP) 474 this->b Up= event.bPressed; //this->shiftCoor(0,.1,0);372 this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); 475 373 else if( event.type == KeyMapper::PEV_DOWN) 476 this->b Down= event.bPressed; //this->shiftCoor(0,-.1,0);374 this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); 477 375 else if( event.type == EV_MOUSE_MOTION) 478 376 { … … 480 378 this->yMouse = event.yRel*mouseSensitivity; 481 379 482 this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))); 483 380 // rotate the Player around the y-axis 381 this->direction *= Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0)); 382 383 // rotate the Camera around the z-axis 484 384 Quaternion yDir = Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)); 485 486 487 385 if ((this->cameraNode.getAbsDirY()).y < 0.5) 488 386 { 489 if((this->cameraNode.getAbsDirX()).y > 0)490 {387 if((this->cameraNode.getAbsDirX()).y > 0) 388 { 491 389 if(yMouse > 0) this->cameraNode.shiftDir(yDir); 492 }493 else494 {495 496 }390 } 391 else 392 { 393 if(yMouse < 0) this->cameraNode.shiftDir(yDir); 394 } 497 395 } 498 else this->cameraNode.shiftDir(yDir); ;499 500 } 396 else this->cameraNode.shiftDir(yDir); 397 } 398 } -
trunk/src/world_entities/space_ships/hover.h
r6803 r6805 35 35 private: 36 36 void init(); 37 void movement(float time); 37 38 38 39 private: 39 void calculateVelocity(float time); 40 void weaponAction(); 41 42 bool bUp; //!< up button pressed. 43 bool bDown; //!< down button pressed. 40 bool bForward; //!< forward button pressed. 41 bool bBackward; //!< backward button pressed. 44 42 bool bLeft; //!< left button pressed. 45 43 bool bRight; //!< right button pressed. 46 44 bool bAscend; //!< ascend button pressed. 47 45 bool bDescend; //!< descend button presses. 48 bool bFire; //!< fire button pressed.49 bool bRollL; //!< rolling button pressed (left)50 bool bRollR; //!< rolling button pressed (right)51 46 52 47 float xMouse; //!< mouse moved in x-Direction … … 65 60 PNode cameraNode; 66 61 67 Vector velocity; //!< the velocity of the player.68 Vector velocityDir; //!< the direction of the velocity of the spaceship69 float travelSpeed; //!< the current speed of the player(to make soft movement)70 float acceleration; //!< the acceleration of the player.62 Vector velocity; //!< the velocity of the Hover. 63 Quaternion direction; //!< the direction of the Hover. 64 float travelSpeed; //!< the current speed of the Hove (to make soft movement) 65 float acceleration; //!< the acceleration of the Hover. 71 66 //float rotorspeed; //!< the speed of the rotor. 72 67 //float tailrotorspeed; //!< the relativ speed ot the tail rotor
Note: See TracChangeset
for help on using the changeset viewer.