Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9003 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
Jul 2, 2006, 1:36:13 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

Location:
trunk/src/world_entities
Files:
2 deleted
15 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/WorldEntities.am

    r8994 r9003  
    55                world_entities/npcs/ground_turret.cc \
    66                world_entities/npcs/generic_npc.cc \
     7                world_entities/npcs/door.cc \
     8                world_entities/npcs/repair_station.cc \
    79                \
    810                world_entities/environment.cc \
     
    1618                world_entities/character_attributes.cc \
    1719                world_entities/test_entity.cc \
    18                 world_entities/door.cc \
    1920                world_entities/planet.cc \
    2021                world_entities/bsp_entity.cc \
     
    6768                npcs/npc_test1.h \
    6869                npcs/ground_turret.h \
     70                npcs/door.cc \
     71                npcs/repair_station.cc \
     72                \
    6973                environment.h \
    7074                skysphere.h \
     
    7781                character_attributes.h \
    7882                test_entity.h \
    79                 door.h \
    8083                planet.h \
    8184                bsp_entity.h \
  • trunk/src/world_entities/bsp_entity.cc

    r8490 r9003  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3 
     3 
    44   Copyright (C) 2004 orx
    5 
     5 
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10 
     10 
    1111   ### File Specific:
    1212   main-programmer: Claudio Botta
     
    1515
    1616#include "bsp_entity.h"
     17#include "util/loading/resource_manager.h"
    1718#include "util/loading/resource_manager.h"
    1819
     
    3839BspEntity::~BspEntity ()
    3940{
    40   if( this->bspManager)
     41  if( this->bspManager != NULL)
    4142    delete this->bspManager;
    4243}
     44
    4345
    4446
     
    4951void BspEntity::init()
    5052{
    51   this->setClassID(CL_BSP_ENTITY, "BspEntity");
    5253
    53   this->bspManager = new BspManager(this);
    54   this->toList(OM_ENVIRON);
    55 
     54  this->bspManager = NULL;
    5655  /**
    5756   * @todo: Write CL_BSP_ENTITY INTO THE src/defs/class_id.h (your own definition)
     
    6463  PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str());
    6564
    66   this->bspManager->load(name.c_str(), 0.1f);
     65  // Check wether file exists....
     66  if ( File(ResourceManager::getFullName(name)).exists()  ) {
     67
     68    this->setClassID(CL_BSP_ENTITY, "BspEntity");
     69    this->bspManager = new BspManager(this);
     70
     71    if(this->bspManager->load(name.c_str(), 0.1f) == -1 ) {
     72      this->bspManager = NULL;
     73
     74    } else {
     75      this->toList(OM_ENVIRON); // Success!!!
     76    }
     77  } else {
     78    this->bspManager = NULL;
     79    this->toList(OM_DEAD);
     80  }
    6781}
    6882
     
    7690{
    7791  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
    78  // WorldEntity::loadParam(root);
     92  // WorldEntity::loadParam(root);
    7993
    8094  LoadParam(root, "Name", this, BspEntity, setName)
    81       .describe("Sets the of the BSP file.");
     95  .describe("Sets the of the BSP file.");
    8296
    83 /*  LoadParam(root, "Scale", this, BSpEntity, setScale)
    84       .describe("Sets the scale factore of the bsp level.");
    85 */
     97  /*  LoadParam(root, "Scale", this, BSpEntity, setScale)
     98        .describe("Sets the scale factore of the bsp level.");
     99  */
    86100
    87101  /**
     
    115129 */
    116130void BspEntity::collidesWith (WorldEntity* entity, const Vector& location)
    117 {
    118 
    119 }
     131{}
  • trunk/src/world_entities/creatures/fps_player.cc

    r8894 r9003  
    8383  this->bBackward = false;
    8484  this->bJump = false;
     85  this->bPosBut = false;
    8586
    8687  this->xMouse = 0.0f;
     
    9091  this->setHealth(80);
    9192
     93  this->fallVelocity = 0.0f;
    9294
    9395  this->cameraNode.setParent(this);
     
    121123
    122124  this->getWeaponManager().setSlotCount(2);
    123   this->getWeaponManager().setSlotPosition(0, Vector(0.0, 5.0, 0.0));
    124   this->getWeaponManager().setSlotDirection(1, Quaternion(M_PI_4*.5, Vector(0,1,0)));
     125  this->getWeaponManager().setSlotPosition(0, Vector(1.5, -0.7, 1.1));
     126//   this->getWeaponManager().setSlotDirection(0, Quaternion(M_PI_2, Vector(0,1,0)));
    125127  this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    126   this->getWeaponManager().setSlotPosition(1, Vector(-0.5, .2, 1.9));
     128  this->getWeaponManager().setSlotPosition(1, Vector(5.0, 0.0, 0.0));
    127129  this->getWeaponManager().setSlotDirection(1, Quaternion(M_PI_4*.5, Vector(1,0,0)));
    128130
     
    205207void FPSPlayer::tick (float time)
    206208{
     209 
     210  if( this->bPosBut)
     211  {
     212    this->bPosBut = false;
     213    printf("prisoner:walkTo( %f, height, %f)\n",this->getAbsCoorX(),this->getAbsCoorZ());
     214  }
     215 
    207216  Playable::tick( time );
    208217
     
    251260  }
    252261
     262
    253263  velocity *= 100;
    254264
     265
     266  // physical falling of the player
     267  if( !this->isOnGround())
     268  {
     269    this->fallVelocity += 300.0f * time;
     270    velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
     271  }
     272  else
     273  {
     274    this->fallVelocity = 0.0f;
     275  }
     276
     277
    255278  this->shiftCoor( velocity*time );
     279
     280
     281
    256282
    257283
     
    321347  }
    322348  else if( event.type == KeyMapper::PEV_JUMP)
    323     this->getAbsCoor().debug();
    324 }
    325 
    326 
    327 
    328 
     349    this->bPosBut = event.bPressed;
     350}
     351
     352
     353
     354
  • trunk/src/world_entities/creatures/fps_player.h

    r8731 r9003  
    4242    bool                  bBackward;
    4343    bool                  bJump;              //!< jumping
     44    bool                  bPosBut;             //!< position button
    4445
    4546    float                 xMouse;             //!< mouse moved in x-Direction
     
    5152
    5253    PNode                 cameraNode;
     54
     55    float                 fallVelocity;        //!< velocity for falling down
    5356};
    5457
  • trunk/src/world_entities/elements/glgui_radar.cc

    r9002 r9003  
    135135      glRotatef((this->_centerNode->getAbsDir().getHeading() - M_PI_2)* 180.0 /M_PI , 0, 0, 1);
    136136
    137       glPointSize(2.0f);
     137      glPointSize(4.0f);
    138138      for (unsigned int i = 0; i < this->_dotLists.size(); ++i)
    139139      {
  • trunk/src/world_entities/npcs/generic_npc.cc

    r8894 r9003  
    1717#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    1818
     19#include "generic_npc.h"
     20
    1921
    2022#include "util/loading/factory.h"
     
    2830#include "loading/resource_manager.h"
    2931
    30 #include "generic_npc.h"
    31 
    32 #include "animation/animation3d.h"
    33 
    34 using namespace std;
    35 
    36 
    3732
    3833CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC);
     
    4035#include "script_class.h"
    4136CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC,
    42                        // Move
    43                         addMethod("walkTo", ExecutorLua3ret<GenericNPC,float,float,float,float>(&GenericNPC::walkTo))
    44                         ->addMethod("setTime", ExecutorLua1<GenericNPC,float>(&GenericNPC::setTime))
    45                         ->addMethod("turnTo", ExecutorLua4ret<GenericNPC,bool,float,float,float,float>(&GenericNPC::turnTo))
    46                        // Display
     37                        // Move
     38                        addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo))
     39                        ->addMethod("runTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::runTo))
     40                        ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo))
     41                        ->addMethod("finalGoalReached", ExecutorLua0ret<GenericNPC,bool>(&GenericNPC::finalGoalReached))
     42                        // Display
    4743                        ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide))
    4844                        ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide))
    49                        // Coordinates
     45                        // Coordinates
    5046                        ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
    5147                        ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     
    5349                        ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
    5450                        ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir))
    55                            
     51
    5652                       );
    5753
     
    6258 */
    6359GenericNPC::GenericNPC(const TiXmlElement* root)
    64   : NPC(root)
     60    : NPC(root)
    6561{
    6662  this->init();
     
    7167
    7268
    73 GenericNPC::GenericNPC()
    74   : NPC(NULL)
    75 {
    76 
    77 }
    78 
    7969/**
    8070 * deconstructor
    8171 */
    8272GenericNPC::~GenericNPC ()
    83 {
    84   if( this->currentAnim != NULL)
    85     delete this->currentAnim;
    86 }
     73{}
    8774
    8875
     
    10087
    10188  time = 30.0f;
     89
    10290  // collision reaction registration
    103 //   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
     91  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    10492}
    10593
     
    128116
    129117
     118
     119/**
     120 * @returns the current animation number
     121 */
     122int GenericNPC::getAnimation()
     123{
     124  if( likely(this->getModel(0) != NULL))
     125    return ((InteractiveModel*)this->getModel(0))->getAnimation();
     126  else
     127    return -1;
     128}
     129
     130
     131
     132/**
     133 * @returns true if animation is finished
     134 */
     135bool GenericNPC::isAnimationFinished()
     136{
     137  if( likely(this->getModel(0) != NULL))
     138    return ((InteractiveModel*)this->getModel(0))->isAnimationFinished();
     139  else
     140    return false;
     141}
     142
     143
     144/**
     145 * sets the animation speed of this entity
     146 */
     147void GenericNPC::setAnimationSpeed(float speed)
     148{
     149  if( likely(this->getModel(0) != NULL))
     150    ((InteractiveModel*)this->getModel(0))->setAnimationSpeed(speed);
     151}
     152
     153
     154
    130155/**
    131156 * sets the animation of this npc
     
    146171 */
    147172void GenericNPC::playSound(std::string filename)
    148 {
    149 
    150 }
    151 
    152 
    153 /**
    154  * walt to
    155  * @param coordinate: coordinate to go to
    156  */
    157 float GenericNPC::walkTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    158 {
    159   Vector destCoor = Vector(x, y, z);
    160   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    161 
    162   // check if this is the current goal
    163   if( this->destCoor != destCoor || this->destDir != destDir)
    164   {
    165     this->destCoor = destCoor;
    166     this->destDir = destDir;
    167 
    168     //float time = 100.0f;
    169 
    170     if( this->currentAnim != NULL)
    171       delete this->currentAnim;
    172 
    173     this->currentAnim = new Animation3D(this);
    174     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
    175     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    176     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    177 
    178     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    179     this->currentAnim->play();
    180 
    181     this->setAnimation(RUN, MD2_ANIM_LOOP);
    182   }
    183 
    184   // calculate the distance
    185   Vector distance = this->getAbsCoor() - this->destCoor;
    186   return distance.len();
    187 }
    188 
    189 
    190 /**
    191  * walk to a specific place with direction
    192  *
    193  * @param x: x coordinate to go to
    194  * @param y: y coordinate to go to
    195  * @param z: z coordinate to go to
    196  *
    197  * without turning itself
    198  */
    199 float GenericNPC::walkTo(float x, float y, float z)
    200 {
    201   Quaternion q = this->getAbsDir();
    202 
    203   //printf("%s moving to %f, %f, %f \n",this->getName(),x,y,z);
    204 
    205   return this->walkTo(x, y, z, q.w, q.v.x, q.v.y, q.v.z);
    206 }
    207 
    208 /**
    209  * walk to a specific place with direction
    210  *
    211  * @param x: x coordinate to go to
    212  * @param y: y coordinate to go to
    213  * @param qu: angle to rotate
    214  * @param qx: x coordinate of rotation vector
    215  * @param qy: y coordinate of rotation vector
    216  * @param qz: z coordinate of rotation vector
    217  *
    218  */
    219 float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz)
    220 {
    221   return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
    222 }
    223 
    224 
    225 /**
    226  * walk to a specific place with direction
    227  *
    228  * @param coor: vector place
    229  * @param dir: direction
    230  *
    231  */
    232 float GenericNPC::walkTo(const Vector& coor, const Quaternion& dir)
    233 {
    234   return this->walkTo(coor.x, coor.y, coor.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    235 }
    236 
    237 
    238 
    239 /**
    240  * run to a specific place with direction
    241  *
    242  * @param x: x coordinate to go to
    243  * @param y: y coordinate to go to
    244  * @param z: z coordinate to go to
    245  * @param qu: angle to rotate
    246  * @param qx: x coordinate of rotation vector
    247  * @param qy: y coordinate of rotation vector
    248  * @param qz: z coordinate of rotation vector
    249  *
    250  */
    251 float GenericNPC::runTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    252 {
    253   Vector destCoor = Vector(x, y, z);
    254   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    255 
    256   // check if this is the current goal
    257   if( this->destCoor != destCoor || this->destDir != destDir)
    258   {
    259     this->destCoor = destCoor;
    260     this->destDir = destDir;
    261 
    262     float time = 5.0f;
    263 
    264     if( this->currentAnim != NULL)
    265       delete this->currentAnim;
    266 
    267     this->currentAnim = new Animation3D(this);
    268     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    269     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    270 
    271 
    272     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    273     this->currentAnim->play();
    274 
    275     this->setAnimation(RUN, MD2_ANIM_LOOP);
    276   }
    277 
    278   // calculate the distance
    279   Vector distance = this->getAbsCoor() - this->destCoor;
    280   return distance.len();
    281 }
    282 
    283 
    284 /**
    285  * run to a specific place with direction
    286  *
    287  * @param x: x coordinate to go to
    288  * @param y: y coordinate to go to
    289  * @param qu: angle to rotate
    290  * @param qx: x coordinate of rotation vector
    291  * @param qy: y coordinate of rotation vector
    292  * @param qz: z coordinate of rotation vector
    293  *
    294  */
    295 float GenericNPC::runTo(float x, float y, float qu, float qx, float qy, float qz)
    296 {
    297   this->runTo(x, y, 0.0f, qu, qx, qy, qz);
    298 }
    299 
    300 
    301 /**
    302  * run to a specific place with direction
    303  *
    304  * @param coor: vector place
    305  * @param dir: direction
    306  *
    307  */
    308 float GenericNPC::runTo(const Vector& coordinate, const Quaternion& dir)
    309 {
    310   this->runTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    311 }
    312 
    313 
    314 /**
    315  * crouch to a specific place with direction
    316  *
    317  * @param x: x coordinate to go to
    318  * @param y: y coordinate to go to
    319  * @param z: z coordinate to go to
    320  * @param qu: angle to rotate
    321  * @param qx: x coordinate of rotation vector
    322  * @param qy: y coordinate of rotation vector
    323  * @param qz: z coordinate of rotation vector
    324  *
    325  */
    326 float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    327 {
    328   Vector destCoor = Vector(x, y, z);
    329   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    330 
    331   // check if this is the current goal
    332   if( this->destCoor != destCoor || this->destDir != destDir)
    333   {
    334     this->destCoor = destCoor;
    335     this->destDir = destDir;
    336 
    337 
    338     if( this->currentAnim != NULL)
    339       delete this->currentAnim;
    340 
    341     this->currentAnim = new Animation3D(this);
    342     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    343     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    344 
    345 
    346     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    347     this->currentAnim->play();
    348 
    349     this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
    350   }
    351 
    352   // calculate the distance
    353   Vector distance = this->getAbsCoor() - this->destCoor;
    354   return distance.len();
    355 }
    356 
    357 
    358 /**
    359  * couch to a specific place with direction
    360  *
    361  * @param x: x coordinate to go to
    362  * @param y: y coordinate to go to
    363  * @param qu: angle to rotate
    364  * @param qx: x coordinate of rotation vector
    365  * @param qy: y coordinate of rotation vector
    366  * @param qz: z coordinate of rotation vector
    367  *
    368  */
    369 float GenericNPC::crouchTo(float x, float y, float qu, float qx, float qy, float qz)
    370 {
    371   this->crouchTo(x, y, 0.0f, qu, qx, qy, qz);
    372 }
    373 
    374 
    375 
    376 /**
    377  * crouch to a specific place with direction
    378  *
    379  * @param coor: vector place
    380  * @param dir: direction
    381  *
    382  */
    383 float GenericNPC::crouchTo(const Vector& coordinate, const Quaternion& dir)
    384 {
    385   this->crouchTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    386 }
     173{}
     174
    387175
    388176
     
    391179 */
    392180void GenericNPC::stop()
    393 {
    394   if( this->currentAnim != NULL)
    395   {
    396     this->currentAnim->stop();
    397     delete this->currentAnim;
    398     this->currentAnim = NULL;
    399 
     181{}
     182
     183
     184
     185void GenericNPC::initNPC()
     186{
     187  if (!this->behaviourList.empty())
     188  {
     189    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     190
     191    switch(this->behaviourList.front().type)
     192    {
     193      case Walk:
     194      {
     195        if( this->getAnimation() != RUN)
     196          this->setAnimation(RUN, MD2_ANIM_LOOP);
     197
     198        Vector dir = (currentAnimation.v - this->getAbsCoor());
     199        dir.y = 0.0f;
     200        dir.getNormalized();
     201        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     202
     203        this->setAnimationSpeed(0.5f);
     204      }
     205        break;
     206      case Run:
     207      {
     208        if( this->getAnimation() != RUN)
     209          this->setAnimation(RUN, MD2_ANIM_LOOP);
     210
     211        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     212        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     213
     214        this->setAnimationSpeed(1.0f);
     215      }
     216        break;
     217      case Crouch:
     218      {
     219        if( this->getAnimation() != CROUCH_WALK)
     220          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
     221
     222        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     223        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     224
     225        this->setAnimationSpeed(1.0f);
     226      }
     227        break;
     228      case LookAt:
     229        if( this->getAnimation() != STAND)
     230          this->setAnimation(STAND, MD2_ANIM_LOOP);
     231        break;
     232      case Shoot:
     233        if( this->getAnimation() != STAND)
     234          this->setAnimation(STAND, MD2_ANIM_LOOP);
     235        break;
     236
     237      default:
     238        if( this->getAnimation() != STAND)
     239          this->setAnimation(STAND, MD2_ANIM_LOOP);
     240        break;
     241
     242    }
     243  }
     244}
     245
     246
     247void GenericNPC::nextStep()
     248{
     249  if (!this->behaviourList.empty())
     250    this->behaviourList.pop_front();
     251  else
     252    return;
     253
     254
     255  if (!this->behaviourList.empty())
     256  {
     257    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     258
     259    switch( currentAnimation.type)
     260    {
     261      case Walk:
     262      {
     263        if( this->getAnimation() != RUN)
     264          this->setAnimation(RUN, MD2_ANIM_LOOP);
     265
     266        Vector dir = (currentAnimation.v - this->getAbsCoor());
     267        dir.y = 0.0f;
     268        dir.getNormalized();
     269        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     270
     271        this->setAnimationSpeed(0.5f);
     272      }
     273        break;
     274      case Run:
     275      {
     276        if( this->getAnimation() != RUN)
     277          this->setAnimation(RUN, MD2_ANIM_LOOP);
     278
     279        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     280        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     281
     282        this->setAnimationSpeed(1.0f);
     283      }
     284        break;
     285      case Crouch:
     286      {
     287        if( this->getAnimation() != CROUCH_WALK)
     288          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
     289
     290        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     291        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     292
     293        this->setAnimationSpeed(1.0f);
     294      }
     295        break;
     296      case LookAt:
     297      {
     298        if( this->getAnimation() != STAND)
     299          this->setAnimation(STAND, MD2_ANIM_LOOP);
     300      }
     301        break;
     302      case Shoot:
     303        if( this->getAnimation() != STAND)
     304        this->setAnimation(STAND, MD2_ANIM_LOOP);
     305        break;
     306
     307      default:
     308        if( this->getAnimation() != STAND)
     309        this->setAnimation(STAND, MD2_ANIM_LOOP);
     310        break;
     311
     312    }
     313  }
     314  else
     315  {
    400316    this->setAnimation(STAND, MD2_ANIM_LOOP);
    401317  }
    402318}
     319
     320
     321
     322
     323void GenericNPC::walkTo(const Vector& coordinate)
     324{
     325
     326  GenericNPC::Anim anim;
     327  anim.v = coordinate;
     328  anim.type = Walk;
     329  anim.speed = 30.0f;
     330
     331  if( this->behaviourList.empty())
     332  {
     333    this->behaviourList.push_back(anim);
     334    this->initNPC();
     335  }
     336  else
     337    this->behaviourList.push_back(anim);
     338}
     339
     340void GenericNPC::walkTo(float x, float y, float z)
     341{
     342  //printf("Walking to %f, %f, %f \n",x,y,z);
     343  this->walkTo(Vector(x,y,z));
     344
     345}
     346
     347/* running functions */
     348void GenericNPC::runTo(const Vector& coordinate)
     349{
     350  GenericNPC::Anim anim;
     351  anim.v = coordinate;
     352  anim.type = Run;
     353  anim.speed = 60.0f;
     354
     355  if( this->behaviourList.empty())
     356  {
     357    this->behaviourList.push_back(anim);
     358    this->initNPC();
     359  }
     360  else
     361    this->behaviourList.push_back(anim);
     362}
     363
     364void GenericNPC::runTo(float x, float y, float z)
     365{
     366  this->runTo(Vector(x,y,z));
     367}
     368
     369/* couching functinos */
     370void GenericNPC::crouchTo(const Vector& coordinate)
     371{
     372  GenericNPC::Anim anim;
     373  anim.v = coordinate;
     374  anim.type = Crouch;
     375
     376  if( this->behaviourList.empty())
     377  {
     378    this->behaviourList.push_back(anim);
     379    this->initNPC();
     380  }
     381  else
     382    this->behaviourList.push_back(anim);
     383}
     384void GenericNPC::crouchTo(float x, float y, float z)
     385{
     386  this->crouchTo(Vector(x,y,z));
     387}
     388
     389
     390
     391void GenericNPC::turnTo(float degreeInY)
     392{
     393  GenericNPC::Anim anim;
     394  anim.q = Quaternion(Vector(0,1,0), degreeInY);
     395  anim.type = TurnTo;
     396
     397  if( this->behaviourList.empty())
     398  {
     399    this->behaviourList.push_back(anim);
     400    this->initNPC();
     401  }
     402  else
     403    this->behaviourList.push_back(anim);
     404}
     405
    403406
    404407
     
    407410 * @param worldEntity: the worldentity to look at
    408411 */
    409 float GenericNPC::lookAt(WorldEntity* worldEntity)
    410 {}
    411 
    412 
    413 /**
    414  * turns to a given direction
    415  */
    416 bool GenericNPC::turnTo(float qu, float qx, float qy, float qz)
    417 {
    418   Quaternion destDir = Quaternion(Vector(qx, qy, qz).getNormalized(), qu);
    419 
    420   printf("Turning: %f, %f, %f, %f \n",qu,qx,qy,qz);
    421   // check if this is the current goal
    422   if( this->destDir != destDir)
    423   {
    424 //     if( this->currentAnim != NULL)
    425 //       this->currentAnim->stop();
    426 //
    427     PRINTF(0)("SET ANIMATION\n");
    428     this->destDir = destDir;
    429 //
    430 
    431 
    432     if( this->currentAnim != NULL)
    433       delete this->currentAnim;
    434 
    435     this->setAbsDir(destDir);
    436 /*
    437     this->currentAnim = new Animation3D(this);
    438     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
    439     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    440     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    441 
    442 
    443     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    444     this->currentAnim->play();*/
    445 
    446     this->setAnimation(STAND, MD2_ANIM_LOOP);
    447   }
    448 
    449   // calculate the distance
    450   Vector distance = this->getAbsCoor() - this->destCoor;
    451   return distance.len();
    452 }
     412void GenericNPC::lookAt(WorldEntity* worldEntity)
     413{
     414  GenericNPC::Anim anim;
     415  anim.entity = worldEntity;
     416  anim.type = LookAt;
     417
     418  if( this->behaviourList.empty())
     419  {
     420    this->behaviourList.push_back(anim);
     421    this->initNPC();
     422  }
     423  else
     424    this->behaviourList.push_back(anim);
     425}
     426
    453427
    454428
     
    459433 * @param dialogNr: sound nr to be played (from the xml load tags)
    460434 */
    461 float GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
     435void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
    462436{}
    463437
     
    483457 * @param time: time in seconds expirded since the last tick
    484458 */
    485 void GenericNPC::tick (float time)
     459void GenericNPC::tick (float dt)
    486460{
    487461  if( likely(this->getModel(0) != NULL))
    488     ((InteractiveModel*)this->getModel(0))->tick(time);
     462    ((InteractiveModel*)this->getModel(0))->tick(dt);
     463
     464
     465  if (!this->behaviourList.empty())
     466  {
     467    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     468
     469    switch( currentAnimation.type)
     470    {
     471      case Walk:
     472        {
     473          Vector dest = currentAnimation.v - this->getAbsCoor();
     474          if (dest.len() < .5)
     475            this->nextStep();
     476          else
     477          {
     478            dest.y = 0.0f;
     479            this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     480
     481          }
     482        }
     483        break;
     484
     485      case Run:
     486      {
     487        Vector dest = currentAnimation.v - this->getAbsCoor();
     488        if (dest.len() < .5)
     489          this->nextStep();
     490        else
     491        {
     492          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     493        }
     494      }
     495      break;
     496
     497      case Crouch:
     498      {
     499        Vector dest = currentAnimation.v - this->getAbsCoor();
     500        if (dest.len() < .5)
     501          this->nextStep();
     502        else
     503        {
     504          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     505        }
     506      }
     507      break;
     508
     509      case TurnTo:
     510        //Quaternion direction = this->
     511        break;
     512
     513      case LookAt:
     514        break;
     515
     516      case Shoot:
     517        break;
     518
     519      default:
     520        break;
     521
     522    }
     523  }
     524
     525  // physical falling of the player
     526  if( !this->isOnGround())
     527  {
     528    this->fallVelocity += 300.0f * dt;
     529    velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
     530   // PRINTF(0)("%s is not on ground\n", this->getName());
     531  }
     532  else
     533  {
     534    this->fallVelocity = 0.0f;
     535  }
     536
     537  this->shiftCoor(Vector(0, -this->fallVelocity * dt,0));
    489538
    490539}
     
    495544{
    496545  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
     546
     547  this->setAnimationSpeed(1.0f);
    497548
    498549  if( randi == 1)
  • trunk/src/world_entities/npcs/generic_npc.h

    r8894 r9003  
    1010#include "npc.h"
    1111
    12 #include <string>
    1312
    1413#include "sound_source.h"
    15 
    16 #include "vector.h"
    17 #include "quaternion.h"
    18 
    1914
    2015namespace OrxSound{ class SoundSource; }
     
    2722class GenericNPC : public NPC
    2823{
     24
     25
    2926 public:
    30   GenericNPC();
    31   GenericNPC(const TiXmlElement* root);
     27  GenericNPC(const TiXmlElement* root = NULL);
    3228  virtual ~GenericNPC ();
    3329
    34   void init();
    3530  virtual void loadParams(const TiXmlElement* root);
    3631
    37   void setAnimation(int animationIndex, int animPlaybackMode);
    3832  /** sets the sound volume to @param vol: volume of the sound */
    3933  inline void setVolume(float vol) { this->soundVolume = vol; }
    4034
    4135
    42   /* npc controlling functions */
    4336
     37  bool finalGoalReached() { return this->behaviourList.empty(); };
     38
     39  /* npc controlling functions to be Queued */
    4440  /* walking functions */
    45   float walkTo(const Vector& coordinate, const Quaternion& dir);
    46   float walkTo(float x, float y, float z);
    47   float walkTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    48   float walkTo(float x, float y, float qu, float qx, float qy, float qz);
     41  void walkTo(const Vector& coordinate);
     42  void walkTo(float x, float y, float z);
    4943
    5044  /* running functions */
    51   float runTo(const Vector& coordinate, const Quaternion& dir);
    52   float runTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    53   float runTo(float x, float y, float qu, float qx, float qy, float qz);
     45  void runTo(const Vector& coordinate);
     46  void runTo(float x, float y, float z);
    5447
    5548  /* couching functinos */
    56   float crouchTo(const Vector& coordinate, const Quaternion& dir);
    57   float crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    58   float crouchTo(float x, float y, float qu, float qx, float qy, float qz);
     49  void crouchTo(const Vector& coordinate);
     50  void crouchTo(float x, float y, float z);
    5951
    6052  /* stopping the movement */
    6153  void stop();
     54  void nextStep();
    6255
    6356  /* some oriantation functions */
    64   float lookAt(WorldEntity* worldEntity);
    65   bool turnTo(float qu, float qx, float qy, float qz);
     57  void lookAt(WorldEntity* worldEntity);
     58  void turnTo(float qu, float qx, float qy, float qz);
     59  void turnTo(float degreeInY);
    6660
    6761  /* talking funcitons*/
    68   float talkTo(WorldEntity* worldEntity, int dialogNr);
     62  void talkTo(WorldEntity* worldEntity, int dialogNr);
    6963
    7064  /* shooting functions */
     
    7771  void playSound(int i);
    7872
    79   void setTime(float newTime){ this->time = newTime; };
    80  
    8173  virtual void tick (float time);
    8274
     
    8476  void destroy();
    8577
     78  private:
     79    void init();
     80
     81    void setAnimation(int animationIndex, int animPlaybackMode);
     82    int getAnimation();
     83    bool isAnimationFinished();
     84    void setAnimationSpeed(float speed);
     85
     86    void initNPC();
     87
    8688
    8789 private:
     90
     91   typedef enum {
     92    Walk,
     93    Run,
     94    Crouch,
     95    Jump,
     96    TurnTo,
     97    LookAt,
     98    TalkTo,
     99
     100    Shoot,
     101
     102
     103   } AnimType;
     104
     105   typedef struct Anim
     106   {
     107     Vector        v;
     108     Quaternion    q;
     109
     110
     111     WorldEntity*  entity;
     112     float         speed;
     113
     114
     115     AnimType      type;
     116   };
     117   typedef std::list<GenericNPC::Anim>     genNPCAnimList;
     118
     119
     120
    88121   OrxSound::SoundSource                   soundSource;
    89122   OrxSound::SoundBuffer*                  soundBuffer;
    90123   float                                   soundVolume;
    91124
     125   std::list<GenericNPC::Anim>             behaviourList;
    92126   Vector                                  destCoor;
    93127   Quaternion                              destDir;
     
    95129   Animation3D*                            currentAnim;
    96130   float                                   time;          //!< Duration of the action
     131   float                                   fallVelocity;
    97132};
    98133
  • trunk/src/world_entities/npcs/npc.cc

    r8894 r9003  
    2929
    3030  this->toList(OM_GROUP_00);
     31
    3132}
    3233
  • trunk/src/world_entities/script_trigger.cc

    r8894 r9003  
    1414*/
    1515
    16 
    1716#include "script_trigger.h"
    1817#include "class_list.h"
     
    2322
    2423CREATE_SCRIPTABLE_CLASS(ScriptTrigger, CL_SCRIPT_TRIGGER,
    25                             addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
    26                             ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
    27                             ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
    28                             ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
     24                          //Position
     25                     addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
     26                     ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
     27                     ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     28                     ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
     29                     //Set values
     30                    // ->addMethod("setTarget", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTarget))
     31                    // ->addMethod("setTriggerParent", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTriggerParent))
     32                     ->addMethod("setTriggerLasts", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setTriggerLasts))
     33                     ->addMethod("setInvert", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert))
     34                     ->addMethod("setRadius", ExecutorLua1<ScriptTrigger, float >(&ScriptTrigger::setRadius))
     35                     //->addMethod("setScript", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setScript))
     36                     //->addMethod("setFunction", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setFunction))
     37                     ->addMethod("setDebugDraw", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert))
    2938                       );
    3039
     
    92101    LoadParam(root, "radius", this, ScriptTrigger, setRadius)
    93102        .describe("the fileName of the script, that should be triggered by this script trigger")
    94         .defaultValues(0);
    95     LoadParam(root, "delay", this, ScriptTrigger, setDelay)
    96         .describe("the delay after which the funtion sould be triggered")
    97103        .defaultValues(0);
    98104    LoadParam(root, "worldentity", this, ScriptTrigger, setTarget)
  • trunk/src/world_entities/script_trigger.h

    r8894 r9003  
    3838    void setInvert(const bool inv) { this->invert = invert; }
    3939    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    40     void setDelay(const float time){if(delay>0) this->delay = delay; }
    4140    void setScript(const std::string& file);
    4241    void setFunction(const std::string& function){ this->functionName = function;}
  • trunk/src/world_entities/test_entity.cc

    r8778 r9003  
    3737
    3838CREATE_FACTORY(TestEntity, CL_TEST_ENTITY);
     39
     40#include "script_class.h"
     41CREATE_SCRIPTABLE_CLASS(TestEntity, CL_TEST_ENTITY,
     42                            addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
     43                            ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
     44                            ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     45                            ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
     46                           
     47                       );
    3948
    4049
  • trunk/src/world_entities/weapons/fps_sniper_rifle.cc

    r8894 r9003  
    6767{
    6868  // model will be deleted from WorldEntity-destructor
     69  if( this->material != NULL)
     70    delete this->material;
    6971}
    7072
     
    7476  this->setClassID(CL_FPS_SNIPER_RIFLE, "FPSSniperRifle");
    7577
    76   this->loadModel("models/guns/fps_sniper_rifle.obj", 0.1);
     78  this->loadModel("models/guns/fps_sniper_rifle.obj", 0.2);
     79  this->material = new Material();
     80  this->material->setIllum(3);
     81  this->material->setAmbient(1.0, 1.0, 1.0);
     82  this->material->setDiffuseMap("maps/rifle01tex.jpg");
    7783
    7884  this->setStateDuration(WS_SHOOTING, .1);
     
    149155
    150156
     157
     158
     159/**
     160 *  this will draw the weapon
     161 */
     162void FPSSniperRifle::draw () const
     163{
     164  /* draw gun body */
     165  glMatrixMode(GL_MODELVIEW);
     166  glPushMatrix();
     167  glTranslatef (this->getAbsCoor ().x,
     168                this->getAbsCoor ().y,
     169                this->getAbsCoor ().z);
     170
     171  Vector tmpRot = this->getAbsDir().getSpacialAxis();
     172  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
     173
     174  if( this->leftRight == W_RIGHT)
     175    glScalef(1.0, 1.0, -1.0);
     176
     177  this->material->select();
     178  static_cast<StaticModel*>(this->getModel())->draw();
     179
     180  glPopMatrix();
     181
     182}
     183
     184
     185
  • trunk/src/world_entities/weapons/fps_sniper_rifle.h

    r8894 r9003  
    3535
    3636
     37class Material;
     38
    3739class FPSSniperRifle : public Weapon
    3840  {
     
    5052    virtual void fire();
    5153
     54    virtual void draw() const;
     55
     56
    5257
    5358  private:
    54     int leftRight;   // this will become an enum
     59    int              leftRight;   //!< this will become an enum
     60    Material*        material;    //!< material
    5561
    5662  };
  • trunk/src/world_entities/world_entity.cc

    r8977 r9003  
    7272
    7373  this->objectListNumber = OM_INIT;
     74  this->lastObjectListNumber = OM_INIT;
    7475  this->objectListIterator = NULL;
    7576
     
    7879    this->collisionHandles[i] = NULL;
    7980  this->bReactive = false;
     81  this->bOnGround = false;
    8082
    8183  // registering default reactions:
     
    613615    }
    614616
    615     if( this->aabbNode != NULL)
    616       this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
     617//     if( this->aabbNode != NULL)
     618//       this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
    617619
    618620    glPopMatrix();
  • trunk/src/world_entities/world_entity.h

    r8974 r9003  
    9494  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
    9595
     96  /** @returns true if this entity is standing on ground (BSP model) */
     97  bool isOnGround() const { return this->bOnGround; }
     98  /** @param flag: marks if this entity is standing on ground */
     99  void setOnGround(bool flag) { this->bOnGround = flag; }
     100
    96101  virtual void hit(float damage);
    97102  virtual void destroy();
     
    117122
    118123  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
    119   void unhide() { this->toList(this->lastObjectListNumber); }
     124  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
    120125
    121126
     
    194199
    195200  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
    196 
     201  bool                    bOnGround;                       //!< true if this entity is standing on the ground
    197202
    198203  protected:
Note: See TracChangeset for help on using the changeset viewer.