Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 19, 2006, 11:18:22 AM (17 years ago)
Author:
marcscha
Message:

velocity fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/playability/src/world_entities/space_ships/space_ship.cc

    r10092 r10095  
    326326
    327327 
    328   this->trail = new Trail( 15, 10, .2);
    329   this->trail->setParent( this);
     328  this->trail = new Trail( 3, 3, .2, this);
     329  //this->trail->setParent( this);
    330330  this->trail->setTexture( "maps/engine.png");
    331331
    332   this->trailL = new Trail( 15, 10, .2);
    333   this->trailL->setParent( this);
     332  this->trailL = new Trail( 3, 3, .2, this);
     333  //this->trailL->setParent( this);
    334334  this->trailL->setTexture( "maps/engine.png");
    335335
    336   this->trailR = new Trail( 15, 10, .2);
    337   this->trailR->setParent( this);
     336  this->trailR = new Trail( 3, 3, .2, this);
     337  //this->trailR->setParent( this);
    338338  this->trailR->setTexture( "maps/engine.png");
    339339}
     
    371371{
    372372  this->secWeaponMan.showCrosshair();
    373   /*for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
    374   {
    375     if( likely( dynamic_cast<WorldEntity*>(*it) != NULL))
    376       dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_01);
    377   }*/
    378373  this->toList( OM_GROUP_01 );
     374  for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
     375  {
     376    if( likely( dynamic_cast<Weapon*>(*it) != NULL))
     377      dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_00_PROJ);
     378  }
    379379  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true);
    380380  //this->attachCamera();
     
    385385{
    386386  this->secWeaponMan.hideCrosshair();
    387   /*for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
    388   {
    389     if( likely(dynamic_cast<WorldEntity*>(*it) != NULL))
    390       dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_00);
    391   }*/
    392387  this->toList( OM_GROUP_00);
     388  for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
     389  {
     390    if( likely( dynamic_cast<Weapon*>(*it) != NULL))
     391      dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_01_PROJ);
     392  }
    393393  //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false);
    394394  //this->detachCamera();
     
    492492  this->acceleration = this->travelSpeed * 2;
    493493
    494   /*
    495   if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() )
    496   {
    497     if (xMouse > controlVelocityX) xMouse = controlVelocityX;
    498     else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
    499     if (yMouse > controlVelocityY) yMouse = controlVelocityY;
    500     else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
    501 
    502     pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
    503 
    504     mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
    505     xMouse = yMouse = 0;
    506   }
    507 */
    508 
    509   // spaceship controlled movement fire(bool bF){ this->bFire = bF;}
    510   //if (this->getOwner() == this->getHostID())
    511 
    512   //is->calculateVelocity(time);
    513 
    514 
    515   //vector move = velocity*time;
    516 
    517   /*
    518   //orient the velocity in the direction of the spaceship.
    519   travelSpeed = velocity.len();
    520   velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity;
    521   velocity = (velocity.getNormalized())*travelSpeed;
    522   */
    523494  this->movement(time);
    524495
     
    527498  this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
    528499
     500 
     501  this->velocity  = (this->getAbsCoor() - this->oldPos) / time;
     502  this->oldPos    = this->getAbsCoor();
     503
    529504  this->trail->tick(time);
    530505  this->trailL->tick(time);
    531506  this->trailR->tick(time);
     507
    532508  //orient the spaceship in direction of the mouse
    533509  /*
     
    600576{
    601577  PRINTF(0)("spaceship destroy\n");
    602   /*
     578 
    603579  EmitterNode* node  = NULL;
    604580  DotEmitter* emitter = NULL;
     
    628604  node->setVelocity( this->getParent()->getVelocity());
    629605  node->setAbsCoor( this->getAbsCoor());
    630   node->start();*/
     606  node->start();
     607/*
    631608  PNode* node          = new PNode();
    632609  node->setAbsCoor(this->getAbsCoor());
    633610  Explosion* explosion = new Explosion();
    634611  explosion->explode( node, Vector(5,5,5));
    635 
     612*/
    636613  this->setAbsCoor(Vector(-10000,10000,10000));
    637614  this->hide();
    638615
    639616  this->toList( OM_DEAD);
    640   /*for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
    641   {
    642     if( dynamic_cast<WorldEntity*>(*it) != NULL)
     617  for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
     618  {
     619    if( likely( dynamic_cast<Weapon*>(*it) != NULL))
    643620      dynamic_cast<WorldEntity*>(*it)->toList( OM_DEAD);
    644   }*/
     621  }
    645622    PRINTF(0)("spaceship destroy == ship translated \n");
    646623}
     
    654631      dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_00);
    655632  }*/
    656   /*if( this->hasPlayer())
     633  if( this->hasPlayer())
     634  {
    657635    this->toList( OM_GROUP_01);
     636    for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
     637        {
     638          if( likely( dynamic_cast<Weapon*>(*it) != NULL))
     639                dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_00_PROJ);
     640        }
     641  }
    658642  else
    659     this->toList( OM_GROUP_00);*/
     643  {
     644    this->toList( OM_GROUP_00);
     645    for(ObjectList<PNode>::const_iterator it = this->getNodesChildren().begin(); it != this->getNodesChildren().end(); it++)
     646        {
     647          if( likely( dynamic_cast<Weapon*>(*it) != NULL))
     648                dynamic_cast<WorldEntity*>(*it)->toList( OM_GROUP_01_PROJ);
     649        }
     650  }
    660651
    661652}
     
    664655void SpaceShip::damage(float pDamage, float eDamage){
    665656  PRINTF(0)("ship hit for (%f,%f) \n",pDamage,eDamage);
    666   PRINTF(0)("SHIP HIT - SHIP HIT - SHIP HIT\n");
    667657
    668658  if( this->shieldActive) {
     
    800790  float pi = 3.14;
    801791 
     792  Vector tempVelocity;
    802793
    803794  switch(this->getPlaymode())
     
    807798      // these routines will change the travel movement into zero in a short amout of time, if the player
    808799      // doesn't press any buttons.
    809       if (this->velocity.x >= 0)
    810       {
    811         if (this->velocity.x > airCoeff*this->acceleration * dt)
    812           this->velocity.x -= airCoeff* this->acceleration * dt;
     800      if (tempVelocity.x >= 0)
     801      {
     802        if (tempVelocity.x > airCoeff*this->acceleration * dt)
     803          tempVelocity.x -= airCoeff* this->acceleration * dt;
    813804        else
    814           this->velocity.x = 0;
     805          tempVelocity.x = 0;
    815806      }
    816807      else
    817808      {
    818         if (this->velocity.x < -airCoeff*this->acceleration * dt)
    819           this->velocity.x += airCoeff* this->acceleration * dt;
     809        if (tempVelocity.x < -airCoeff*this->acceleration * dt)
     810          tempVelocity.x += airCoeff* this->acceleration * dt;
    820811        else
    821           this->velocity.x = 0;
    822       }
    823       if (this->velocity.z >= 0)
    824       {
    825         if (this->velocity.z > airCoeff*this->acceleration * dt)
    826           this->velocity.z -= airCoeff* this->acceleration * dt;
     812          tempVelocity.x = 0;
     813      }
     814      if (tempVelocity.z >= 0)
     815      {
     816        if (tempVelocity.z > airCoeff*this->acceleration * dt)
     817          tempVelocity.z -= airCoeff* this->acceleration * dt;
    827818        else
    828           this->velocity.z = 0;
     819          tempVelocity.z = 0;
    829820      }
    830821      else
    831822      {
    832         if (this->velocity.z < -airCoeff*this->acceleration * dt)
    833           this->velocity.z += airCoeff* this->acceleration * dt;
     823        if (tempVelocity.z < -airCoeff*this->acceleration * dt)
     824          tempVelocity.z += airCoeff* this->acceleration * dt;
    834825        else
    835           this->velocity.z = 0;
     826          tempVelocity.z = 0;
    836827      }
    837828   
     
    851842        if(this->getRelCoor().x < this->travelDistancePlus.x)
    852843        {
    853           if (this->velocity.x < this->travelSpeed)
     844          if (tempVelocity.x < this->travelSpeed)
    854845          {
    855             this->velocity.x += (airCoeff + 1.0)*this->acceleration*dt;
     846            tempVelocity.x += (airCoeff + 1.0)*this->acceleration*dt;
    856847          }
    857848          else
    858849          {
    859             this->velocity.x = this->travelSpeed;
     850            tempVelocity.x = this->travelSpeed;
    860851          }
    861852        }
    862853        else
    863854        {
    864           this->velocity.x = 0.0f;
     855          tempVelocity.x = 0.0f;
    865856        }
    866857      }
     
    870861        if(this->getRelCoor().x > this->travelDistanceMinus.x)
    871862        {
    872           if (this->velocity.x > -this->travelSpeed)
     863          if (tempVelocity.x > -this->travelSpeed)
    873864          {
    874             this->velocity.x -= (airCoeff + 1.0)*this->acceleration*dt;
     865            tempVelocity.x -= (airCoeff + 1.0)*this->acceleration*dt;
    875866          }
    876867          else
    877868          {
    878             this->velocity.x = -this->travelSpeed;
     869            tempVelocity.x = -this->travelSpeed;
    879870          }
    880871        }
    881872        else
    882873        {
    883           this->velocity.x = 0.0f;
     874          tempVelocity.x = 0.0f;
    884875        }
    885876      }
     
    889880        if(this->getRelCoor().z > this->travelDistanceMinus.y)
    890881        {
    891           if (this->velocity.z > -this->travelSpeed)
     882          if (tempVelocity.z > -this->travelSpeed)
    892883          {
    893             this->velocity.z -= (airCoeff + 1.0)*this->acceleration*dt;
     884            tempVelocity.z -= (airCoeff + 1.0)*this->acceleration*dt;
    894885          }
    895886          else
    896887          {
    897             this->velocity.z = -this->travelSpeed;
     888            tempVelocity.z = -this->travelSpeed;
    898889          }
    899890        }
    900891        else
    901892        {
    902           this->velocity.z = 0.0f;
     893          tempVelocity.z = 0.0f;
    903894        }
    904895        this->setRelDirSoft(Quaternion(-pi/6, Vector(1,0,0)), 6);
     
    909900        if(this->getRelCoor().z < this->travelDistancePlus.y)
    910901        {
    911           if (this->velocity.z < this->travelSpeed)
     902          if (tempVelocity.z < this->travelSpeed)
    912903          {
    913             this->velocity.z += (airCoeff + 1.0)*this->acceleration*dt;
     904            tempVelocity.z += (airCoeff + 1.0)*this->acceleration*dt;
    914905          }
    915906          else
    916907          {
    917             this->velocity.z = this->travelSpeed;
     908            tempVelocity.z = this->travelSpeed;
    918909          }
    919910        }
    920911        else
    921912        {
    922           this->velocity.z = 0.0f;
     913          tempVelocity.z = 0.0f;
    923914        }
    924915        this->setRelDirSoft(Quaternion(pi/6, Vector(1,0,0)), 6);
     
    931922
    932923      this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
    933       this->shiftCoor (this->velocity * dt);
     924      this->shiftCoor (tempVelocity * dt);
    934925
    935926    //normalisation of the vectors (vector sum must be <= travelspeed)
    936     float xzNorm = sqrt(pow(this->velocity.x, 2) + pow(this->velocity.z, 2));
     927    float xzNorm = sqrt(pow(tempVelocity.x, 2) + pow(tempVelocity.z, 2));
    937928    if (xzNorm > this->travelSpeed)
    938929    {
    939       this->velocity.x = this->velocity.x/xzNorm * this->travelSpeed;
    940       this->velocity.z = this->velocity.z/xzNorm * this->travelSpeed;
     930      tempVelocity.x = tempVelocity.x/xzNorm * this->travelSpeed;
     931      tempVelocity.z = tempVelocity.z/xzNorm * this->travelSpeed;
    941932    }
    942933
     
    945936   
    946937    //set new coordinates calculated through key- events.
    947     this->shiftCoor (this->velocity * dt);
     938    this->shiftCoor (tempVelocity * dt);
    948939    break;
    949940    }
     
    954945  }
    955946 
     947
     948/*
    956949  this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0));
    957   this->shiftCoor (this->velocity * dt);
    958  
    959   float angle = this->velocity.z / travelSpeed * pi / 3;
     950  this->shiftCoor (tempVelocity * dt);
     951
     952  float angle = tempVelocity.z / travelSpeed * pi / 3;
    960953  if (angle > pi/4) angle = pi/4;
    961954  if (angle < -pi/4) angle = -pi/4;
    962955  this->setRelDirSoft(Quaternion(angle, Vector(1,0,0)), 5.0f);
     956*/
     957 
    963958}
    964959
Note: See TracChangeset for help on using the changeset viewer.