Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 22, 2006, 3:14:58 PM (19 years ago)
Author:
bensch
Message:

merged the bsp-model-stuff back here

Location:
trunk/src/world_entities
Files:
14 edited
4 copied

Legend:

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

    r8490 r8724  
    44                world_entities/npcs/npc_test.cc \
    55                world_entities/npcs/ground_turret.cc \
     6                world_entities/npcs/generic_npc.cc \
    67                \
    78                world_entities/environment.cc \
     
    4142                world_entities/space_ships/collision_probe.cc \
    4243                world_entities/creatures/md2_creature.cc \
     44                world_entities/creatures/fps_player.cc \
    4345                world_entities/spectator.cc \
    4446                \
     
    9799                space_ships/collision_probe.cc \
    98100                creatures/md2_creature.h \
     101                creatures/fps_player.h \
    99102                spectator.h \
    100103                \
  • trunk/src/world_entities/creatures/md2_creature.cc

    r8490 r8724  
    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
     117  // control initialisation
    109118  this->mouseDirX *= Quaternion( M_PI * 0.75f, Vector(0,1,0));
    110119
     
    116125  cycle = 0.0;
    117126
    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 
    125   travelSpeed = 15.0;
     127  travelSpeed =300.0;
    126128  this->velocity = Vector(0.0,0.0,0.0);
    127129
    128 //   GLGuiButton* button = new GLGuiPushButton();
    129 //   button->show();
    130 //   button->setLabel("orxonox");
    131 //   button->setBindNode(this);
    132130
    133131  //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);
     132  //add events to the eventlist
     133  registerEvent(KeyMapper::PEV_FORWARD);
     134  registerEvent(KeyMapper::PEV_BACKWARD);
     135  registerEvent(KeyMapper::PEV_LEFT);
     136  registerEvent(KeyMapper::PEV_RIGHT);
     137  registerEvent(KeyMapper::PEV_UP);
     138  registerEvent(KeyMapper::PEV_DOWN);
     139  registerEvent(KeyMapper::PEV_FIRE1);
     140  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
     141  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
     142  registerEvent(EV_MOUSE_MOTION);
    138143  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);
    145144
    146145
     
    165164  this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5));
    166165  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());
     166  //
     167  this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
     168  this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     169  //
     170
     171  this->cameraConnNode.addChild(this->getWeaponManager().getFixedTarget());
    173172  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
    174173
    175   this->getWeaponManager().getFixedTarget()->setRelCoor(10,0,0);
    176 
    177 }
    178 
    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 }
     174  this->getWeaponManager().getFixedTarget()->setRelCoor(0,0,0);
     175
     176}
     177
    193178
    194179/**
     
    202187
    203188
     189void MD2Creature::enter()
     190{
     191  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
     192
     193  State::getCameraNode()->setParent(&this->cameraConnNode);
     194  State::getCameraNode()->setRelCoor(0, 0,0);
     195  State::getCameraTargetNode()->setParentSoft(&this->cameraConnNode);
     196
     197}
     198
     199void MD2Creature::leave()
     200{
     201  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
     202  this->detachCamera();
     203}
     204
     205
    204206/**
    205207 *  effect that occurs after the MD2Creature is spawned
    206208*/
    207209void MD2Creature::postSpawn ()
    208 {
    209   //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
    210 }
     210{}
    211211
    212212/**
     
    234234  if (this->getCurrentPlayer() != NULL)
    235235    WorldEntity::draw();
    236 //  this->cameraConnNode.debugDraw(0);
     236
     237  this->cameraConnNode.debugDraw(0);
    237238}
    238239
     
    254255  this->shiftCoor (move);
    255256
     257
     258  // handle animations differently
    256259  if( this->bJump && likely(this->getModel(0) != NULL))
    257260  {
     
    260263  else if( this->bFire && likely(this->getModel(0) != NULL))
    261264  {
    262     if( ((MD2Model*)this->getModel(0))->getAnim() != ATTACK) ((MD2Model*)this->getModel(0))->setAnimation(ATTACK);
     265    if( ((MD2Model*)this->getModel(0))->getAnimation() != ATTACK)
     266      ((MD2Model*)this->getModel(0))->setAnimation(ATTACK);
    263267  }
    264268  else if( fabs(move.len()) > 0.0f && likely(this->getModel(0) != NULL))
    265269  {
    266     if( ((MD2Model*)this->getModel(0))->getAnim() != RUN) ((MD2Model*)this->getModel(0))->setAnimation(RUN);
     270    if( ((MD2Model*)this->getModel(0))->getAnimation() != RUN)
     271      ((MD2Model*)this->getModel(0))->setAnimation(RUN);
    267272  }
    268273  else if (likely(this->getModel(0) != NULL))
    269274  {
    270     if( ((MD2Model*)this->getModel(0))->getAnim() != STAND) ((MD2Model*)this->getModel(0))->setAnimation(STAND);
     275    if( ((MD2Model*)this->getModel(0))->getAnimation() != STAND)
     276      ((MD2Model*)this->getModel(0))->setAnimation(STAND);
    271277  }
    272278
    273279
    274280  //orient the MD2Creature in direction of the mouse
    275   this->setAbsDir(mouseDirX);
     281//   this->setAbsDir(mouseDirX);
     282//    this->cameraConnNode.setRelDir(mouseDirY);
     283
    276284  this->cameraConnNode.setRelDir(mouseDirY);
     285  this->setAbsDir(this->mouseDirX);
    277286}
    278287
     
    286295  Vector accel(0.0, 0.0, 0.0);
    287296  /*
    288   Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter
     297  Vector rot(0.0, 0.0, 0.0); // wird ben�igt fr Helicopter
    289298  */
    290299  //float rotVal = 0.0;
     
    292301  /* calculate the direction in which the craft is heading  */
    293302
     303  if( bMouseMotion)
     304  {
     305    this->mouseDirX *= Quaternion(-M_PI / 4.0f * this->xMouse*mouseSensitivity, Vector(0,1,0));
     306    this->mouseDirY *= Quaternion(-M_PI / 4.0f * this->yMouse*mouseSensitivity, Vector(0,0,1));
     307    this->bMouseMotion = false;
     308  }
     309
    294310  if( this->bUp )
    295    {
    296      accel += (this->getAbsDirX())*2;
    297    }
     311  {
     312    accel += (this->getAbsDirX())*2;
     313  }
    298314
    299315  if( this->bDown )
    300    {
    301      accel -= (this->getAbsDirX())*2;
    302    }
     316  {
     317    accel -= (this->getAbsDirX())*2;
     318  }
    303319
    304320  if( this->bLeft/* > -this->getRelCoor().z*2*/)
     
    329345  }
    330346
    331   velocity = accel * 20.0f;
     347  velocity = accel * 40.0f;
    332348  //rot.normalize();
    333349  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
     
    335351
    336352
    337 
    338353/**
    339354 * @todo switch statement ??
     
    342357{
    343358  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);
     359  if( event.type == KeyMapper::PEV_LEFT)
     360    this->bStrafeL = event.bPressed;
     361  else if( event.type == KeyMapper::PEV_RIGHT)
     362    this->bStrafeR = event.bPressed;
     363  else if( event.type == KeyMapper::PEV_FORWARD)
     364    this->bUp = event.bPressed;
     365  else if( event.type == KeyMapper::PEV_BACKWARD)
     366    this->bDown = event.bPressed;
    352367  else if( event.type == SDLK_SPACE)
    353368    this->bJump = event.bPressed;
    354369  else if( event.type == EV_MOUSE_MOTION)
    355370  {
     371    this->bMouseMotion = true;
    356372    this->xMouse = event.xRel;
    357373    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 }
     374  }
     375}
  • trunk/src/world_entities/creatures/md2_creature.h

    r7346 r8724  
    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.
  • trunk/src/world_entities/npcs/ground_turret.cc

    r7954 r8724  
    3939 */
    4040GroundTurret::GroundTurret(const TiXmlElement* root)
     41  : NPC(root)
    4142{
    4243  this->init();
  • trunk/src/world_entities/npcs/npc.cc

    r7076 r8724  
    1919
    2020#include "npc.h"
    21 #include "obb_tree.h"
    2221
    23 #include "state.h"
    24 #include "stdlibincl.h"
    25 #include "power_ups/turret_power_up.h"
    26 #include "power_ups/laser_power_up.h"
    2722
    2823using namespace std;
    2924
    3025
    31 NPC::NPC()
     26NPC::NPC(const TiXmlElement* root)
    3227{
    3328  this->setClassID(CL_NPC, "NPC");
     29
    3430  this->toList(OM_GROUP_00);
    3531}
     
    3935
    4036
    41 void NPC::collidesWith(WorldEntity* entity, const Vector& location)
    42 {
    4337
    44   if (entity == collider)
    45     return;
    46   collider = entity;
    47 
    48   if (entity->isA(CL_PROJECTILE))
    49   {
    50     this->decreaseHealth(entity->getHealth() *(float)rand()/(float)RAND_MAX);
    51     // EXTREME HACK
    52     if (this->getHealth() <= 0.0f)
    53     {
    54       this->destroy();
    55     }
    56   }
     38/**
     39 * adds an AI to this NPC
     40 */
     41void NPC::addAI(AI* ai)
     42{}
    5743
    5844
    59 // //    PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);
    60 // //    this->applyForce(Vector(0,0,0)-location*1000);
    61 //     if ((float)rand()/RAND_MAX < .3)
    62 //     {
    63 //       WorldEntity* powerUp = new TurretPowerUp();
    64 //       powerUp->setAbsCoor(this->getAbsCoor());
    65 // //      powerUp->toList(OM_COMMON);
    66 //     }
    67 //     else if ((float)rand()/RAND_MAX < .3)
    68 //     {
    69 //       WorldEntity* powerUp = new LaserPowerUp();
    70 //       powerUp->setAbsCoor(this->getAbsCoor());
    71 //       powerUp->toList(OM_COMMON);
    72 //     }
    73 //     this->toList(OM_DEAD);
    74 //     this->removeNode();
    75 //
    76 //       this->collider = entity;
    77 //   }
    78 //   //  else if (entity->isA(CL_PLAYER))
    79 //   //    this->applyForce(Vector(0,0,0)-location*100);
    80 //   else if (entity->isA(CL_NPC))
    81 //   {
    82 //     this->setVisibiliy(false);
    83 //     this->toList(OM_DEAD);
    84 //     this->removeNode();
    85 //   }
     45
     46/**
     47 * loads the xml tags
     48 * @param root: root xml tag for this element
     49 */
     50void NPC::loadParams(const TiXmlElement* root)
     51{
     52  WorldEntity::loadParams(root);
    8653}
     54
  • trunk/src/world_entities/npcs/npc.h

    r6981 r8724  
    44
    55#include "world_entity.h"
    6 #include "physics_interface.h"
    76
    87class AI;
     
    1110
    1211 public:
    13   NPC ();
     12   NPC (const TiXmlElement* root);
    1413  virtual ~NPC ();
    1514
     15  virtual void loadParams(const TiXmlElement* root = NULL);
    1616
    1717  void addAI(AI* ai);
    18 
    19   virtual void collidesWith (WorldEntity* entity, const Vector& location);
    2018
    2119
    2220 private:
    2321
    24    WorldEntity* collider;
    25 
    2622};
    2723
  • trunk/src/world_entities/npcs/npc_test.cc

    r6222 r8724  
    3131
    3232NPC2::NPC2()
     33  : NPC(NULL)
    3334{
    3435  this->setClassID(CL_NPC_TEST2, "NPC2");
  • trunk/src/world_entities/npcs/npc_test1.cc

    r6222 r8724  
    2929
    3030NPCTest1::NPCTest1()
     31  : NPC(NULL)
    3132{
    3233  this->setClassID(CL_NPC_TEST1, "NPCTest1");
  • trunk/src/world_entities/playable.cc

    r8490 r8724  
    6565
    6666  this->bDead = false;
    67 
     67 
    6868  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    6969
     
    376376    if (this->getHealth() <= 0.0f)
    377377    {
    378       this->die();
     378//       this->destory();
    379379
    380380      if( State::getGameRules() != NULL)
     
    411411
    412412
    413 void Playable::die()
     413
     414void Playable::destroy()
    414415{
    415416  Explosion::explode(dynamic_cast<PNode*>(this), Vector(1.0f, 1.0f, 1.0f));
  • trunk/src/world_entities/playable.h

    r8055 r8724  
    7676
    7777  // WorldEntity Extensions
    78   virtual void die();
     78  virtual void destroy();
    7979  virtual void respawn();
    8080  virtual void collidesWith(WorldEntity* entity, const Vector& location);
  • trunk/src/world_entities/space_ships/collision_probe.cc

    r8490 r8724  
    6767  this->loadModel("models/dr_freak.md2");
    6868
    69   this->localVelocity = Vector(0,-4,0);
     69  this->localVelocity = Vector(0,0,0);
    7070}
    7171
  • trunk/src/world_entities/test_entity.h

    r7113 r8724  
    1515class TestEntity : public WorldEntity, public PhysicsInterface
    1616{
    17   friend class World;
    18 
    1917 public:
    2018  TestEntity ();
  • trunk/src/world_entities/world_entity.cc

    r8490 r8724  
    2424#include "md3/md3_model.h"
    2525
     26#include "aabb_tree_node.h"
     27
    2628#include "util/loading/resource_manager.h"
    2729#include "util/loading/load_param.h"
     
    6062
    6163  this->obbTree = NULL;
     64  this->aabbNode = NULL;
    6265  this->healthWidget = NULL;
    6366  this->healthMax = 1.0f;
     
    201204        this->buildObbTree(obbTreeDepth);
    202205    }
    203     else if(fileName.find(".md3") != std::string::npos)
     206    else /*if(fileName.find(".md3") != std::string::npos)*/
    204207    {
    205208      PRINTF(4)("fetching MD3 file: %s\n", fileName.c_str());
     
    240243
    241244  this->models[modelNumber] = model;
    242 
    243 
    244   //   if (this->model != NULL)
    245   //     this->buildObbTree(4);
    246245}
    247246
     
    257256
    258257  if (this->models[0] != NULL)
    259   {
    260258    this->obbTree = new OBBTree(depth, models[0]->getModelInfo(), this);
    261     return true;
    262   }
    263259  else
    264260  {
     
    267263    return false;
    268264  }
     265
     266
     267  // create the axis aligned bounding box
     268  if( this->aabbNode != NULL)
     269  {
     270    delete this->aabbNode;
     271    this->aabbNode = NULL;
     272  }
     273
     274  if( this->models[0] != NULL) {
     275    this->aabbNode = new AABBTreeNode();
     276    this->aabbNode->spawnBVTree(this->models[0]);
     277  }
     278  return true;
    269279}
    270280
     
    604614      this->models[0]->draw();
    605615    }
     616
     617    if( this->aabbNode != NULL)
     618      this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
     619
    606620    glPopMatrix();
    607621  }
     
    712726    this->healthWidget->hide();
    713727}
     728
     729
     730/**
     731 * hit the world entity with
     732 *  @param damage damage to be dealt
     733 */
     734void WorldEntity::hit(float damage)
     735{
     736  this->decreaseHealth(damage);
     737
     738  if( this->getHealth() > 0)
     739  {
     740    // any small explosion animaitions
     741  }
     742  else
     743  {
     744    this->destroy();
     745
     746//     if( State::getGameRules() != NULL)
     747//       State::getGameRules()->registerKill(Kill(NULL, this));
     748  }
     749}
     750
    714751
    715752/**
  • trunk/src/world_entities/world_entity.h

    r8490 r8724  
    1616#include <vector>
    1717
     18#include "aabb_tree_node.h"
     19
    1820#include "physics_interface.h"
    1921
     
    2628class BVTree;
    2729class BoundingVolume;
     30class AABBTreeNode;
    2831class Model;
    2932class CollisionHandle;
     
    5861  virtual void postSpawn ();
    5962  virtual void leaveWorld ();
    60   virtual void destroy() {};
    6163
    6264  virtual void tick (float time);
     
    7375  inline BVTree* getOBBTree() const { return this->obbTree; };
    7476  void drawBVTree(int depth, int drawMode) const;
     77  inline AABB* getModelAABB() { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
    7578
    7679  /* --- Collision Reaction Block --- */
     
    9093
    9194  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
     95
     96  virtual void hit(float damage);
     97  virtual void destroy() {};
    9298
    9399
     
    109115  /** @returns a Reference to the Iterator */
    110116  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
    111 
    112   /* --- Network Block --- */
    113   int       writeState(const byte* data, int length, int sender);
    114   int       readState(byte* data, int maxLength );
    115117
    116118  /* --- Character Attribute Block --- */
     
    167169  std::string             modelLODName;       //!< the name of the model lod file
    168170  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
     171  AABBTreeNode*           aabbNode;           //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension
    169172
    170173  bool                    bCollide;           //!< If it should be considered for the collisiontest.
Note: See TracChangeset for help on using the changeset viewer.