Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6805 in orxonox.OLD for trunk/src/world_entities/space_ships


Ignore:
Timestamp:
Jan 28, 2006, 12:20:58 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: hover works as it should

Location:
trunk/src/world_entities/space_ships
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/space_ships/helicopter.cc

    r6804 r6805  
    259259void Helicopter::collidesWith(WorldEntity* entity, const Vector& location)
    260260{
    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);
    266261}
    267262
     
    468463
    469464    glPopMatrix ();
    470 
    471   this->getWeaponManager()->draw();
    472465}
    473466
     
    515508    }
    516509}
    517 
    518 #include "weapons/aiming_turret.h"
    519 // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG
    520 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   else
    534   {
    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  
    4242    void calculateVelocity(float time);
    4343
    44     // !! temporary !!
    45     void ADDWEAPON();
    46 
    4744    bool                  bUp;                //!< up button pressed.
    4845    bool                  bDown;              //!< down button pressed.
  • trunk/src/world_entities/space_ships/hover.cc

    r6804 r6805  
    3939 */
    4040Hover::~Hover ()
    41 {
    42 }
     41{}
    4342
    4443/**
     
    9796void Hover::init()
    9897{
    99 //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
     98  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
    10099  this->setClassID(CL_HOVER, "Hover");
    101100
     
    106105  EventHandler::getInstance()->grabEvents(true);
    107106
    108   bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    109   bFire = false;
     107  bForward = bBackward = bLeft = bRight = bAscend = bDescend = false;
    110108  xMouse = yMouse = 0;
    111109  mouseSensitivity = 0.05;
     
    144142  this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3);
    145143  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);
    151144
    152145  //add events to the eventlist
     
    243236void Hover::collidesWith(WorldEntity* entity, const Vector& location)
    244237{
    245 
    246238}
    247239
     
    257249
    258250  if( xMouse != 0 || yMouse != 0)
    259    {
     251  {
    260252    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
    261253    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
     
    265257
    266258  // spaceship controlled movement
    267   this->calculateVelocity(dt);
     259  this->movement(dt);
    268260
    269261  Vector move = (velocity)*dt;
     
    271263  // this is the air friction (necessary for a smooth control)
    272264  if(velocity.len() != 0) velocity -= velocity*0.1;
    273   this->shiftCoor (move);
     265    this->shiftCoor (move);
    274266
    275267}
     
    279271 * @param time the timeslice since the last frame
    280272*/
    281 void Hover::calculateVelocity (float time)
     273void Hover::movement (float time)
    282274{
    283275  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  }
    376295  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);
    395307}
    396308
     
    440352  this->getModel(4)->draw();
    441353  glPopMatrix ();
    442 
    443   this->getWeaponManager()->draw();
    444 }
    445 
    446 
    447 /**
    448  * weapon manipulation by the player
    449 */
    450 void Hover::weaponAction()
    451 {
    452   if( this->bFire)
    453     {
    454       this->getWeaponManager()->fire();
    455     }
    456354}
    457355
     
    464362
    465363  if( event.type == KeyMapper::PEV_LEFT)
    466       this->bLeft = event.bPressed;
     364    this->bLeft = event.bPressed;
    467365  else if( event.type == KeyMapper::PEV_RIGHT)
    468       this->bRight = event.bPressed;
     366    this->bRight = event.bPressed;
    469367  else if( event.type == SDLK_e)
    470368    this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
     
    472370    this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);
    473371  else if( event.type == KeyMapper::PEV_UP)
    474     this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
     372    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
    475373  else if( event.type == KeyMapper::PEV_DOWN)
    476     this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
     374    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
    477375  else if( event.type == EV_MOUSE_MOTION)
    478376  {
     
    480378    this->yMouse = event.yRel*mouseSensitivity;
    481379
    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
    484384    Quaternion yDir = Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1));
    485 
    486 
    487385    if ((this->cameraNode.getAbsDirY()).y < 0.5)
    488386    {
    489      if((this->cameraNode.getAbsDirX()).y > 0)
    490      {
     387      if((this->cameraNode.getAbsDirX()).y > 0)
     388      {
    491389        if(yMouse > 0) this->cameraNode.shiftDir(yDir);
    492      }
    493      else
    494      {
    495          if(yMouse < 0) this->cameraNode.shiftDir(yDir);
    496      }
     390      }
     391      else
     392      {
     393        if(yMouse < 0) this->cameraNode.shiftDir(yDir);
     394      }
    497395    }
    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  
    3535  private:
    3636    void init();
     37    void movement(float time);
    3738
    3839  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.
    4442    bool                  bLeft;              //!< left button pressed.
    4543    bool                  bRight;             //!< right button pressed.
    4644    bool                  bAscend;            //!< ascend button pressed.
    4745    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)
    5146
    5247    float                 xMouse;             //!< mouse moved in x-Direction
     
    6560    PNode                 cameraNode;
    6661
    67     Vector                velocity;           //!< the velocity of the player.
    68     Vector                velocityDir;        //!< the direction of the velocity of the spaceship
    69     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.
    7166    //float                 rotorspeed;         //!< the speed of the rotor.
    7267    //float                 tailrotorspeed;     //!< the relativ speed ot the tail rotor
Note: See TracChangeset for help on using the changeset viewer.