Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 3, 2006, 11:55:31 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: better 2d-playable

Location:
branches/presentation/src/world_entities/space_ships
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/presentation/src/world_entities/space_ships/spacecraft_2d.cc

    r9061 r9074  
    3636CREATE_FACTORY(Spacecraft2D, CL_SPACECRAFT_2D);
    3737
     38/**
     39 *  destructs the spacecraft_2d, deletes alocated memory
     40 */
     41Spacecraft2D::~Spacecraft2D ()
     42{
     43  this->setPlayer(NULL);
     44}
    3845
    3946/**
     
    8693
    8794/**
    88  *  destructs the spacecraft_2d, deletes alocated memory
    89  */
    90 Spacecraft2D::~Spacecraft2D ()
    91 {
    92   this->setPlayer(NULL);
    93 }
    94 
    95 /**
    9695 * @brief initializes a Spacecraft2D
    9796 */
     
    101100  this->setClassID(CL_SPACECRAFT_2D, "Spacecraft2D");
    102101
    103   this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal);
    104 
     102  this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal );
    105103
    106104  bForward = bBackward = bLeft = bRight = false;
     
    110108  this->rotation = 0.0f;
    111109  this->acceleration = 10.0f;
    112   this->altitude = 0.0f;
     110  this->airFriction = 2.0f;
    113111
    114112  this->setHealthMax(100);
    115113  this->setHealth(100);
    116114
    117 
     115  this->travelNode = new PNode();
    118116  // camera - issue
    119   this->travelNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
     117  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     118  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
    120119  //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT);
    121120  //this->cameraNode.setParent(this);
    122121
    123   // rotors
    124122  // PARTICLES
    125123  this->burstEmitter = new DotEmitter(200, 5.0, .01);
     
    128126  this->burstEmitter->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1)));
    129127  this->burstEmitter->setName("Spacecraft2D_Burst_emitter_Left");
    130 
    131128
    132129  this->burstSystem = new SpriteParticles(1000);
     
    150147  this->registerEvent(KeyMapper::PEV_LEFT);
    151148  this->registerEvent(KeyMapper::PEV_RIGHT);
    152   this->registerEvent(KeyMapper::PEV_UP);
    153   this->registerEvent(KeyMapper::PEV_DOWN);
    154149  this->registerEvent(KeyMapper::PEV_FIRE1);
    155150  this->registerEvent(KeyMapper::PEV_NEXT_WEAPON);
     
    178173  this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0)));
    179174
    180   this->travelNode.setRelCoor(0,0,0);
    181   //this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
    182   //this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);
     175  this->cameraNode.setRelCoor(1,5,0);
     176  this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
     177  this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);
    183178
    184179  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
     
    205200}
    206201
    207 void Spacecraft2D::setTravelDirecton(const Quaternion& rot, float speed)
    208 {
    209   this->setPlayDirection(rot, speed);
    210 }
    211 
    212 void Spacecraft2D::setTravelSpeed(float travelSpeed)
    213 {
    214   this->travelSpeed = travelSpeed;
    215 }
    216 
    217 
    218 
    219202void Spacecraft2D::enter()
    220203{
    221204  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
    222 
    223   if (State::getCameraNode != NULL)
    224   {
    225     State::getCameraNode()->setParentSoft(&this->travelNode);
    226     State::getCameraNode()->setRelCoorSoft(-10, 50,0);
    227     State::getCameraTargetNode()->setParentSoft(&this->travelNode);
    228   }
    229205}
    230206
     
    235211
    236212}
     213
     214
     215void Spacecraft2D::enterPlaymode(Playable::Playmode playmode)
     216{
     217  switch(playmode)
     218  {
     219    case Playable::Full3D:
     220      if (State::getCameraNode != NULL)
     221      {
     222        State::getCameraNode()->setParentSoft(&this->cameraNode);
     223        State::getCameraNode()->setRelCoorSoft(-10, 0,0);
     224        State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
     225      }
     226      break;
     227
     228
     229    case Playable::Horizontal:
     230      if (State::getCameraNode != NULL)
     231      {
     232        this->travelNode->setAbsCoor(this->getAbsCoor());
     233        this->travelNode->updateNode(0.01f);
     234        this->setParentSoft(this->travelNode);
     235
     236        State::getCameraNode()->setParentSoft(this->travelNode);
     237        State::getCameraNode()->setRelCoorSoft(-10, 50,0);
     238        State::getCameraTargetNode()->setParentSoft(this->travelNode);
     239      }
     240      break;
     241
     242    default:
     243      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName());
     244  }
     245}
     246
    237247
    238248
     
    277287
    278288  // TRYING TO FIX PNode.
    279   //this->travelNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
    280   //this->travelNode.setRelDirSoft(this->getAbsDir(), 30.0f);
     289  this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
     290  this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
    281291}
    282292
     
    307317    accel += Vector(0, 0, this->acceleration);
    308318  }
    309 
    310319
    311320  switch(this->getPlaymode())
     
    316325
    317326        // this is the air friction (necessary for a smooth control)
    318 
    319         this->velocity += (accelerationDir)* dt;
     327        Vector damping = (this->velocity * this->airFriction);
     328
     329
     330        this->velocity += (accelerationDir - damping)* dt;
    320331        this->shiftCoor (this->velocity * dt);
    321332
     
    332343
    333344        this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
    334 
    335345      }
    336346      break;
     
    343353
    344354        // this is the air friction (necessary for a smooth control)
    345 
    346 
    347         this->velocity += (accelerationDir )* dt;
     355        Vector damping = (this->velocity * this->airFriction);
     356
     357
     358        this->velocity += (accelerationDir - damping)* dt;
    348359        this->shiftCoor (this->velocity * dt);
    349360
     
    352363        {
    353364          float maxRot = 10.0 * dt;
    354           if (unlikely(this->rotation > 0.01 || this->rotation < 0.01)) this->rotation /=1.5;
     365          if (unlikely(this->rotation > maxRot)) this->rotation = maxRot;
     366          if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot;
    355367          this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0));
    356368
     
    363375
    364376    default:
    365       PRINTF(2)("Playmode %s Not Implemented\n", Playable::playmodeToString(this->getPlaymode()).c_str());
     377      PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassName());
    366378  }
    367379}
     
    395407
    396408    // rotate the Player around the y-axis
    397     if (this->getPlaymode() == Playable::Full3D)
    398       this->rotation += xMouse;
     409    this->rotation += xMouse;
    399410
    400411    this->cameraLook += yMouse;
  • branches/presentation/src/world_entities/space_ships/spacecraft_2d.h

    r9061 r9074  
    2323    virtual void loadParams(const TiXmlElement* root);
    2424    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f);
    25     void setTravelDirecton(const Quaternion& rot, float speed = 0.0);
    26     void setTravelSpeed(float travelSpeed);
    27 
    2825    virtual void enter();
    2926    virtual void leave();
    30 
    31 
    3227
    3328    virtual void postSpawn();
     
    3934
    4035    virtual void process(const Event &event);
     36
     37  protected:
     38    virtual void enterPlaymode(Playable::Playmode playmode);
    4139
    4240  private:
     
    5452
    5553
     54    PNode*                travelNode;
    5655
    57     PNode                 travelNode;
    58     float                 travelSpeed;
    59 
     56    PNode                 cameraNode;
    6057    float                 cameraLook;
    6158    float                 rotation;
     
    6360   // Vector                velocity;           //!< the velocity of the Spacecraft2D.
    6461    Quaternion            direction;          //!< the direction of the Spacecraft2D.
     62    float                 travelSpeed;        //!< the current speed of the Hove (to make soft movement)
    6563    float                 acceleration;       //!< the acceleration of the Spacecraft2D.
    66     float                 maxSpeed;           //!< The Maximal speed of the Spacecraft2D.
     64    float                 airFriction;        //!< AirFriction.
    6765
    68     float                 altitude;           //!< The height in the Entity.
     66    float                 airViscosity;
    6967
    7068    ParticleEmitter*      burstEmitter;
Note: See TracChangeset for help on using the changeset viewer.