Changeset 6693 in orxonox.OLD for branches/network/src/world_entities/space_ships
- Timestamp:
- Jan 25, 2006, 2:19:46 PM (19 years ago)
- Location:
- branches/network/src/world_entities/space_ships
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/space_ships/helicopter.cc
r6512 r6693 117 117 bFire = false; 118 118 xMouse = yMouse = 0; 119 mouseSensitivity = 0.0 01;120 rotorspeed = 1;121 tailrotorspeed = 0;122 123 cycle = 0.0;124 125 126 travelSpeed = 15.0;119 mouseSensitivity = 0.05; 120 //rotorspeed = 1; 121 //tailrotorspeed = 0; 122 123 //cycle = 0.0; 124 125 126 //travelSpeed = 15.0; 127 127 this->velocity = Vector(0.0,0.0,0.0); 128 128 this->velocityDir = Vector(1.0,0.0,0.0); … … 134 134 135 135 //add events to the eventlist 136 registerEvent( SDLK_w);137 registerEvent( SDLK_s);138 registerEvent( SDLK_a);139 registerEvent( SDLK_d);140 registerEvent(SDLK_q);136 registerEvent(KeyMapper::PEV_UP); 137 registerEvent(KeyMapper::PEV_DOWN); 138 registerEvent(KeyMapper::PEV_LEFT); 139 registerEvent(KeyMapper::PEV_RIGHT); 140 //registerEvent(SDLK_q); 141 141 registerEvent(SDLK_e); 142 142 registerEvent(SDLK_c); … … 144 144 registerEvent(KeyMapper::PEV_NEXT_WEAPON); 145 145 registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); 146 registerEvent(SDLK_PAGEUP);147 registerEvent(SDLK_PAGEDOWN);146 //registerEvent(SDLK_PAGEUP); 147 //registerEvent(SDLK_PAGEDOWN); 148 148 registerEvent(EV_MOUSE_MOTION); 149 149 … … 249 249 void Helicopter::tick (float time) 250 250 { 251 /* 251 252 tailrotorspeed += xMouse/20; 252 253 if (tailrotorspeed >= 0.07) tailrotorspeed = 0.07; … … 256 257 else if (tailrotorspeed < -0.0008) tailrotorspeed += 0.001; 257 258 if (tailrotorspeed <= 0.001 && tailrotorspeed >= -0.001) tailrotorspeed = 0; 258 259 */ 260 259 261 // spaceship controlled movement 260 262 this->calculateVelocity(time); 261 263 262 Vector move = (velocity) ;264 Vector move = (velocity)*time; 263 265 264 266 // this is the air friction (necessary for a smooth control) 265 267 if(velocity.len() != 0) velocity -= velocity*0.1; 268 269 //travelSpeed = velocity.len(); 266 270 267 271 //physics: Gravity 268 this->shiftCoor(Vector(0,-1,0));272 /*this->shiftCoor(Vector(0,-1,0)); 269 273 270 274 this->shiftCoor(getAbsDirY()*rotorspeed); 271 275 */ 276 277 /* 272 278 //hoover effect 273 279 cycle += time; 274 280 this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); 281 */ 275 282 276 283 //readjust … … 281 288 282 289 this->shiftCoor (move); 283 this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0)));290 //this->shiftDir(Quaternion(-M_PI/4*tailrotorspeed, Vector(0,1,0))); 284 291 285 292 this->getWeaponManager()->tick(time); … … 295 302 { 296 303 Vector accel(0.0, 0.0, 0.0); 297 Vector rot(0.0, 0.0, 0.0);298 float rotVal = 0.0;304 float rotValX = 0.0; 305 float rotValZ = 0.0; 299 306 /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ 300 307 /* calculate the direction in which the craft is heading */ … … 304 311 //this->shiftCoor(this->getAbsDirX()); 305 312 //accel -= this->getAbsDirY(); 306 rot += Vector (0,0,1); 307 rotVal -= time/5; 313 314 accel += Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); 315 if((this->getAbsDirX()).y >= -0.1) rotValZ -= time; 308 316 } 309 317 else 310 318 { 311 if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time /8, Vector(0,0,1)));319 if(this->getAbsDirX().y < -.02) this->shiftDir(Quaternion(time, Vector(0,0,1))); 312 320 } 313 321 … … 316 324 //this->shiftCoor((this->getAbsDirX())*-1); 317 325 //accel -= this->getAbsDirY(); 318 rot += Vector (0,0,1); 319 rotVal += time/5; 326 327 accel -= Vector((this->getAbsDirX()).x,0,(this->getAbsDirX()).z); 328 rotValZ += time; 320 329 } 321 330 else 322 331 { 323 if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time /8, Vector(0,0,1)));332 if(this->getAbsDirX().y > 0.02) this->shiftDir(Quaternion(-time, Vector(0,0,1))); 324 333 } 325 334 … … 329 338 //accel -= this->getAbsDirY(); 330 339 //velocityDir.normalize(); 331 rot += Vector(1,0,0); 332 rotVal -= time/5; 340 341 accel -= Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); 342 rotValX -= time; 333 343 } 334 344 else 335 345 { 336 if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time /5, Vector(1,0,0)));346 if(this->getAbsDirZ().y > 0.02) this->shiftDir(Quaternion(time, Vector(1,0,0))); 337 347 } 338 348 … … 340 350 { 341 351 //this->shiftDir(Quaternion(-time, Vector(0,1,0))); 342 accel += this->getAbsDirY();352 //accel += this->getAbsDirY(); 343 353 //velocityDir.normalize(); 344 rot += Vector(1,0,0); 345 rotVal += time/5; 354 355 accel += Vector((this->getAbsDirZ()).x,0,(this->getAbsDirZ()).z); 356 rotValX += time; 346 357 } 347 358 else 348 359 { 349 if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time /5, Vector(1,0,0)));360 if(this->getAbsDirZ().y < -0.02) this->shiftDir(Quaternion(-time, Vector(1,0,0))); 350 361 } 351 362 … … 371 382 //this->shiftDir(Quaternion(time, Vector(0,0,1))); 372 383 373 rotorspeed += 0.05; 374 if (rotorspeed >= 2) rotorspeed = 2; 384 accel += this->getAbsDirY(); 385 //rotorspeed += 0.05; 386 //if (rotorspeed >= 2) rotorspeed = 2; 375 387 //velocityDir.normalize(); 376 388 //rot += Vector(0,0,1); … … 379 391 else 380 392 { 381 if(rotorspeed >= 1.05) rotorspeed -= 0.05;393 //if(rotorspeed >= 1.05) rotorspeed -= 0.05; 382 394 } 383 395 … … 386 398 //this->shiftDir(Quaternion(-time, Vector(0,0,1))); 387 399 388 rotorspeed -= 0.05; 389 if (rotorspeed <= 0) rotorspeed = 0; 400 accel -= this->getAbsDirY(); 401 //rotorspeed -= 0.05; 402 //if (rotorspeed <= 0) rotorspeed = 0; 390 403 //velocityDir.normalize(); 391 404 //rot += Vector(0,0,1); … … 394 407 else 395 408 { 396 if(rotorspeed <= 0.05) rotorspeed += 0.05;397 } 398 399 //velocity += accel;400 rot.normalize();401 this->shiftDir(Quaternion(rotVal, rot));409 //if(rotorspeed <= 0.05) rotorspeed += 0.05; 410 } 411 412 velocity += accel*3; 413 if((this->getAbsDirX()).y <= 0.3 && (this->getAbsDirX()).y >= -0.3) this->shiftDir(Quaternion(rotValZ, Vector(0,0,1))); 414 if((this->getAbsDirZ()).y <= 0.3 && (this->getAbsDirZ()).y >= -0.3) this->shiftDir(Quaternion(rotValX, Vector(1,0,0))); 402 415 } 403 416 … … 429 442 430 443 431 if( event.type == SDLK_a)444 if( event.type == KeyMapper::PEV_LEFT) 432 445 this->bLeft = event.bPressed; 433 else if( event.type == SDLK_d)446 else if( event.type == KeyMapper::PEV_RIGHT) 434 447 this->bRight = event.bPressed; 435 448 else if( event.type == KeyMapper::PEV_FIRE1) … … 443 456 else if( event.type == SDLK_c) 444 457 this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); 445 else if( event.type == SDLK_w)458 else if( event.type == KeyMapper::PEV_UP) 446 459 this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); 447 else if( event.type == SDLK_s)460 else if( event.type == KeyMapper::PEV_DOWN) 448 461 this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); 449 462 else if( event.type == EV_MOUSE_MOTION) … … 452 465 this->yMouse = event.yRel*mouseSensitivity; 453 466 454 //this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1)));467 this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))/*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))*/); 455 468 } 456 469 } -
branches/network/src/world_entities/space_ships/helicopter.h
r6512 r6693 57 57 float xMouse; //!< mouse moved in x-Direction 58 58 float yMouse; //!< mouse moved in y-Direction 59 int yInvert; 59 60 float mouseSensitivity; //!< the mouse sensitivity 60 float cycle; //!< hovercycle61 //float cycle; //!< hovercycle 61 62 62 63 Vector velocity; //!< the velocity of the player. … … 64 65 float travelSpeed; //!< the current speed of the player (to make soft movement) 65 66 float acceleration; //!< the acceleration of the player. 66 float rotorspeed; //!< the speed of the rotor.67 float tailrotorspeed; //!< the relativ speed ot the tail rotor67 //float rotorspeed; //!< the speed of the rotor. 68 //float tailrotorspeed; //!< the relativ speed ot the tail rotor 68 69 69 70 float airViscosity; -
branches/network/src/world_entities/space_ships/space_ship.cc
r6688 r6693 128 128 this->addWeapon(cannon, 0, 6); 129 129 130 //this->addWeapon(turret, 3, 0);131 132 130 this->getWeaponManager()->changeWeaponConfig(1); 133 131 … … 137 135 bFire = false; 138 136 xMouse = yMouse = 0; 137 yInvert = 1; 139 138 mouseSensitivity = 0.001; 140 airViscosity = 1.0; 141 cycle = 0.0; 139 airViscosity = 0.05; 140 controlVelocityX = 25; 141 controlVelocityY = 150; 142 shipInertia = 0.5 ; 143 // cycle = 0.0; 142 144 143 145 this->setMaxEnergy(100); 144 146 this->setEnergy(80); 145 147 146 travelSpeed = 15.0; 147 this->velocity = Vector(0.0,0.0,0.0); 148 travelSpeed = 40.0; 149 acceleration = 3; 150 this->velocity = this->getAbsDirX()*travelSpeed; 148 151 this->mouseDir = this->getAbsDir(); 152 this->pitchDir = this->getAbsDir(); 149 153 150 154 // GLGuiButton* button = new GLGuiPushButton(); … … 160 164 161 165 //add events to the eventlist 162 registerEvent( SDLK_w);163 registerEvent( SDLK_s);164 registerEvent( SDLK_a);165 registerEvent( SDLK_d);166 registerEvent(SDLK_q);167 registerEvent(SDLK_e);166 registerEvent(KeyMapper::PEV_UP); 167 registerEvent(KeyMapper::PEV_DOWN); 168 registerEvent(KeyMapper::PEV_LEFT); 169 registerEvent(KeyMapper::PEV_RIGHT); 170 //registerEvent(SDLK_q); 171 //registerEvent(SDLK_e); 168 172 registerEvent(KeyMapper::PEV_FIRE1); 169 173 registerEvent(KeyMapper::PEV_NEXT_WEAPON); 170 174 registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); 171 registerEvent(SDLK_PAGEUP);172 registerEvent(SDLK_PAGEDOWN);175 //registerEvent(SDLK_PAGEUP); 176 //registerEvent(SDLK_PAGEDOWN); 173 177 registerEvent(EV_MOUSE_MOTION); 174 178 … … 285 289 this->weaponAction(); 286 290 291 if( xMouse != 0 || yMouse != 0) 292 { 293 if (xMouse > controlVelocityX) xMouse = controlVelocityX; 294 else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX; 295 if (yMouse > controlVelocityY) yMouse = controlVelocityY; 296 else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY; 297 298 pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0))); 299 300 mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir); 301 xMouse = yMouse = 0; 302 } 303 304 287 305 // if( this != State::getPlayer()->getControllable()) 288 306 // return; … … 291 309 this->calculateVelocity(time); 292 310 293 Vector move = (velocity)*time;311 Vector move = velocity*time; 294 312 295 313 //orient the velocity in the direction of the spaceship. … … 299 317 300 318 //orient the spaceship in direction of the mouse 301 rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)* 3.0);319 rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*shipInertia); 302 320 if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) 303 321 this->setAbsDir( rotQuat); … … 305 323 306 324 // this is the air friction (necessary for a smooth control) 307 if(velocity.len() != 0) velocity -= velocity*0.01; 325 if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; 326 else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; 327 328 //other physics (gravity) 329 //if(travelSpeed < 120) 330 //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time; 308 331 309 332 //hoover effect … … 312 335 313 336 //readjust 314 315 /*316 In the game "Yager" the spaceship gets readjusted when the player moves the mouse.317 I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox.318 */319 //if (xMouse != 0 && yMouse != 0)320 321 337 //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); 322 338 //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); … … 324 340 //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); 325 341 326 this->shiftCoor 342 this->shiftCoor(move); 327 343 328 344 … … 343 359 /* calculate the direction in which the craft is heading */ 344 360 345 Plane plane(Vector(0,1,0), Vector(0,0,0));361 //Plane plane(Vector(0,1,0), Vector(0,0,0)); 346 362 347 363 if( this->bUp ) 348 364 { 349 365 //this->shiftCoor(this->getAbsDirX()); 350 accel += (this->getAbsDirX())*2; 351 352 /* Heli-Steuerung 353 accel += (this->getAbsDirX()*2; 354 if( 355 */ 366 //accel += (this->getAbsDirX())*2; 367 accel += (this->getAbsDirX())*acceleration; 368 356 369 } 357 370 … … 359 372 { 360 373 //this->shiftCoor((this->getAbsDirX())*-1); 361 accel -= (this->getAbsDirX())*2; 374 //accel -= (this->getAbsDirX())*2; 375 accel -= (this->getAbsDirX())*0.5*acceleration; 362 376 } 363 377 … … 383 397 if( this->bRollL /* > -this->getRelCoor().z*2*/) 384 398 { 385 mouseDir *= Quaternion(-time , Vector(1,0,0));399 mouseDir *= Quaternion(-time*2, Vector(1,0,0)); 386 400 // accel -= rightDirection; 387 401 //velocityDir.normalize(); … … 391 405 if( this->bRollR /* > this->getRelCoor().z*2*/) 392 406 { 393 mouseDir *= Quaternion(time , Vector(1,0,0));407 mouseDir *= Quaternion(time*2, Vector(1,0,0)); 394 408 395 409 // accel += rightDirection; … … 438 452 void SpaceShip::process(const Event &event) 439 453 { 440 441 442 if( event.type == SDLK_a) 454 if( event.type == KeyMapper::PEV_LEFT) 443 455 this->bRollL = event.bPressed; 444 else if( event.type == SDLK_d)456 else if( event.type == KeyMapper::PEV_RIGHT) 445 457 this->bRollR = event.bPressed; 446 458 else if( event.type == KeyMapper::PEV_FIRE1) … … 452 464 else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) 453 465 this->previousWeaponConfig(); 454 else if( event.type == SDLK_w)466 else if( event.type == KeyMapper::PEV_UP) 455 467 this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); 456 else if( event.type == SDLK_s)468 else if( event.type == KeyMapper::PEV_DOWN) 457 469 this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); 458 470 else if( event.type == EV_MOUSE_MOTION) 459 471 { 460 this->xMouse = event.xRel; 461 this->yMouse = event.yRel; 462 mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))); 463 // if( xMouse*xMouse + yMouse*yMouse < 0.9) 464 //this->setAbsDir(mouseDir); 472 this->xMouse += event.xRel; 473 this->yMouse += event.yRel; 465 474 } 466 475 } -
branches/network/src/world_entities/space_ships/space_ship.h
r6634 r6693 65 65 float yMouse; //!< mouse moved in y-Direction 66 66 float mouseSensitivity; //!< the mouse sensitivity 67 float cycle; //!< hovercycle 67 int yInvert; 68 int controlVelocityX; 69 int controlVelocityY; 70 // float cycle; //!< hovercycle 68 71 69 72 Vector velocity; //!< the velocity of the player. 70 73 Quaternion mouseDir; //!< the direction where the player wants to fly 74 float shipInertia; //!< the inertia of the ship(how fast the ship reacts to a mouse input) 71 75 Quaternion rotQuat; 76 Quaternion pitchDir; 72 77 float travelSpeed; //!< the current speed of the player (to make soft movement) 73 78 float acceleration; //!< the acceleration of the player.
Note: See TracChangeset
for help on using the changeset viewer.