Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 27, 2006, 1:11:41 AM (18 years ago)
Author:
patrick
Message:

generic npc crouch, run and stop functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/single_player_map/src/world_entities/npcs/generic_npc.cc

    r8817 r8818  
    304304 * crouch to a specific place with direction
    305305 *
    306  * @param coor: vector place
    307  * @param dir: direction
    308  *
    309  */
    310 float GenericNPC::crouchTo(const Vector& coordinate, const Quaternion& dir)
    311 {
    312 }
    313 
    314 
    315 /**
    316  * crouch to a specific place with direction
    317  *
    318306 * @param x: x coordinate to go to
    319307 * @param y: y coordinate to go to
     
    326314 */
    327315float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    328 {}
     316{
     317  Vector destCoor = Vector(x, y, z);
     318  Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
     319
     320  // check if this is the current goal
     321  if( this->destCoor != destCoor || this->destDir != destDir)
     322  {
     323    this->destCoor = destCoor;
     324    this->destDir = destDir;
     325
     326    float time = 5.0f;
     327
     328    if( this->currentAnim != NULL)
     329      delete this->currentAnim;
     330
     331    this->currentAnim = new Animation3D(this);
     332    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.1f, ANIM_LINEAR, ANIM_LINEAR);
     333    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
     334    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
     335    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
     336
     337    this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
     338    this->currentAnim->play();
     339
     340    this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
     341  }
     342
     343  // calculate the distance
     344  Vector distance = this->getAbsCoor() - this->destCoor;
     345  return distance.len();
     346}
    329347
    330348
     
    341359 */
    342360float GenericNPC::crouchTo(float x, float y, float qu, float qx, float qy, float qz)
    343 {}
    344 
     361{
     362  this->crouchTo(x, y, 0.0f, qu, qx, qy, qz);
     363}
     364
     365
     366
     367/**
     368 * crouch to a specific place with direction
     369 *
     370 * @param coor: vector place
     371 * @param dir: direction
     372 *
     373 */
     374float GenericNPC::crouchTo(const Vector& coordinate, const Quaternion& dir)
     375{
     376  this->crouchTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
     377}
    345378
    346379
     
    349382 */
    350383void GenericNPC::stop()
    351 {}
     384{
     385  if( this->currentAnim != NULL)
     386  {
     387    this->currentAnim->stop();
     388    delete this->currentAnim;
     389    this->currentAnim = NULL;
     390
     391    this->setAnimation(STAND, MD2_ANIM_LOOP);
     392  }
     393}
    352394
    353395
Note: See TracChangeset for help on using the changeset viewer.