Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8504 in orxonox.OLD for branches/bsp_model/src/world_entities


Ignore:
Timestamp:
Jun 15, 2006, 10:39:55 PM (18 years ago)
Author:
patrick
Message:

bsp: md2 creature repared, no segfaults anymore. better entity handling now. but no good control

Location:
branches/bsp_model/src/world_entities/creatures
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/world_entities/creatures/md2_creature.cc

    r8490 r8504  
    6363
    6464  this->loadParams(doc.RootElement());
    65   this->toList(OM_GROUP_01);
    6665}
    6766
     
    7776  if (root != NULL)
    7877    this->loadParams(root);
     78}
     79
     80
     81/**
     82 * initializes a MD2Creature
     83 */
     84void MD2Creature::init()
     85{
     86  PRINTF(4)("MD2CREATURE INIT\n");
     87  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
     88  this->setClassID(CL_MD2_CREATURE, "MD2Creature");
     89
     90  this->toList(OM_GROUP_01);
    7991
    8092  //weapons:
     
    8799  cannon->setName("BFG");
    88100
    89    this->getWeaponManager().addWeapon(wpLeft, 1, 0);
    90    this->getWeaponManager().addWeapon(wpRight,1 ,1);
    91 //   this->getWeaponManager().addWeapon(cannon, 0, 6);
    92 
    93   //this->getWeaponManager().addWeapon(turret, 3, 0);
    94 
     101  this->addWeapon(wpLeft, 1, 0);
     102  this->addWeapon(wpRight,1 ,1);
    95103  this->getWeaponManager().changeWeaponConfig(0);
    96 }
    97 
    98 
    99 /**
    100  * initializes a MD2Creature
    101  */
    102 void MD2Creature::init()
    103 {
    104 //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
    105   this->setClassID(CL_MD2_CREATURE, "MD2Creature");
    106 
    107   PRINTF(4)("MD2CREATURE INIT\n");
    108 
     104
     105
     106  // pnode camera issue
     107  this->cameraConnNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     108  this->cameraConnNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
     109  this->cameraConnNode.setName("CameraConnectorNode");
     110  this->addChild(&this->cameraConnNode);
     111  this->cameraConnNode.addChild(State::getCameraTargetNode());
     112  this->cameraConnNode.addChild(State::getCameraNode());
     113  State::getCameraTargetNode()->setRelCoor(10,0,0);
     114
     115
     116  // control initialisation
    109117  this->mouseDirX *= Quaternion( M_PI * 0.75f, Vector(0,1,0));
    110118
     
    116124  cycle = 0.0;
    117125
    118   this->cameraConnNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    119   this->cameraConnNode.setName("CameraConnectorNode");
    120   this->addChild(&this->cameraConnNode);
    121   this->cameraConnNode.addChild(State::getCameraTargetNode());
    122   this->cameraConnNode.addChild(State::getCameraNode());
    123   State::getCameraTargetNode()->setRelCoor(10,0,0);
    124 
    125126  travelSpeed = 15.0;
    126127  this->velocity = Vector(0.0,0.0,0.0);
    127128
    128 //   GLGuiButton* button = new GLGuiPushButton();
    129 //   button->show();
    130 //   button->setLabel("orxonox");
    131 //   button->setBindNode(this);
    132129
    133130  //add events to the eventlist
    134   this->registerEvent(SDLK_w);
    135   this->registerEvent(SDLK_s);
    136   this->registerEvent(SDLK_a);
    137   this->registerEvent(SDLK_d);
     131  //add events to the eventlist
     132  registerEvent(KeyMapper::PEV_FORWARD);
     133  registerEvent(KeyMapper::PEV_BACKWARD);
     134  registerEvent(KeyMapper::PEV_LEFT);
     135  registerEvent(KeyMapper::PEV_RIGHT);
     136  registerEvent(KeyMapper::PEV_UP);
     137  registerEvent(KeyMapper::PEV_DOWN);
     138  registerEvent(KeyMapper::PEV_FIRE1);
     139  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
     140  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
     141  registerEvent(EV_MOUSE_MOTION);
    138142  this->registerEvent(SDLK_SPACE);
    139   this->registerEvent(SDLK_q);
    140   this->registerEvent(SDLK_e);
    141   this->registerEvent(KeyMapper::PEV_FIRE1);
    142   this->registerEvent(KeyMapper::PEV_NEXT_WEAPON);
    143   this->registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
    144   this->registerEvent(EV_MOUSE_MOTION);
    145143
    146144
     
    165163  this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5));
    166164  this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
    167 //
    168    this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
    169    this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    170    //
    171 
    172    this->cameraConnNode.addChild(this->getWeaponManager().getFixedTarget());
     165  //
     166  this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
     167  this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     168  //
     169
     170  this->cameraConnNode.addChild(this->getWeaponManager().getFixedTarget());
    173171  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
    174172
     
    177175}
    178176
    179 
    180 void MD2Creature::enter()
    181 {
    182   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
    183   this->attachCamera();
    184 
    185 }
    186 
    187 void MD2Creature::leave()
    188 {
    189   dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
    190 
    191 
    192 }
    193177
    194178/**
     
    202186
    203187
     188void MD2Creature::enter()
     189{
     190  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
     191
     192  State::getCameraNode()->setParentSoft(&this->cameraConnNode);
     193  State::getCameraNode()->setRelCoorSoft(-10, 0,0);
     194  State::getCameraTargetNode()->setParentSoft(&this->cameraConnNode);
     195
     196}
     197
     198void MD2Creature::leave()
     199{
     200  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
     201  this->detachCamera();
     202}
     203
     204
    204205/**
    205206 *  effect that occurs after the MD2Creature is spawned
    206207*/
    207208void MD2Creature::postSpawn ()
    208 {
    209   //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
    210 }
     209{}
    211210
    212211/**
     
    234233  if (this->getCurrentPlayer() != NULL)
    235234    WorldEntity::draw();
    236 //  this->cameraConnNode.debugDraw(0);
     235
     236  this->cameraConnNode.debugDraw(0);
    237237}
    238238
     
    254254  this->shiftCoor (move);
    255255
     256
     257  // handle animations differently
    256258  if( this->bJump && likely(this->getModel(0) != NULL))
    257259  {
     
    260262  else if( this->bFire && likely(this->getModel(0) != NULL))
    261263  {
    262     if( ((MD2Model*)this->getModel(0))->getAnim() != ATTACK) ((MD2Model*)this->getModel(0))->setAnimation(ATTACK);
     264    if( ((MD2Model*)this->getModel(0))->getAnim() != ATTACK)
     265      ((MD2Model*)this->getModel(0))->setAnimation(ATTACK);
    263266  }
    264267  else if( fabs(move.len()) > 0.0f && likely(this->getModel(0) != NULL))
    265268  {
    266     if( ((MD2Model*)this->getModel(0))->getAnim() != RUN) ((MD2Model*)this->getModel(0))->setAnimation(RUN);
     269    if( ((MD2Model*)this->getModel(0))->getAnim() != RUN)
     270      ((MD2Model*)this->getModel(0))->setAnimation(RUN);
    267271  }
    268272  else if (likely(this->getModel(0) != NULL))
    269273  {
    270     if( ((MD2Model*)this->getModel(0))->getAnim() != STAND) ((MD2Model*)this->getModel(0))->setAnimation(STAND);
     274    if( ((MD2Model*)this->getModel(0))->getAnim() != STAND)
     275      ((MD2Model*)this->getModel(0))->setAnimation(STAND);
    271276  }
    272277
    273278
    274279  //orient the MD2Creature in direction of the mouse
    275   this->setAbsDir(mouseDirX);
    276   this->cameraConnNode.setRelDir(mouseDirY);
     280//   this->setAbsDir(mouseDirX);
     281//    this->cameraConnNode.setRelDir(mouseDirY);
     282
     283  this->setAbsDir(this->mouseDirX);
    277284}
    278285
     
    292299  /* calculate the direction in which the craft is heading  */
    293300
     301  if( bMouseMotion)
     302  {
     303    PRINTF(0)("motion\n");
     304    this->mouseDirX *= Quaternion(-M_PI / 4.0f * this->xMouse*mouseSensitivity, Vector(0,1,0));
     305    this->mouseDirY *= Quaternion(-M_PI / 4.0f * this->yMouse*mouseSensitivity, Vector(0,0,1));
     306    this->bMouseMotion = false;
     307  }
     308
    294309  if( this->bUp )
    295    {
    296      accel += (this->getAbsDirX())*2;
    297    }
     310  {
     311    accel += (this->getAbsDirX())*2;
     312  }
    298313
    299314  if( this->bDown )
    300    {
    301      accel -= (this->getAbsDirX())*2;
    302    }
     315  {
     316    accel -= (this->getAbsDirX())*2;
     317  }
    303318
    304319  if( this->bLeft/* > -this->getRelCoor().z*2*/)
     
    335350
    336351
    337 
    338352/**
    339353 * @todo switch statement ??
     
    342356{
    343357  Playable::process(event);
    344   if( event.type == SDLK_a)
    345       this->bStrafeL = event.bPressed;
    346   else if( event.type == SDLK_d)
    347       this->bStrafeR = event.bPressed;
    348   else if( event.type == SDLK_w)
    349     this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
    350   else if( event.type == SDLK_s)
    351     this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
     358  if( event.type == KeyMapper::PEV_LEFT)
     359    this->bStrafeL = event.bPressed;
     360  else if( event.type == KeyMapper::PEV_RIGHT)
     361    this->bStrafeR = event.bPressed;
     362  else if( event.type == KeyMapper::PEV_FORWARD)
     363    this->bUp = event.bPressed;
     364  else if( event.type == KeyMapper::PEV_BACKWARD)
     365    this->bDown = event.bPressed;
    352366  else if( event.type == SDLK_SPACE)
    353367    this->bJump = event.bPressed;
    354368  else if( event.type == EV_MOUSE_MOTION)
    355369  {
     370    this->bMouseMotion = true;
    356371    this->xMouse = event.xRel;
    357372    this->yMouse = event.yRel;
    358     this->mouseDirX *= Quaternion(-M_PI/4*this->xMouse*mouseSensitivity, Vector(0,1,0));
    359     this->mouseDirY *= Quaternion(-M_PI/4*this->yMouse*mouseSensitivity, Vector(0,0,1));
    360 //     if( xMouse*xMouse < 0.9)
    361 //      this->setAbsDir(mouseDir);
    362   }
    363 }
     373  }
     374}
  • branches/bsp_model/src/world_entities/creatures/md2_creature.h

    r7346 r8504  
    5757    bool                  bStrafeR;           //!< strafe to the rith side
    5858    bool                  bJump;              //!< jump
     59    bool                  bMouseMotion;       //!< mouse motion evet
    5960
    6061    PNode                 cameraConnNode;     //!< The Node the camera is connected to.
Note: See TracChangeset for help on using the changeset viewer.