Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8724 in orxonox.OLD for trunk/src


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
Files:
41 edited
12 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r8717 r8724  
    196196  CL_SPECTATOR                  =    0x00000360,
    197197  CL_COLLISION_PROBE            =    0x00000361,
     198  CL_FPS_PLAYER                 =    0x00000362,
    198199
    199200  // Powerups
     
    223224  CL_NPC_TEST1                  =    0x00000401,
    224225  CL_NPC_TEST2                  =    0x00000402,
     226  CL_GENERIC_NPC                =    0x00000403,
    225227
    226228  // Testing Entities
     
    280282  CL_OBB                        =    0x00720000,
    281283  CL_BOUNDING_SPHERE            =    0x00740000,
     284  CL_AABB_TREE_NODE             =    0x00000724,                //FIXME: is this correct? AABB_TREE_NODE isA BV_TREE_NODE
     285  CL_AABB                       =    0x00780000,                //FIXME: is this correct? AABB isA BOUNDING_VOLUME
    282286
    283287
  • trunk/src/lib/collision_detection/Makefile.am

    r8190 r8724  
    1111                     bv_tree_node.cc \
    1212                     bounding_volume.cc \
    13                      bounding_sphere.cc
     13                     bounding_sphere.cc \
     14                     aabb_tree_node.cc \
     15                     aabb.cc
    1416
    1517
     
    2224                     bv_tree_node.h \
    2325                     bounding_volume.h \
    24                      bounding_sphere.h
     26                     bounding_sphere.h \
     27                     aabb_tree_node.h \
     28                     aabb.h
    2529
  • trunk/src/lib/collision_reaction/collision_handle.cc

    r8495 r8724  
    101101      return;
    102102
    103    // add element
    104    //PRINTF(0)("addTarget: %i \n", target);
     103  // add element
     104   PRINTF(5)("addTarget: %i \n", target);
    105105
    106106   this->targetList.push_back(target);
     
    177177
    178178 c->registerCollisionEvent(collisionEvent);
    179  PRINTF(0)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassName(), collisionEvent->getEntityB()->getClassName());
     179 PRINTF(5)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassName(), collisionEvent->getEntityB()->getClassName());
    180180}
    181181
     
    231231    if( collisionEvent->getEntityA() == this->owner) {
    232232      if( collisionEvent->getEntityB()->isA((ClassID)(*it))) {
    233         PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
     233        PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
    234234                  collisionEvent->getEntityB()->getClassName(), *it);
    235235        return true; }
     
    237237    else {
    238238      if( collisionEvent->getEntityA()->isA((ClassID)(*it))) {
    239         PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
     239        PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(),
    240240                  collisionEvent->getEntityA()->getClassName(), *it);
    241241      return true; }
  • trunk/src/lib/collision_reaction/cr_object_damage.cc

    r8490 r8724  
    6363  if( collision->isEntityACollide()) {
    6464    damage = collision->getEntityB()->getDamage();
    65     collision->getEntityA()->decreaseHealth(damage);
     65    collision->getEntityA()->hit(damage);
    6666  }
    6767  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());
     
    6969  if( collision->isEntityBCollide()) {
    7070    damage = collision->getEntityA()->getDamage();
    71     collision->getEntityB()->decreaseHealth(damage);
     71    collision->getEntityB()->hit(damage);
    7272  }
    7373  PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r8490 r8724  
    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: Patrick Boenzli
     
    2424#include "cr_physics_ground_walk.h"
    2525
    26 #include "debug.h"
    27 
    2826#include <vector>
    2927
     
    3533 */
    3634CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
    37   : CollisionReaction()
     35    : CollisionReaction()
    3836{
    3937  this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk");
     
    4543 */
    4644CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
    47 {
    48 }
     45{}
    4946
    5047
     
    5754  CollisionEvent* ce = collision->getCollisionEvents().front();
    5855  Vector normal = ce->getGroundNormal();
    59   normal.normalize();
     56  // normal.normalize();
    6057
    6158  // put it back
    62 //   PRINTF(0)("putting it back to lastPos: \n");
    63 //   this->lastPositions[0].debug();
    64 //   PRINTF(0)("current pos:\n");
    65 //   collision->getEntityB()->getAbsCoor().debug();
     59  //   PRINTF(0)("putting it back to lastPos: \n");
     60  //   this->lastPositions[0].debug();
     61  //   PRINTF(0)("current pos:\n");
     62  //   collision->getEntityB()->getAbsCoor().debug();
    6663
     64
     65  Vector height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor();
     66
     67  if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
     68    collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
     69    return;
     70  }
     71  if(ce->getGroundNormal().len() <= 0.1f) {
     72    collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
     73    return;
     74  }
     75  if(ce->getGroundNormal().len() >= 1.4f) {
     76    downspeed++;
     77    collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
     78    return;
     79  }
     80
     81
     82  if(height.y < -3.510001 + 10.0) // Above ground
     83  {
     84    if(height.y > -15.6) // Snap in
     85    {
     86      downspeed = 0;
     87      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,height.y+3.500005 + 10.0,0.0));
     88    } else
     89    {
     90      downspeed++;
     91      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
     92    }
     93
     94  }
     95  else {
     96    if(height.y > -3.50000 + 10.0  && height.y <    9.9+ 10.0) // below ground
     97    {
     98      //if(downspeed <= 0) downspeed =1;
     99      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, 0.00001 /*height.y+3.500005 + 10.0*/,0.0));
     100      //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));
     101      downspeed = 0;
     102    }
     103
     104  }
     105
     106
     107  /*
    67108  PRINTF(0)("Collision with Ground: \n");
    68109  collision->getEntityB()->getAbsCoor().debug();
     110  collision->getEntityB()->setVelocity(Vector());
     111  collision->getEntityB()->setAbsCoor(this->lastPositions[1]);
    69112
    70   //collision->getEntityB()->setVelocity(Vector());
    71   //collision->getEntityB()->setAbsCoor(this->lastPositions[5]);
     113  */
    72114}
     115
    73116
    74117
     
    81124  for( int i = 9; i > 0; i--) {
    82125    this->lastPositions[i] = this->lastPositions[i-1];
    83 //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
     126    //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
    84127  }
    85128  this->lastPositions[0] = owner->getAbsCoor();
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.h

    r8490 r8724  
    2929
    3030    Vector       lastPositions[10];           //!< last 10 positions
     31    float        downspeed;
    3132};
    3233
  • trunk/src/lib/event/key_mapper.cc

    r7677 r8724  
    4545int KeyMapper::PEV_STRAFE_LEFT       = EV_UNKNOWN;
    4646int KeyMapper::PEV_STRAFE_RIGHT      = EV_UNKNOWN;
     47int KeyMapper::PEV_JUMP              = EV_UNKNOWN;
    4748
    4849int KeyMapper::PEV_FIRE1             = EV_UNKNOWN;
     
    8384  {&KeyMapper::PEV_STRAFE_LEFT,          "StrafeLeft",                       SDLK_q},
    8485  {&KeyMapper::PEV_STRAFE_RIGHT,         "StrafeRight",                      SDLK_e},
     86  {&KeyMapper::PEV_JUMP,                 "Jump",                             SDLK_SPACE},
    8587
    8688  {&KeyMapper::PEV_FIRE1,                CONFIG_NAME_PLAYER_FIRE,            EV_MOUSE_BUTTON_LEFT},
  • trunk/src/lib/event/key_mapper.h

    r7661 r8724  
    5555  static int PEV_STRAFE_RIGHT;      //!< strafe right button
    5656
     57  static int PEV_JUMP;              //!< jump
     58
    5759  static int PEV_FIRE1;             //!< fire button 1
    5860  static int PEV_FIRE2;             //!< fire button 2
  • trunk/src/lib/graphics/importer/Makefile.am

    r8490 r8724  
    3434                           md3/md3_model.cc \
    3535                           md3/md3_animation.cc \
     36                           md3/md3_animation_cfg.cc \
    3637                           md3/md3_bone_frame.cc \
    3738                           md3/md3_mesh.cc \
     
    7677                md3/md3_model.h \
    7778                md3/md3_animation.h \
     79                md3/md3_animation_cfg.h \
    7880                md3/md3_bone_frame.h \
    7981                md3/md3_mesh.h \
  • trunk/src/lib/graphics/importer/bsp_manager.cc

    r8490 r8724  
    5050BspManager::BspManager(WorldEntity* parent)
    5151{
    52  
     52
    5353  this->parent = parent;
    5454  /*// open a BSP file
     
    840840        this->checkBrushRayN(&curBrush);
    841841      if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
    842     }
     842    }
     843   
    843844    return;
    844845  }
     
    907908
    908909}
     910
     911float BspManager::checkPatchAltitude(BspTreeNode* node)
     912{
     913  leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
     914  for(int i = 0; i < curLeaf.n_leaffaces ; i++)
     915  {
     916   
     917  }
     918  return 10.0f;
     919}
     920
    909921void BspManager::checkCollisionBox(void)
    910922{
     
    937949void BspManager::checkCollision(WorldEntity* worldEntity)
    938950{
    939  
     951
    940952  this->outputStartsOut = true;
    941953  this->outputAllSolid = false;
    942954  this->outputFraction = 1.0f;
    943  
    944   Vector position = worldEntity->getAbsCoor();
     955
     956
    945957
    946958
    947959  Vector forwardDir = worldEntity->getAbsDirX();
    948   forwardDir = forwardDir * 8.0f;
     960
    949961
    950962  Vector upDir = worldEntity->getAbsDirY();
     
    958970  dest.z  += forwardDir.z;
    959971  */
    960 
    961   dest = worldEntity->getAbsCoor() - upDir*40.0;
     972  Vector position = worldEntity->getAbsCoor() + upDir*10.0f ;
     973  dest = worldEntity->getAbsCoor() - upDir*40.0f; //
    962974  Vector out = dest;
    963975
     
    966978
    967979  bool collision = false;
    968   Vector position1 = position + Vector(0.0,0.1,0.0);
    969   Vector position2 = position + Vector(0.0,0.2,0.0);
    970   Vector dest1 = position1 + forwardDir;
     980  Vector position1 = position; // + Vector(0.0,0.6,0.0);
     981  Vector position2 = position + Vector(0.0,1.0,0.0);
     982  Vector dest1 = position + forwardDir*4.0f;
    971983  Vector dest2 = position2 + forwardDir;
    972984  dest = position - Vector(0.0, 40.0,0.0);
     
    976988
    977989  float height = 40;
    978  
     990
    979991  this->inputStart =  position;
    980992  this->inputEnd =   dest;
    981993  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
    982 
    983   PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction);
    984   PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z);
    985   PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z); 
     994 
     995
     996
     997//   PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction);
     998//   PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z);
     999//   PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z);
     1000
    9861001//   position1.debug();
     1002
     1003  if(!this->outputStartsOut )
     1004  {
     1005    this->collPlane = new plane;
     1006    this->collPlane->x = 0.0f;
     1007    this->collPlane->y = 0.0f;
     1008    this->collPlane->z = 0.0f;
     1009    collision = true;
     1010  }
     1011  else
     1012  {
     1013
     1014
     1015
    9871016
    9881017  if( this->outputFraction == 1.0f)
    9891018  {
    990     if(this->outputAllSolid)
     1019    if(this->outputAllSolid )
    9911020    {
    9921021      this->collPlane = new plane;
    993       this->collPlane->x = 1.0f;
     1022      this->collPlane->x = 0.0f;
    9941023      this->collPlane->y = 0.0f;
    9951024      this->collPlane->z = 0.0f;
     
    10131042  }
    10141043
     1044
     1045  }
     1046 
     1047  plane* testPlane = this->collPlane;
     1048 
     1049  this->outputStartsOut = true;
     1050  this->outputAllSolid = false;
     1051  this->outputFraction = 1.0f;
     1052  this->inputStart =  position;
     1053  this->inputEnd =   dest1;
     1054  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest1 );
     1055  out.x = this->outputFraction;
     1056  out.z = this->outputFraction;
     1057 
     1058  /*
     1059  out.x = position1.x + (dest.x -position1.x) * this->outputFraction;
     1060 
     1061  out.z = position1.z + (dest.z -position1.z) * this->outputFraction;
     1062  */
     1063 
     1064 
    10151065  // Return the normal here: Normal's stored in this->collPlane;
    10161066  if( collision) {
    1017     PRINTF(0)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
    1018     worldEntity->registerCollision(this->parent, worldEntity, Vector(this->collPlane->x, this->collPlane->y, this->collPlane->z), out);
    1019   }
     1067    PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
     1068    worldEntity->registerCollision(this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out);
     1069  }
     1070  else  worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest);
    10201071
    10211072}
  • trunk/src/lib/graphics/importer/bsp_manager.h

    r8490 r8724  
    7373  void  checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
    7474  void  checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
    75   void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
     75  void  TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
    7676  void  checkCollisionBox(void);
    7777  void  checkBrushRay(brush* curBrush);
    7878  void  checkBrushRayN(brush* curBrush);
    79   void   checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
     79  void  checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
     80  float  checkPatchAltitude(BspTreeNode* node); //! To be implemented...
    8081
    8182  void drawDebugCube(Vector* cam);
  • trunk/src/lib/graphics/importer/interactive_model.h

    r8490 r8724  
    3737
    3838    virtual void setAnimation(int animNum, int playbackMode = 0) = 0;
     39    virtual int getAnimation() = 0;
    3940};
    4041
  • trunk/src/lib/graphics/importer/md2/md2Model.h

    r8490 r8724  
    159159  virtual void setAnimation(int type, int animPlayback = MD2_ANIM_LOOP);
    160160  /**  returns the current animation @returns animation type */
    161   inline int MD2Model::getAnim() { return this->animationState.type; }
     161  inline int MD2Model::getAnimation() { return this->animationState.type; }
    162162  /**  scales the current model @param scaleFactor: the factor [0..1] to use for scaling */
    163163  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
  • trunk/src/lib/graphics/importer/md3/md3_animation.cc

    r8490 r8724  
    2222{
    2323
     24
     25
     26  MD3AnimationMap MD3Animation::animationList[25] = {
     27    { "Death 1",                 BOTH  },
     28    { "Dead 1",                  BOTH  },
     29    { "Death 2",                 BOTH  },
     30    { "Dead 2",                  BOTH  },
     31    { "Death 3",                 BOTH  },
     32    { "Dead 3",                  BOTH  },
     33    { "Gesture",                 BOTH  },
     34    { "Shoot",                   TORSO },
     35    { "Hit",                     TORSO },
     36    { "Drop Weapon",             TORSO },
     37    { "Raise Weapon",            TORSO },
     38    { "Stand With Weapon",       TORSO },
     39    { "Stand with Gauntlet",     TORSO },
     40    { "Crouched Walk",           LEGS  },
     41    { "Walk",                    LEGS  },
     42    { "Run",                     LEGS  },
     43    { "Backpedal",               LEGS  },
     44    { "Swim",                    LEGS  },
     45    { "Jump Forward",            LEGS  },
     46    { "Land Forward",            LEGS  },
     47    { "Jump Backward",           LEGS  },
     48    { "Land Backward",           LEGS  },
     49    { "Stand Idle",              LEGS  },
     50    { "Crouched Idle",           LEGS  },
     51    { "Turn In Place",           LEGS  }
     52  };
     53
     54
    2455  /**
    2556   * create an empty MD3Animation object
     
    2859  {
    2960    this->init();
    30   }
    31 
    32 
    33   /**
    34    * create a new MD3 Anumation object and initialize it with the data on the given line
    35    * @param line: the line to read from
    36    */
    37   MD3Animation::MD3Animation(std::string line)
    38   {
    39     this->init();
    40     // loadAnimation()
    4161  }
    4262
  • trunk/src/lib/graphics/importer/md3/md3_animation.h

    r8490 r8724  
    1111#include <string>
    1212
     13namespace md3
     14{
    1315
    14 typedef struct AnimationType
    15 {};
     16typedef enum MD3AnimationType {
     17  LEGS      = 0,             //!< animation only applicatble to the legs. top level model loaded from lower.md3
     18  TORSO,                     //!< animation only applicatboe to the torso. normaly loaded from upper.md3
     19  BOTH,                      //!< animation is applicable on both
     20  ALL,                       //!< animation is applicable to all submodels
     21
     22  NUM_ANIMATION_TYPE         //!< number of animations
     23};
     24
     25
     26typedef struct MD3AnimationMap {
     27  std::string        animationName;
     28  MD3AnimationType   animationType;
     29};
     30
     31
    1632
    1733
     
    2440  public:
    2541    MD3Animation();
    26     MD3Animation(std::string line);
    2742    virtual ~MD3Animation();
    2843
     
    3348
    3449  public:
    35     AnimationType    type;                        //!< specifies for what parts of a model this animation is appilcable (e.g. LEGS, BOTH)
    36     std::string      name;                        //!< name of the animation
     50    MD3AnimationType      type;                      //!< specifies for what parts of a model this animation is appilcable (e.g. LEGS)
     51    std::string           name;                      //!< name of the animation
    3752
    38     int              offset;                      //!< for LEGS animation, this is the offset value to skip TORSO frames
    39     int              first;                       //!< first frame
    40     int              numFrames;                   //!< the number of frames in the anumation. < 0 means that all available frames used
    41     int              numLoopFrames;               //!< number of looping frames
    42     int              fps;                         //!< frames per second
     53    int                   offset;                    //!< for LEGS animation, this is the offset value to skip TORSO frames
     54    int                   first;                     //!< first frame
     55    int                   numFrames;                 //!< the number of frames in the anumation. < 0 means that all available frames used
     56    int                   numLoopFrames;             //!< number of looping frames
     57    int                   fps;                       //!< frames per second
    4358
    44 
     59    static MD3AnimationMap animationList[25];         //!< the animation list
    4560};
    4661
    47 
     62}
    4863#endif /* _MD3_ANIMATION_H */
  • trunk/src/lib/graphics/importer/md3/md3_bone_frame.h

    r8490 r8724  
    66 */
    77
    8 #ifndef _MD3_ANIMATION_H
    9 #define _MD3_ANIMATION_H
     8#ifndef _MD3_BONE_FRAME_ANIMATION_H
     9#define _MD3_BONE_FRAME_ANIMATION_H
    1010
    1111#include "vector.h"
     
    5151}
    5252
    53 #endif /* _MD3_ANIMATION_H */
     53#endif /* _MD3_BONE_FRAME_ANIMATION_H */
  • trunk/src/lib/graphics/importer/md3/md3_data.cc

    r8490 r8724  
    3737MD3Data::MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
    3838{
    39 
    40 
     39  this->filename = modelFileName;
     40
     41  this->parentTagIndex = -1;
     42  this->parent = NULL;
     43
     44  this->animationState.currentFrame = 0;
     45  this->animationState.nextFrame = 1;
     46  this->animationState.interpolationFraction = 0.0f;
     47
     48  this->animation = NULL;
     49  this->bInterpolate = false;
     50  this->upperBound = 0;
    4151
    4252  this->loadModel(modelFileName);
    4353//   this->loadSkin(skinFileName);
     54  this->init();
    4455}
    4556
     
    5465  delete this->header;
    5566}
     67
     68
     69/**
     70 * init data
     71 */
     72void MD3Data::init()
     73{
     74  // create the temporary data to work with (interpolation data)
     75  this->tmpBoneFrame = new MD3BoneFrame();
     76
     77  this->tmpMesh = new sVec3D*[this->header->meshNum];
     78  for( int i = 0; i < this->header->meshNum; i++)
     79    this->tmpMesh[i] = new sVec3D[this->meshes[i]->header->vertexNum];
     80
     81  this->tmpNormal = new MD3Normal*[this->header->meshNum];
     82  for( int i = 0; i < this->header->meshNum; i++)
     83    this->tmpNormal[i] = new MD3Normal[this->meshes[i]->header->vertexNum];
     84
     85  // there are at most 4 different models and submodels
     86  this->tmpMatrix = new float*[4];
     87  for( int i = 0; i < 4; i++)
     88    this->tmpMatrix[i] = new float[16];
     89
     90}
     91
     92
     93/**
     94 * link a model at the specified tag position to this model. if the position is already
     95 * occupied, the old submodel will be replaced
     96 *
     97 *  @param tagIndex: tag to link the submodel to
     98 *  @param child: the submodel that should be linked to this model
     99 */
     100void MD3Data::addLinkedModel(int tagIndex, MD3Data* child)
     101{
     102  this->sortedMap[tagIndex] = child;
     103  child->parentTagIndex = tagIndex;
     104}
     105
     106
     107
     108/**
     109 * Return the index of the tag with the given name for this model.
     110 *
     111 * This will return -1 if their is no such tag.
     112 */
     113 int MD3Data::getTagIndexByName(std::string tagName)
     114{
     115   int res = -1;
     116
     117   if( this->header->boneFrameNum > 0) {
     118     MD3Tag** tags = this->boneFrames[0]->tags;
     119     for( int i = 0; i < this->header->tagNum; i++)
     120       if( tags[i]->name.find(tagName) == std::string::npos)
     121         return i;
     122   }
     123
     124   return res;
     125 }
    56126
    57127
     
    67137//  char* buffer;                           //buffer for frame data
    68138  int fileOffset = 0;                     // file data offset
    69 
    70139
    71140
     
    219288      fread(md, 1, sizeof(MD3TagData), pFile);
    220289      this->boneFrames[i]->tags[j]->data = md;
     290
     291      this->boneFrames[i]->tags[j]->name = std::string(this->boneFrames[i]->tags[j]->data->name);
     292      this->boneFrames[i]->tags[j]->position = Vector( this->boneFrames[i]->tags[j]->data->position[0],
     293                                                       this->boneFrames[i]->tags[j]->data->position[1],
     294                                                       this->boneFrames[i]->tags[j]->data->position[2]);
     295      for( int k = 0; k < 3; k++)
     296        for( int l = 0; l < 3; l++)
     297          this->boneFrames[i]->tags[j]->matrix[k][l] = this->boneFrames[i]->tags[j]->data->matrix[k][l];
     298
     299      //PRINTF(0)("Tag name: %s\n", this->boneFrames[i]->tags[j]->name.c_str());
    221300    }
    222301  }
     
    318397  fread(this->meshes[mesh]->triangles, 1, sizeof(MD3Triangle) * this->meshes[mesh]->header->triangleNum, pFile);
    319398
     399//   for( int i = 0; i < this->meshes[mesh]->header->triangleNum; i++) {
     400//     PRINTF(0)("Triangle read: %i, %i, %i\n", this->meshes[mesh]->triangles[i].vertexOffset[0], this->meshes[mesh]->triangles[i].vertexOffset[1]
     401//         , this->meshes[mesh]->triangles[i].vertexOffset[2]);
     402//   }
     403
    320404  return this->meshes[mesh]->header->triangleNum * sizeof(MD3Triangle);
    321405}
     
    337421  for( int i = 0; i < this->meshes[mesh]->header->textureNum; i++) {
    338422    PRINTF(0)(" texture file: %s\n", tex[i].fileName);
    339     this->meshes[mesh]->material[i].setDiffuseMap(tex[i].fileName);
     423#warning texture stuff hard coded. make this again
     424    std::string path("/home/boenzlip/tmp/q3/Downloads/MOH/q3mdl-alien3/");
     425    std::string path1(tex[i].fileName);
     426    std::string fullPath( path + path1);
     427    this->meshes[mesh]->material[i].setDiffuseMap(/*tex[i].fileName*/ /*fullPath.c_str()*/ "maps/creatures/gork/gorkup.tga");
    340428    this->meshes[mesh]->material[i].setAmbient(1, 1, 1);
    341429  }
     
    355443  fread(this->meshes[mesh]->texVecs, 1, sizeof(MD3TexVecs) * this->meshes[mesh]->header->vertexNum, pFile);
    356444
     445//   for( int i = 0; i < this->meshes[mesh]->header->vertexNum; i++)  {
     446//     PRINTF(0)("TexVec read: %f, %f\n", this->meshes[mesh]->texVecs[i].textureCoord[0], this->meshes[mesh]->texVecs[i].textureCoord[0]);
     447//   }
     448
    357449  return this->meshes[mesh]->header->vertexNum * sizeof(MD3TexVecs);
    358450}
     
    367459
    368460  // reserver memory for the vertex informations
    369   this->meshes[mesh]->meshFrames = new sVec3D[this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum];
    370   this->meshes[mesh]->normals = new MD3Normal[this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum];
    371 
    372   for( int i = 0; i < this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum; i++)
     461  this->meshes[mesh]->meshFrames = new sVec3D*[this->meshes[mesh]->header->meshFrameNum]; // * this->meshes[mesh]->header->vertexNum
     462  this->meshes[mesh]->normals = new MD3Normal*[this->meshes[mesh]->header->meshFrameNum];
     463
     464  for( int i = 0; i < this->meshes[mesh]->header->meshFrameNum; i++)
    373465  {
    374     // read out the compressed data
    375     MD3VertexCompressed* vc = new MD3VertexCompressed;
    376     fread(vc, 1, sizeof(MD3VertexCompressed), pFile);
    377 
    378     this->meshes[mesh]->meshFrames[i][0] = (float)vc->vector[0] / 64.0f;
    379     this->meshes[mesh]->meshFrames[i][1] = (float)vc->vector[1] / 64.0f;
    380     this->meshes[mesh]->meshFrames[i][2] = (float)vc->vector[2] / 64.0f;
    381 
    382     this->meshes[mesh]->normals[i].vertexNormal[0] = vc->vertexNormal[0];
    383     this->meshes[mesh]->normals[i].vertexNormal[1] = vc->vertexNormal[1];
    384 
    385     delete vc;
     466    this->meshes[mesh]->meshFrames[i] = new sVec3D[this->meshes[mesh]->header->vertexNum];
     467    this->meshes[mesh]->normals[i] = new MD3Normal[this->meshes[mesh]->header->vertexNum];
     468
     469    for( int j = 0; j < this->meshes[mesh]->header->vertexNum; j++)
     470    {
     471      // read out the compressed data
     472      MD3VertexCompressed* vc = new MD3VertexCompressed;
     473      fread(vc, 1, sizeof(MD3VertexCompressed), pFile);
     474
     475      this->meshes[mesh]->meshFrames[i][j][0] = (float)vc->vector[0] / 64.0f;
     476      this->meshes[mesh]->meshFrames[i][j][1] = (float)vc->vector[1] / 64.0f;
     477      this->meshes[mesh]->meshFrames[i][j][2] = (float)vc->vector[2] / 64.0f;
     478
     479      this->meshes[mesh]->normals[i][j].vertexNormal[0] = (int)vc->vertexNormal[0];
     480      this->meshes[mesh]->normals[i][j].vertexNormal[1] = (int)vc->vertexNormal[1];
     481
     482//     PRINTF(0)("nr: %i, meshframes: %f, %f, %f, normal: %f, %f\n", i, this->meshes[mesh]->meshFrames[i][0], this->meshes[mesh]->meshFrames[i][1],
     483//     this->meshes[mesh]->meshFrames[i][2], this->meshes[mesh]->normals[i].vertexNormal[0], this->meshes[mesh]->normals[i].vertexNormal[1]);
     484
     485      delete vc;
     486    }
    386487  }
    387488
    388   // delete the temp memory again
    389 //   delete vc;
    390 
    391489  return this->meshes[mesh]->header->meshFrameNum * this->meshes[mesh]->header->vertexNum * sizeof(MD3VertexCompressed);
    392490}
    393491
    394 }
    395 
    396 
    397 
    398 
    399 
    400 
    401 
     492
     493
     494}
     495
     496
     497
     498
     499
     500
     501
  • trunk/src/lib/graphics/importer/md3/md3_data.h

    r8490 r8724  
    2525#include "md_model_structure.h"
    2626
     27#include <map>
     28
    2729
    2830//! These are the needed defines for the max values when loading .MD2 files
    2931#define MD3_IDENT                       (('3'<<24) + ('P'<<16) + ('D'<<8) + 'I') //!< the md3 identifier tag in the bin file
    3032#define MD3_VERSION                     15                                       //!< the md2 version in the header
    31 #define MD2_MAX_TRIANGLES               4096                                     //!< maximal triangles count
    32 #define MD2_MAX_VERTICES                2048                                     //!< maximal vertices count
    33 #define MD2_MAX_TEXCOORDS               2048                                     //!< maximal tex coordinates
    34 #define MD2_MAX_FRAMES                  512                                      //!< maximal frames
    35 #define MD2_MAX_SKINS                   32                                       //!< maximal skins
    36 #define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)             //!< maximal framesize
    3733
    38 #define NUM_VERTEX_NORMALS              162                                      //!< number of vertex normals
    39 #define SHADEDOT_QUANT                  16                                       //!< shade dot quantity - no idea what it is
    40 
    41 //! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
    42 #define kAnimationSpeed                 12.0f                                    //!< animation speed
    4334
    4435
     
    4839  class MD3BoneFrame;
    4940  class MD3Mesh;
     41  class MD3Normal;
     42  class MD3Animation;
    5043
    51 //! This holds the header information that is read in at the beginning of the file: id software definition
    52 struct MD3Header
    53 {
    54    int ident;                           //!< This is used to identify the file
    55    int version;                         //!< The version number of the file (Must be 8)
     44  //! This holds the header information that is read in at the beginning of the file: id software definition
     45  typedef struct MD3Header
     46  {
     47    int ident;                           //!< This is used to identify the file
     48    int version;                         //!< The version number of the file (Must be 8)
    5649
    57    char filename[68];                   //!< The filename of the model
     50    char filename[68];                   //!< The filename of the model
    5851
    59    int boneFrameNum;                    //!< number of frames
    60    int tagNum;                          //!< number of tags
    61    int meshNum;                         //!< number of mesh
    62    int maxTexNum;                       //!< number of texture
     52    int boneFrameNum;                    //!< number of frames
     53    int tagNum;                          //!< number of tags
     54    int meshNum;                         //!< number of mesh
     55    int maxTexNum;                       //!< number of texture
    6356
    64    int boneFrameStart;                  //!< start of bone frames
    65    int tagStart;                        //!< start of the tag
    66    int meshStart;                       //!< mesh start
     57    int boneFrameStart;                  //!< start of bone frames
     58    int tagStart;                        //!< start of the tag
     59    int meshStart;                       //!< mesh start
    6760
    68    int fileSize;                        //!< file size
    69 };
     61    int fileSize;                        //!< file size
     62  };
     63
     64  //!< holding the informations about the current animation state
     65  typedef struct MD3AnimationState
     66  {
     67    int     currentFrame;          //!< currently rendered animation key frame of this model. Every part has its own current frame!
     68    int     nextFrame;             //!< next animation key frame of the model.
     69    float   interpolationFraction; //!< interpolation position between currentFrame and nextFrame [0,1]
     70  };
    7071
    7172
     73  //! class to store the md2 data in
     74  class MD3Data : public BaseObject
     75  {
     76    public:
     77      MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
     78      virtual ~MD3Data();
    7279
    73 //! class to store the md2 data in
    74 class MD3Data : public BaseObject
    75 {
    76  public:
    77    MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
    78   virtual ~MD3Data();
     80      void addLinkedModel(int tagIndex, MD3Data* child);
     81      int getTagIndexByName(std::string name);
     82
     83    private:
     84      bool loadModel(const std::string& fileName);
     85      bool loadSkin(const std::string& fileName = "");
     86
     87      void init();
     88
     89      int readHeader(FILE* pFile, int fileOffset);
     90      int readBoneFrames(FILE* pFile, int fileOffset);
     91      int readTags(FILE* pFile, int fileOffset);
     92      int readMeshes(FILE* pFile, int fileOffset);
    7993
    8094
    81  private:
    82    bool loadModel(const std::string& fileName);
    83    bool loadSkin(const std::string& fileName = "");
    84 
    85    int readHeader(FILE* pFile, int fileOffset);
    86    int readBoneFrames(FILE* pFile, int fileOffset);
    87    int readTags(FILE* pFile, int fileOffset);
    88    int readMeshes(FILE* pFile, int fileOffset);
     95      int readMeshTriangles(FILE* pFile, int fileOffset, int mesh);
     96      int readMeshTextures(FILE* pFile, int fileOffset, int mesh);
     97      int readMeshTexVecs(FILE* pFile, int fileOffset, int mesh);
     98      int readMeshVertices(FILE* pFile, int fileOffset, int mesh);
    8999
    90100
    91    int readMeshTriangles(FILE* pFile, int fileOffset, int mesh);
    92    int readMeshTextures(FILE* pFile, int fileOffset, int mesh);
    93    int readMeshTexVecs(FILE* pFile, int fileOffset, int mesh);
    94    int readMeshVertices(FILE* pFile, int fileOffset, int mesh);
     101    public:
    95102
    96  public:
     103      MD3Header*                header;            //!< the header file
    97104
    98   MD3Header*          header;            //!< the header file
     105      std::map<int, MD3Data*>   sortedMap;         //!< map
     106      int                       parentTagIndex;    //!< the tag index of the parent model
     107      MD3Data*                  parent;            //!< the parent model
    99108
    100   std::string         filename;          //!< the name of the file as recorded in the .md3 file
    101   std::string         loadFilename;      //!< filename of the actual file from which data was loaded
     109      std::string               filename;          //!< the name of the file as recorded in the .md3 file
    102110
    103   int                 boneFrameNum;      //!< number of anumation key fames in the models
    104   int                 tagNum;            //!< number of tags
    105   int                 meshNum;           //!< number of meshes
     111      MD3AnimationState         animationState;    //!< the animation state of this model
    106112
    107   int                 maxTextureNum;     //!< maximum number of unique used in an md3 file
    108   int                 boneFrameStart;    //!< starting position of bone frame data structures
    109   int                 tagStart;          //!< starting position of tag-structures
     113      MD3BoneFrame**            boneFrames;        //!< array of bone frames, contains the metadata (bounding box, tags,...) for each frame
     114      MD3Mesh**                 meshes;            //!< array of meshes in the model. each containing the mesh for each of the animation
    110115
    111   int                 meshStart;         //!< starting position of mesh structures
    112 
    113   int                 fileSize;          //!< file size
     116      MD3BoneFrame*             tmpBoneFrame;      //!< a temporary bone frame
     117      sVec3D**                  tmpMesh;           //!< a temporary mesh frame
     118      MD3Normal**               tmpNormal;         //!< a temporary normals frame
     119      float**                   tmpMatrix;         //!< a temporary matrix
    114120
    115121
    116   MD3BoneFrame**      boneFrames;        //!< array of bone frames, contains the metadata (bounding box, tags,...) for each frame
    117   MD3Mesh**           meshes;            //!< array of meshes in the model. each containing the mesh for each of the animation
    118 
    119   int                 parentTagIndex;    //!< tag index
    120 
    121   //MD3Model*           parent;            //!< reference to the MD3Model
    122 
    123 
    124 };
     122     /* the animation part */
     123     MD3Animation*              animation;         //!< animation
     124     int                        op;                //!< the current operation
     125     int                        upperBound;        //!< the upper bound
     126     bool                       bInterpolate;      //!< interpolate the frames
     127  };
    125128
    126129
  • trunk/src/lib/graphics/importer/md3/md3_mesh.h

    r8490 r8724  
    7777    MD3Triangle*       triangles;               //!< indices into mesh frames and texture coord arrays
    7878    MD3TexVecs*        texVecs;                 //!< tex vecs coordinates
    79     sVec3D*            meshFrames;              //!< mesh frames
    80     MD3Normal*         normals;                 //!< 3d array of normals with spherical coordinates giving the dir of the vertex normal
     79    sVec3D**           meshFrames;              //!< mesh frames
     80    MD3Normal**        normals;                 //!< 3d array of normals with spherical coordinates giving the dir of the vertex normal
    8181
    8282};
  • trunk/src/lib/graphics/importer/md3/md3_model.cc

    r8490 r8724  
    1818
    1919#include "md3_data.h"
    20 
     20#include "md3_mesh.h"
     21#include "md3_tag.h"
     22#include "md3_bone_frame.h"
     23#include "md3_animation.h"
     24
     25#include "md3_animation_cfg.h"
     26
     27#include "material.h"
     28#include "quaternion.h"
     29
     30#include "loading/resource_manager.h"
     31
     32#include "debug.h"
    2133
    2234namespace md3
     
    2840  MD3Model::MD3Model(std::string filename, float scaling)
    2941  {
    30     this->md3Data = new MD3Data(filename, filename, scaling);
     42    this->autoAssemblePlayerModel(filename, scaling);
     43
     44    this->bDrawBones = false;
     45    this->bDrawNormals = false;
     46
     47    this->time = 0.0f;
     48
     49    // set the animation
     50    this->interpolate(this->md3Data, this->config->getAnimation("Dead 1"), MD3_ANIM_NEXT, true);
    3151  }
    3252
     
    3454
    3555  MD3Model::~MD3Model()
     56  {
     57//     delete this->tmpBoneFrame;
     58//     delete [] this->tmpMesh;
     59
     60    ///TODO deleting mesh
     61    ///TODO deleting matrices
     62  }
     63
     64
     65  /**
     66   * auto assemples a player model
     67   * @param filename is the name to the directory of the modelzzzzzz
     68   */
     69  void MD3Model::autoAssemblePlayerModel(std::string filename, float scaling)
     70  {
     71    // loading the config file
     72    std::string cfgName(filename + "/animation.cfg");
     73    this->config = (MD3AnimationCfg*)ResourceManager::getInstance()->load(cfgName, MD3_CONFIG, RP_GAME);
     74
     75    //first load the torso or the upper part
     76    std::string nameUpper(filename + "/upper.md3");
     77    if( (this->md3Data = (MD3Data*)ResourceManager::getInstance()->load(nameUpper, MD3, RP_GAME, nameUpper, scaling)) == NULL)
     78    {
     79      std::string nameTorso(filename + "/torso.md3");
     80      this->md3Data = (MD3Data*)ResourceManager::getInstance()->load(nameTorso, MD3, RP_GAME, nameTorso, scaling);
     81    }
     82
     83    if( this->md3Data == NULL)
     84    {
     85      PRINTF(1)("Problems loading the MD3Model. Abording\n");
     86      return;
     87    }
     88
     89    // load lower
     90    std::string nameLower(filename + "/lower.md3");
     91    MD3Data* lower = (MD3Data*)ResourceManager::getInstance()->load(nameLower, MD3, RP_GAME, nameLower, scaling);
     92    if( lower != NULL)
     93    {
     94      int tag = this->md3Data->getTagIndexByName("tag_lower");
     95      PRINTF(0)("Loaded the %s model on index %i\n", nameLower.c_str(), tag);
     96      if( tag >= 0)
     97       this->md3Data->addLinkedModel(tag, lower);
     98      else
     99        PRINTF(0)("Could not add %s\n", nameLower.c_str());
     100
     101    }
     102
     103
     104    // load head
     105    std::string nameHead(filename + "/head.md3");
     106    MD3Data* head = (MD3Data*)ResourceManager::getInstance()->load(nameHead, MD3, RP_GAME, nameLower, scaling);
     107    if( head != NULL)
     108    {
     109      int tag = this->md3Data->getTagIndexByName("tag_head");
     110      PRINTF(0)("Loaded the %s model on index %i\n", nameHead.c_str(), tag);
     111      if( tag >= 0)
     112        this->md3Data->addLinkedModel(tag, head);
     113      else
     114        PRINTF(0)("Could not add %s\n", nameHead.c_str());
     115    }
     116
     117  }
     118
     119
     120
     121  /**
     122   * tick float
     123   * @param time: time elapsed
     124   */
     125  void MD3Model::tick(float time)
     126  {
     127    if(this->md3Data == NULL)
     128      return;
     129
     130    this->visit(this->md3Data, time);
     131
     132    this->tick(time, this->md3Data);
     133  }
     134
     135
     136  /**
     137   * tick each data
     138   */
     139  void MD3Model::tick(float time, MD3Data* data)
     140  {
     141    // draw the bones if needed#
     142    if( this->bDrawBones)
     143    {
     144      // get bone frame, interpolate if necessary
     145      if( data->animationState.interpolationFraction != 0.0 &&
     146          data->animationState.currentFrame != data->animationState.nextFrame)
     147      {
     148        //interpolate bone frame
     149        data->tmpBoneFrame = this->interpolateBoneFrame(data, data->boneFrames[data->animationState.currentFrame],
     150                                                        data->boneFrames[data->animationState.nextFrame],
     151                                                        data->animationState.interpolationFraction);
     152      }
     153      else
     154      {
     155        data->tmpBoneFrame = data->boneFrames[data->animationState.currentFrame];
     156      }
     157    }
     158
     159
     160    //draw all meshes of current frame of this model
     161    for( int i = 0;  i < data->header->meshNum; i++)
     162    {
     163      MD3Mesh* mesh = data->meshes[i];
     164
     165      //interpolate mesh frame between the 2 current mesh frames
     166      if( data->header->boneFrameNum > 1)
     167        this->interpolateMeshFrame( data,
     168                                    mesh->meshFrames[data->animationState.currentFrame],
     169                                    mesh->meshFrames[data->animationState.nextFrame],
     170                                    data->animationState.interpolationFraction, mesh, i);
     171      else
     172        this->interpolateMeshFrame( data,
     173                                    mesh->meshFrames[data->animationState.currentFrame],
     174                                    mesh->meshFrames[data->animationState.currentFrame],
     175                                    0.0f, mesh, i);
     176
     177      // draw vertex normals if needed
     178      if( this->bDrawNormals)
     179      {
     180        // get vertex normals, interpolate if necessary
     181        if( data->animationState.interpolationFraction != 0.0 &&
     182            data->animationState.currentFrame != data->animationState.nextFrame)
     183        {
     184          //interpolate vertex normals
     185          this->interpolateVertexNormals(data,
     186                                         mesh->normals[data->animationState.currentFrame],
     187                                         mesh->normals[data->animationState.nextFrame],
     188                                         data->animationState.interpolationFraction, mesh, i);
     189        }
     190      }
     191    }
     192
     193
     194    // draw all models linked to this model
     195    std::map<int, MD3Data*>::iterator it = data->sortedMap.begin();
     196    int i = 0;
     197    while( it != data->sortedMap.end())
     198    {
     199      MD3Data* child = it->second;
     200
     201      //build transformation array m from matrix, interpolate if necessary
     202
     203      MD3Tag* currFrameTag = data->boneFrames[data->animationState.currentFrame]->tags[child->parentTagIndex];
     204
     205      if( data->animationState.interpolationFraction != 0.0 &&
     206          data->animationState.currentFrame != data->animationState.nextFrame)
     207      {
     208        //we need to interpolate
     209        MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex];
     210        this->interpolateTransformation(child, currFrameTag, nextFrameTag, data->animationState.interpolationFraction, i);
     211      }
     212      else
     213      {
     214        //no interpolation needed, stay with last transformation
     215        //OpenGL matrix is in column-major order
     216        data->tmpMatrix[i][0] = currFrameTag->matrix[0][0];
     217        data->tmpMatrix[i][1] = currFrameTag->matrix[1][0];
     218        data->tmpMatrix[i][2] = currFrameTag->matrix[2][0];
     219        data->tmpMatrix[i][3] = 0.0f;
     220        data->tmpMatrix[i][4] = currFrameTag->matrix[0][1];
     221        data->tmpMatrix[i][5] = currFrameTag->matrix[1][1];
     222        data->tmpMatrix[i][6] = currFrameTag->matrix[2][1];
     223        data->tmpMatrix[i][7] = 0.0f;
     224        data->tmpMatrix[i][8] = currFrameTag->matrix[0][2];
     225        data->tmpMatrix[i][9] = currFrameTag->matrix[1][2];
     226        data->tmpMatrix[i][10]= currFrameTag->matrix[2][2];
     227        data->tmpMatrix[i][11]= 0.0f;
     228        data->tmpMatrix[i][12] = currFrameTag->position.x;
     229        data->tmpMatrix[i][13] = currFrameTag->position.y;
     230        data->tmpMatrix[i][14] = currFrameTag->position.z;
     231        data->tmpMatrix[i][15] = 1.0f;
     232      }
     233
     234      // switch to child coord system
     235
     236      // and tick child
     237      this->tick(time, child);
     238
     239      i++;
     240      it++;
     241    }
     242  }
     243
     244
     245  /**
     246   * this draws the md3 model
     247   */
     248  void MD3Model::draw() const
     249  {
     250    //draw current bone frame
     251    this->draw(this->md3Data);
     252  }
     253
     254
     255  /**
     256   * draw the md3model
     257   * @param data: the data to be drawn
     258   */
     259  void MD3Model::draw(MD3Data* data) const
     260  {
     261
     262    // draw the bones if needed
     263    if( this->bDrawBones)
     264    {
     265      // get bone frame, interpolate if necessary
     266      if( data->animationState.interpolationFraction != 0.0 &&
     267          data->animationState.currentFrame != data->animationState.nextFrame) {
     268        //interpolate bone frame
     269        this->drawBoneFrame(data->tmpBoneFrame);
     270      }
     271      else {
     272        //stick with current bone frame
     273        this->drawBoneFrame(data->boneFrames[data->animationState.currentFrame]);
     274      }
     275    }
     276
     277
     278    //draw all meshes of current frame of this model
     279    for( int i = 0;  i < data->header->meshNum; i++)
     280    {
     281      MD3Mesh* mesh = data->meshes[i];
     282      sVec3D* frame = data->tmpMesh[i];
     283
     284      if( mesh->header->textureNum > 0 && &mesh->material[0] != NULL)
     285        mesh->material[0].select();
     286
     287      this->drawMesh(mesh, frame);
     288
     289      // draw vertex normals if needed
     290      if( this->bDrawNormals)
     291      {
     292        // get vertex normals, interpolate if necessary
     293        if( data->animationState.interpolationFraction != 0.0 &&
     294            data->animationState.currentFrame != data->animationState.nextFrame)
     295        {
     296          //interpolate vertex normals
     297          this->drawVertexNormals(frame, data->tmpNormal[i]);
     298        }
     299        else {
     300          //stick with current vertex normals
     301          this->drawVertexNormals(frame, mesh->normals[data->animationState.currentFrame]);
     302        }
     303      }
     304    }
     305
     306
     307    // draw all models linked to this model
     308    int i = 0;
     309    std::map<int, MD3Data*>::iterator it = data->sortedMap.begin();
     310    while( it != data->sortedMap.end())
     311    {
     312      MD3Data* child = it->second;
     313
     314      //switch to child coord system
     315      glPushMatrix();
     316      glMultMatrixf(data->tmpMatrix[i]);
     317
     318      // and draw child
     319      this->draw(child);
     320
     321      glPopMatrix();
     322
     323      i++;
     324      it++;
     325    }
     326
     327  }
     328
     329
     330  /**
     331   * draws the mesh
     332   */
     333  void MD3Model::drawMesh(MD3Mesh* mesh, sVec3D* frame) const
     334  {
     335    Vector tmpVec1, tmpVec2;
     336
     337    glColor3f(1.0f, 1.0f, 1.0f);
     338    glBegin( GL_TRIANGLES);
     339
     340    // upload all triangles in the frame to OpenGL
     341    for( int t = 0; t < mesh->header->triangleNum; t++)
     342    {
     343      // calc normal vector
     344      tmpVec1.x = frame[mesh->triangles[t].vertexOffset[1]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
     345      tmpVec1.y = frame[mesh->triangles[t].vertexOffset[1]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
     346      tmpVec1.z = frame[mesh->triangles[t].vertexOffset[1]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
     347
     348      tmpVec2.x = frame[mesh->triangles[t].vertexOffset[2]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
     349      tmpVec2.y = frame[mesh->triangles[t].vertexOffset[2]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
     350      tmpVec2.z = frame[mesh->triangles[t].vertexOffset[2]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
     351
     352      Vector normal = tmpVec1.cross(tmpVec2);
     353      normal.normalize();
     354
     355//       PRINTF(0)("normal: %f, %f, %f\n", normal.x, normal.y, normal.z);
     356
     357      glNormal3f(normal.x, normal.y, normal.z);
     358      glTexCoord2fv( mesh->texVecs[mesh->triangles[t].vertexOffset[0]].textureCoord);
     359      glVertex3f( frame[mesh->triangles[t].vertexOffset[0]][0],
     360                  frame[mesh->triangles[t].vertexOffset[0]][2],
     361                  frame[mesh->triangles[t].vertexOffset[0]][1]);
     362
     363      glNormal3f(normal.x, normal.y, normal.z);
     364      glTexCoord2fv( mesh->texVecs[mesh->triangles[t].vertexOffset[1]].textureCoord);
     365      glVertex3f( frame[mesh->triangles[t].vertexOffset[1]][0],
     366                  frame[mesh->triangles[t].vertexOffset[1]][2],
     367                  frame[mesh->triangles[t].vertexOffset[1]][1]);
     368
     369      glNormal3f(normal.x, normal.y, normal.z);
     370      glTexCoord2fv( mesh->texVecs[mesh->triangles[t].vertexOffset[2]].textureCoord);
     371      glVertex3f( frame[mesh->triangles[t].vertexOffset[2]][0],
     372                  frame[mesh->triangles[t].vertexOffset[2]][2],
     373                  frame[mesh->triangles[t].vertexOffset[2]][1]);
     374    }
     375    glEnd();
     376  }
     377
     378
     379  /**
     380   *  drawo vertex normals
     381   */
     382  void MD3Model::drawVertexNormals(sVec3D* frame, MD3Normal* normals) const
    36383  {}
    37384
    38385
     386  /**
     387   * draw bone frame
     388   */
     389  void MD3Model::drawBoneFrame(MD3BoneFrame* frame) const
     390  {
     391    float x1 = frame->mins.x;
     392    float y1 = frame->mins.y;
     393    float z1 = frame->mins.z;
     394    float x2 = frame->maxs.x;
     395    float y2 = frame->maxs.y;
     396    float z2 = frame->maxs.z;
     397
     398    glPushAttrib(GL_TEXTURE_2D);
     399    glPushAttrib(GL_LIGHTING);
     400
     401    glColor3f(1.0f,0.0f,0.0f);
     402    glPointSize(6.0f);
     403
     404    glBegin(GL_POINTS);
     405    glVertex3f(frame->position.x, frame->position.y, frame->position.z);
     406    glEnd();
     407    glPointSize(1.0f);
     408
     409    glColor3f(0.0f,1.0f,0.0f);
     410    glBegin(GL_LINE_LOOP);
     411    glVertex3f(x1,y1,z1);
     412    glVertex3f(x1,y1,z2);
     413    glVertex3f(x1,y2,z2);
     414    glVertex3f(x1,y2,z1);
     415    glEnd();
     416
     417    glBegin(GL_LINE_LOOP);
     418    glVertex3f(x2,y2,z2);
     419    glVertex3f(x2,y1,z2);
     420    glVertex3f(x2,y1,z1);
     421    glVertex3f(x2,y2,z1);
     422    glEnd();
     423
     424    glBegin(GL_LINES);
     425    glVertex3f(x1,y1,z1);
     426    glVertex3f(x2,y1,z1);
     427
     428    glVertex3f(x1,y1,z2);
     429    glVertex3f(x2,y1,z2);
     430
     431    glVertex3f(x1,y2,z2);
     432    glVertex3f(x2,y2,z2);
     433
     434    glVertex3f(x1,y2,z1);
     435    glVertex3f(x2,y2,z1);
     436    glEnd();
     437
     438     glPopAttrib();
     439     glPopAttrib();
     440  }
     441
     442
     443  /**
     444   *  interpolate bone frame
     445   * @param currBoneFrame Start bone frame.
     446   * @param nextBoneFrame End bone frame.
     447   * @param frac Interpolation fraction, in [0,1].
     448   */
     449  MD3BoneFrame* MD3Model::interpolateBoneFrame(MD3Data* data, MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac)
     450  {
     451    data->tmpBoneFrame->mins.x      = (1.0f - frac) * currBoneFrame->mins.x       + frac * nextBoneFrame->mins.x;
     452    data->tmpBoneFrame->maxs.x      = (1.0f - frac) * currBoneFrame->maxs.x       + frac * nextBoneFrame->maxs.x;
     453    data->tmpBoneFrame->position.x  = (1.0f - frac) * currBoneFrame->position.x   + frac * nextBoneFrame->position.x;
     454    data->tmpBoneFrame->mins.y      = (1.0f - frac) * currBoneFrame->mins.y       + frac * nextBoneFrame->mins.y;
     455    data->tmpBoneFrame->maxs.y      = (1.0f - frac) * currBoneFrame->maxs.y       + frac * nextBoneFrame->maxs.y;
     456    data->tmpBoneFrame->position.y  = (1.0f - frac) * currBoneFrame->position.y   + frac * nextBoneFrame->position.y;
     457    data->tmpBoneFrame->mins.z      = (1.0f - frac) * currBoneFrame->mins.z       + frac * nextBoneFrame->mins.z;
     458    data->tmpBoneFrame->maxs.z      = (1.0f - frac) * currBoneFrame->maxs.z       + frac * nextBoneFrame->maxs.z;
     459    data->tmpBoneFrame->position.z  = (1.0f - frac) * currBoneFrame->position.z   + frac * nextBoneFrame->position.z;
     460
     461    return data->tmpBoneFrame;
     462  }
     463
     464
     465
     466  /**
     467   * interpolate mesh frame
     468   */
     469  sVec3D* MD3Model::interpolateMeshFrame(MD3Data* data, sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i)
     470  {
     471    int vertexNum = mesh->header->vertexNum;
     472
     473    if( /*frac == 0.0f*/ true)
     474    {
     475      // just copy the vertices
     476      for( int t = 0; t < vertexNum; t++)
     477      {
     478        data->tmpMesh[i][t][0]  = currMeshFrame[t][0];
     479        data->tmpMesh[i][t][1]  = currMeshFrame[t][1];
     480        data->tmpMesh[i][t][2]  = currMeshFrame[t][2];
     481      }
     482    }
     483    else
     484    {
     485      // calc interpolated vertices
     486      for( int t = 0; t < vertexNum; t++)
     487      {
     488        data->tmpMesh[i][t][0]  = (1.0f - frac)   * currMeshFrame[t][0]  + frac * nextMeshFrame[t][0];
     489        data->tmpMesh[i][t][1]  = (1.0f - frac)   * currMeshFrame[t][1]  + frac * nextMeshFrame[t][1];
     490        data->tmpMesh[i][t][2]  = (1.0f - frac)   * currMeshFrame[t][2]  + frac * nextMeshFrame[t][2];
     491      }
     492    }
     493
     494    return data->tmpMesh[i];
     495  }
     496
     497
     498  /**
     499   * interpolate vertex normal
     500   */
     501  MD3Normal* MD3Model::interpolateVertexNormals(MD3Data* data, MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i)
     502  {
     503    for( int j = 0; j < mesh->header->vertexNum; j++)
     504    {
     505      data->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]);
     506      data->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]);
     507    }
     508
     509    return data->tmpNormal[i];
     510  }
     511
     512
     513  /**
     514   * interpolate transformation
     515   */
     516  float* MD3Model::interpolateTransformation(MD3Data* data, MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i)
     517  {
     518    // interpolate position
     519    Vector interpolatedPosition = currFrameTag->position * (1.0f - frac) + nextFrameTag->position * frac;
     520
     521
     522    // interpolate rotation matrix
     523    float  currRot[4][4];
     524    float  nextRot[4][4];
     525    float  interpolatedMatrix[4][4];
     526
     527    Quaternion currQuat(currFrameTag->matrix); currQuat.matrix(currRot);
     528    Quaternion nextQuat(nextFrameTag->matrix); nextQuat.matrix(nextRot);
     529
     530    Quaternion interpolatedQuat = Quaternion::quatSlerp(currQuat, nextQuat, frac); interpolatedQuat.matrix(interpolatedMatrix);
     531
     532    // quaternion code is column based, so use transposed matrix when spitting out to gl
     533    data->tmpMatrix[i][0] = interpolatedMatrix[0][0];
     534    data->tmpMatrix[i][4] = interpolatedMatrix[1][0];
     535    data->tmpMatrix[i][8] = interpolatedMatrix[2][0];
     536    data->tmpMatrix[i][12] = interpolatedPosition.x;
     537    data->tmpMatrix[i][1] = interpolatedMatrix[0][1];
     538    data->tmpMatrix[i][5] = interpolatedMatrix[1][1];
     539    data->tmpMatrix[i][9] = interpolatedMatrix[2][1];
     540    data->tmpMatrix[i][13] = interpolatedPosition.y;
     541    data->tmpMatrix[i][2] = interpolatedMatrix[0][2];
     542    data->tmpMatrix[i][6] = interpolatedMatrix[1][2];
     543    data->tmpMatrix[i][10]= interpolatedMatrix[2][2];
     544    data->tmpMatrix[i][14] = interpolatedPosition.z;
     545    data->tmpMatrix[i][3] = 0.0f;
     546    data->tmpMatrix[i][7] = 0.0f;
     547    data->tmpMatrix[i][11]= 0.0f;
     548    data->tmpMatrix[i][15] = 1.0f;
     549
     550    return data->tmpMatrix[i];
     551
     552  }
     553
     554
     555
     556  /**
     557   * visit the model
     558   */
     559  void MD3Model::visit(MD3Data* data, float time)
     560  {
     561    if ( (data->filename.find("lower") == std::string::npos &&
     562          (data->animation->type == LEGS || data->animation->type == BOTH)) // this is the LEGS model and the animation is applicable
     563          ||
     564          (data->filename.find("upper") == std::string::npos &&
     565          (data->animation->type == TORSO || data->animation->type == BOTH)) // this is the TORSO model and the animation is applicable
     566          ||
     567          data->animation->type == ALL // the animation is allways applicable
     568       )
     569      this->doOp(data, time);
     570
     571    // visit children
     572//     std::map<int, MD3Data*>::iterator it = data->sortedMap.begin();
     573//     while( it != data->sortedMap.end())
     574//     {
     575//       this->visit(it->second);
     576//       it++;
     577//     }
     578  }
     579
     580
     581  /**
     582   * Create a new visitor to apply an animation operation (NEXT, REWIND, ...)
     583   * to a MD3 model. The operation is executed in the context of the specified
     584   * animation.
     585   *
     586   * @param anim The animation that provides the context for the operation.
     587   * @param op The operation to apply.
     588   * @param interpolate Should interpolation be done?
     589   */
     590  void MD3Model::interpolate(MD3Data* data, MD3Animation* anim, int op, bool bInterpolate)
     591  {
     592     data->animation = anim;
     593     if( op == MD3_ANIM_NEXT || op == MD3_ANIM_PREVIOUS || op == MD3_ANIM_REWIND)
     594      data->op = op;
     595
     596     data->bInterpolate = bInterpolate;
     597  }
     598
     599
     600  /**
     601   * calc next frame number
     602   */
     603  int MD3Model::next(MD3Data* data, int nr)
     604  {
     605    if( nr < (data->upperBound - 1))
     606      return nr + 1;
     607    else
     608    { //rewind needed
     609      if( data->animation->numFrames < 0)
     610        return data->animation->first;
     611      else {
     612        nr = (data->animation->numLoopFrames != 0)?(data->animation->numFrames - data->animation->numLoopFrames):0;
     613        return data->animation->first + nr;
     614      }
     615    }
     616  }
     617
     618
     619  /**
     620   * calc prev frame number
     621   */
     622  int MD3Model::prev(MD3Data* data, int nr)
     623  {
     624    if( nr == data->animation->first)
     625      return data->upperBound - 1;
     626    else
     627      return nr - 1;
     628  }
     629
     630
     631  /**
     632   * apply the specified operation to the animation state data members of the model
     633   * taking the specified animation into account
     634   *
     635   * @param data: the data of the model
     636   */
     637  void MD3Model::doOp(MD3Data* data, float time)
     638  {
     639    // animation to be applied could have illegal data with respect to this model,
     640    // ignore anim in this case
     641
     642    if( data->animation->first >= data->animation->numFrames || data->animation->first < 0)
     643    {
     644      PRINTF(0)("MD3: this animation type seems to be invalid, no animation calculated\n");
     645      return;
     646    }
     647
     648
     649    //calc upper bound for animation frames in this model
     650    if( data->animation->numFrames < 0)
     651      data->upperBound = data->header->boneFrameNum; //use all available frames
     652    else
     653    {
     654      if( data->header->boneFrameNum < (data->animation->first + data->animation->numFrames))
     655        data->upperBound = data->header->boneFrameNum;
     656      else
     657        data->upperBound = (data->animation->first + data->animation->numFrames);
     658    }
     659
     660
     661    switch( data->op) {
     662
     663      case MD3_ANIM_NEXT:
     664        if( data->bInterpolate)
     665        {
     666          // keyframe interpolation animation
     667          data->animationState.interpolationFraction += time * data->animation->fps;
     668
     669          if( data->animationState.interpolationFraction >= 1.0f)
     670          {
     671            data->animationState.currentFrame = data->animationState.nextFrame;
     672            data->animationState.nextFrame = next(data, data->animationState.nextFrame);
     673            data->animationState.interpolationFraction = 0.0f;
     674          }
     675        }
     676        else
     677        {
     678          // only keyframe animation
     679          this->time += time * data->animation->fps;
     680          if( this->time > 1.0f)
     681          {
     682            data->animationState.currentFrame = data->animationState.nextFrame;
     683            data->animationState.nextFrame = next(data, data->animationState.nextFrame);
     684            this->time = 0.0f;
     685          }
     686        }
     687        break;
     688
     689      case MD3_ANIM_PREVIOUS:
     690        if( data->bInterpolate)
     691        {
     692          data->animationState.interpolationFraction -= time / data->animation->fps;
     693          if( data->animationState.interpolationFraction < 0.0f)
     694          {
     695            data->animationState.nextFrame = data->animationState.currentFrame;
     696            data->animationState.currentFrame = prev(data, data->animationState.currentFrame);
     697            data->animationState.interpolationFraction = 0.8f;
     698          }
     699        }
     700        else
     701        {
     702          data->animationState.nextFrame = data->animationState.currentFrame;
     703          data->animationState.currentFrame = prev(data, data->animationState.currentFrame);
     704        }
     705        break;
     706
     707      case MD3_ANIM_REWIND:
     708        data->animationState.currentFrame = data->animation->first;
     709        data->animationState.nextFrame = next(data, data->animationState.currentFrame);
     710        data->animationState.interpolationFraction = 0.0f;
     711        break;
     712    }
     713
     714  }
     715
     716
    39717}
  • trunk/src/lib/graphics/importer/md3/md3_model.h

    r8490 r8724  
    1313
    1414
     15#define FRACTION 0.34f
     16
     17
    1518namespace md3
    1619{
     
    1821
    1922class MD3Data;
     23class MD3BoneFrame;
     24class MD3Mesh;
     25class MD3Tag;
     26class MD3AnimationCfg;
     27class MD3Animation;
     28
     29struct MD3Normal;
     30
     31
     32typedef enum MD3FrameHandling {
     33  MD3_ANIM_NEXT = 0,          //!< swith to the next frame
     34  MD3_ANIM_PREVIOUS,          //!< swith to the previous frame
     35  MD3_ANIM_REWIND             //!< rewind the animation
     36};
     37
    2038
    2139class MD3Model : public InteractiveModel
     
    2644    ~MD3Model();
    2745
    28     virtual void tick(float dt) {}
    2946    virtual void setAnimation(int animNum, int playbackMode = 0) {}
     47    virtual int getAnimation() { return 0;}
     48
     49    virtual void tick(float dt);
     50    virtual void draw() const;
     51
     52
     53  private:
     54
     55    void autoAssemblePlayerModel(std::string filename, float scaling);
     56
     57    void draw(MD3Data* data) const;
     58    void tick(float dt, MD3Data* data);
     59
     60
     61    void drawMesh(MD3Mesh* mesh, sVec3D* frame) const;
     62    void drawVertexNormals(sVec3D* frame, MD3Normal* normals) const;
     63    void drawBoneFrame(MD3BoneFrame* frame) const;
     64
     65
     66    MD3BoneFrame* interpolateBoneFrame(MD3Data* data, MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac);
     67    sVec3D* interpolateMeshFrame(MD3Data* data, sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i);
     68    MD3Normal* interpolateVertexNormals(MD3Data* data, MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i);
     69    float* interpolateTransformation(MD3Data* data, MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i);
     70
     71
     72    void interpolate(MD3Data* data, MD3Animation* anim, int op, bool bInterpolate);
     73
     74    void visit(MD3Data* data, float time);
     75    int next(MD3Data* data, int nr);
     76    int prev(MD3Data* data, int nr);
     77    void doOp(MD3Data* data, float time);
     78
    3079
    3180  private:
    3281    MD3Data*            md3Data;           //!< reference to the md3 model data
     82
     83    bool                bDrawBones;        //!< draws the bone frames too
     84    bool                bDrawNormals;      //!< draw the normals
     85
     86    MD3AnimationCfg*    config;            //!< the config file parsed
     87
     88    float               time;
     89
    3390};
     91
    3492
    3593}
  • trunk/src/lib/math/quaternion.cc

    r7348 r8724  
    133133
    134134
     135
    135136/**
    136137 * @brief Slerps this QUaternion performs a smooth move.
     
    298299}
    299300
     301
     302/**
     303 * Creates a quaternion from a 3x3 rotation matrix.
     304 * @param mat The 3x3 source rotation matrix.
     305 * @return The equivalent 4 float quaternion.
     306 */
     307Quaternion::Quaternion(float mat[3][3])
     308{
     309  int   NXT[] = {1, 2, 0};
     310  float q[4];
     311
     312  // check the diagonal
     313  float tr = mat[0][0] + mat[1][1] + mat[2][2];
     314  if( tr > 0.0f) {
     315    float s = (float)sqrtf(tr + 1.0f);
     316    this->w = s * 0.5f;
     317    s = 0.5f / s;
     318    this->v.x = (mat[1][2] - mat[2][1]) * s;
     319    this->v.y = (mat[2][0] - mat[0][2]) * s;
     320    this->v.z = (mat[0][1] - mat[1][0]) * s;
     321  }
     322  else
     323  {
     324    // diagonal is negative
     325    // get biggest diagonal element
     326    int i = 0;
     327    if (mat[1][1] > mat[0][0]) i = 1;
     328    if (mat[2][2] > mat[i][i]) i = 2;
     329    //setup index sequence
     330    int j = NXT[i];
     331    int k = NXT[j];
     332
     333    float s = (float)sqrtf((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0f);
     334
     335    q[i] = s * 0.5f;
     336
     337    if (s != 0.0f) s = 0.5f / s;
     338
     339    q[j] = (mat[i][j] + mat[j][i]) * s;
     340    q[k] = (mat[i][k] + mat[k][i]) * s;
     341    q[3] = (mat[j][k] - mat[k][j]) * s;
     342
     343    this->v.x = q[0];
     344    this->v.y = q[1];
     345    this->v.z = q[2];
     346    this->w   = q[3];
     347  }
     348}
     349
    300350/**
    301351 * @brief outputs some nice formated debug information about this quaternion
     
    314364  PRINT(0)("angle = %f, axis: ax=%f, ay=%f, az=%f\n", this->getSpacialAxisAngle(), axis.x, axis.y, axis.z );
    315365}
     366
     367
     368
     369
     370
     371
  • trunk/src/lib/math/quaternion.h

    r7348 r8724  
    4242  inline Quaternion (const Vector& v, float f) { this->w = f; this->v = v; }
    4343  Quaternion (float m[4][4]);
     44  Quaternion (float m[3][3]);
    4445  /** turns a rotation along an axis into a Quaternion @param angle: the amount of radians to rotate @param axis: the axis to rotate around */
    4546  inline Quaternion (float angle, const Vector& axis) { w = cos(angle/2.0); v = axis * sin(angle/2.0); }
     
    118119
    119120
     121
    120122#endif /* __QUATERNION_H_ */
    121123
  • trunk/src/lib/util/Makefile.am

    r8367 r8724  
    66libORXlibutil_a_SOURCES = \
    77                substring.cc \
     8                tokenizer.cc \
    89                color.cc \
    910                helper_functions.cc \
     
    2829                timer.cc
    2930
     31
    3032noinst_HEADERS = \
    3133                substring.h \
     34                tokenizer.h \
    3235                multi_type.h \
    3336                color.h \
  • trunk/src/lib/util/loading/resource_manager.cc

    r8490 r8724  
    2828#include "primitive_model.h"
    2929#include "md2/md2Model.h"
     30#include "md3/md3_data.h"
     31#include "md3/md3_animation_cfg.h"
    3032#endif /* NO_MODEL */
    3133#ifndef NO_TEXTURES
     
    201203  else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md2", 4))
    202204    tmpType = MD2;
     205  else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md3", 4))
     206    tmpType = MD3;
     207  else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".cfg", 4))
     208    tmpType = MD3_CONFIG;
    203209  else if (!strcasecmp(fileName.c_str(), "cube") ||
    204210            !strcasecmp(fileName.c_str(), "sphere") ||
     
    400406      }
    401407      break;
     408    case MD3:
     409      if(File(fullName).isFile())
     410      {
     411        tmpResource->param[0] = param0;
     412        tmpResource->param[1] = param1;
     413        tmpResource->pointer = new md3::MD3Data(fullName, tmpResource->param[0].getCString(), tmpResource->param[1].getFloat());
     414      }
     415      break;
     416    case MD3_CONFIG:
     417      if(File(fullName).isFile())
     418      {
     419        tmpResource->param[0] = param0;
     420        tmpResource->param[1] = param1;
     421        tmpResource->pointer = new md3::MD3AnimationCfg(fullName);
     422      }
     423      break;
    402424#endif /* NO_MODEL */
    403425#ifndef NO_TEXT
     
    624646            match = true;
    625647          break;
     648        case MD3:
     649          if (param0 == MT_NULL && ((*resource)->param[0] == "") && param1 == MT_NULL && ((*resource)->param[0] == 1.0f))
     650            match = true;
     651          else if ((*resource)->param[0] == ((MultiType)param0).getString() && (*resource)->param[1] == ((MultiType)param1).getFloat())
     652            match = true;
     653          break;
     654        case MD3_CONFIG:
     655          if (param0 == MT_NULL && ((*resource)->param[0] == ""))
     656            match = true;
     657          else if ((*resource)->param[0] == ((MultiType)param0).getString())
     658            match = true;
     659          break;
     660
    626661#endif /* NO_MODEL */
    627662#ifndef NO_TEXT
     
    863898    "PrimitiveModel",
    864899    "MD2-Data",
     900    "MD3-Data",
     901    "MD3-Config"
    865902#endif
    866903#ifndef NO_TEXT
  • trunk/src/lib/util/loading/resource_manager.h

    r8330 r8724  
    3333  PRIM,                 //!< loading primitive model
    3434  MD2,                  //!< loading md2-file
     35  MD3,                  //!< loading md3-file
     36  MD3_CONFIG,           //!< the md3 config file
    3537#endif /* NO_MODEL */
    3638#ifndef NO_TEXT
  • trunk/src/story_entities/game_world.cc

    r8717 r8724  
    305305    this->tick ();
    306306
     307   
     308    /* update the state */
     309    this->update ();
     310
     311   
    307312    /* collision detection */
    308313    this->collisionDetection ();
     
    310315    this->collisionReaction ();
    311316
     317    /* check the game rules */
     318    this->checkGameRules();
     319   
    312320    /* update the state */
    313321    this->update ();
    314 
    315     /* check the game rules */
    316     this->checkGameRules();
    317322    /* draw everything */
    318323    this->display ();
  • 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.