Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 25, 2006, 5:35:49 PM (20 years ago)
Author:
bensch
Message:

merged the Spaceshipcontrol back to the trunk

File:
1 edited

Legend:

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

    r6637 r6724  
    3636
    3737/**
    38  *  creates the controlable Spaceship
     38 *  creates the controlable Helicopter
    3939 */
    4040Helicopter::Helicopter()
     
    4444
    4545/**
    46  *  destructs the spaceship, deletes alocated memory
     46 *  destructs the helicopter, deletes alocated memory
    4747 */
    4848Helicopter::~Helicopter ()
     
    5151
    5252/**
    53  * loads a Spaceships information from a specified file.
    54  * @param fileName the name of the File to load the spaceship from (absolute path)
     53 * loads a Helicopter information from a specified file.
     54 * @param fileName the name of the File to load the helicopter from (absolute path)
    5555 */
    5656Helicopter::Helicopter(const char* fileName)
     
    108108  this->setClassID(CL_HELICOPTER, "Helicopter");
    109109
    110   PRINTF(4)("SPACESHIP INIT\n");
     110  PRINTF(4)("HELICOPTER INIT\n");
    111111
    112112  this->loadModel("models/ships/helicopter_#.obj", 1.0);
     
    118118  xMouse = yMouse = 0;
    119119  mouseSensitivity = 0.05;
     120  controlVelocityX = 100;
     121  controlVelocityY = 100;
    120122  //rotorspeed = 1;
    121123  //tailrotorspeed = 0;
    122124
    123125  //cycle = 0.0;
     126 
     127  // cameraissue
     128  this->cameraNode.setParent(this);
     129  this->cameraNode.setParentMode(PNODE_ALL);
     130 
     131 
     132  // rotors
     133  this->topRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     134  this->tailRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     135 
     136  this->topRotor.setParent(this);
     137  this->tailRotor.setParent(this);
     138 
     139  this->topRotor.setRelCoor(Vector(-0.877,0.627,0));
     140  this->tailRotor.setRelCoor(Vector(-4.43,0.297,0.068));
     141  this->tailRotor.setAbsDir(Quaternion(M_PI_2,Vector(1,0,0)));
     142 
     143  this->loadModel("models/ships/rotor.obj",1.0,3);
     144  this->loadModel("models/ships/rotor.obj",0.2,4);
    124145
    125146
     
    127148  this->velocity = Vector(0.0,0.0,0.0);
    128149  this->velocityDir = Vector(1.0,0.0,0.0);
    129 
    130150//   GLGuiButton* button = new GLGuiPushButton();
    131151//   button->show();
     
    177197//   this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
    178198
    179   this->getWeaponManager()->getFixedTarget()->setParent(this);
    180   this->getWeaponManager()->getFixedTarget()->setRelCoor(100000,0,0);
     199  this->getWeaponManager()->getFixedTarget()->setParent(&(this->cameraNode));
     200  this->getWeaponManager()->getFixedTarget()->setRelCoor(0,0,0);
    181201
    182202  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
     
    193213}
    194214
    195 
     215void  Helicopter::attachCamera()
     216{
     217  State::getCamera()->setParentSoft(this->getWeaponManager()->getFixedTarget());
     218  State::getCameraTarget()->setParentSoft(this->getWeaponManager()->getFixedTarget());
     219
     220}
    196221
    197222
     
    221246
    222247/**
    223  *  the action occuring if the spaceship left the game
     248 *  the action occuring if the helicopter left the game
    224249*/
    225250void Helicopter::leftWorld ()
     
    249274void Helicopter::tick (float time)
    250275{
    251   /*
    252   tailrotorspeed += xMouse/20;
    253   if (tailrotorspeed >= 0.07) tailrotorspeed = 0.07;
    254   else if (tailrotorspeed <= -0.07) tailrotorspeed = -0.07;
    255 
    256   if (tailrotorspeed > 0.0008) tailrotorspeed -= 0.001;
    257   else if (tailrotorspeed < -0.0008) tailrotorspeed += 0.001;
    258   if (tailrotorspeed <= 0.001 && tailrotorspeed >= -0.001) tailrotorspeed = 0;
    259   */
     276  if( xMouse != 0 || yMouse != 0)
     277   {
     278    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
     279    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
     280    if (yMouse > controlVelocityY) yMouse = controlVelocityY;
     281    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
     282  }
     283 
     284  // rotorrotation
     285  this->topRotor.shiftDir(Quaternion(time*10, Vector(0,1,0)));
     286  this->tailRotor.shiftDir(Quaternion(time*10, Vector(0,1,0)));
    260287 
    261288  // spaceship controlled movement
     
    419446{
    420447  WorldEntity::draw();
     448 
     449  glMatrixMode(GL_MODELVIEW);
     450    glPushMatrix();
     451
     452    /* translate */
     453    glTranslatef (this->topRotor.getAbsCoor ().x,
     454                  this->topRotor.getAbsCoor ().y,
     455                  this->topRotor.getAbsCoor ().z);
     456    Vector tmpRot = this->topRotor.getAbsDir().getSpacialAxis();
     457    glRotatef (this->topRotor.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     458    this->getModel(3)->draw();
     459
     460    glPopMatrix ();
     461    glPushMatrix();
     462
     463    /* translate */
     464    glTranslatef (this->tailRotor.getAbsCoor ().x,
     465                  this->tailRotor.getAbsCoor ().y,
     466                  this->tailRotor.getAbsCoor ().z);
     467    tmpRot = this->tailRotor.getAbsDir().getSpacialAxis();
     468    glRotatef (this->tailRotor.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     469    this->getModel(4)->draw();
     470
     471    glPopMatrix ();
    421472
    422473  this->getWeaponManager()->draw();
     
    465516    this->yMouse = event.yRel*mouseSensitivity;
    466517
    467     this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))/*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))*/);
    468   }
     518    this->shiftDir(Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0)));
     519   
     520    Quaternion yDir = Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1));
     521
     522   
     523    if ((this->cameraNode.getAbsDirY()).y < 0.5)
     524    {
     525     if((this->cameraNode.getAbsDirX()).y > 0)
     526     {
     527        if(yMouse > 0) this->cameraNode.shiftDir(yDir);
     528     }
     529     else
     530     {
     531         if(yMouse < 0) this->cameraNode.shiftDir(yDir);
     532     }
     533    }
     534    else this->cameraNode.shiftDir(yDir);;
     535    }
    469536}
    470537
Note: See TracChangeset for help on using the changeset viewer.