Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7711 in orxonox.OLD for trunk


Ignore:
Timestamp:
May 18, 2006, 11:44:21 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the cd branche back to trunk

Location:
trunk/src
Files:
33 edited

Legend:

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

    r7661 r7711  
    3939#define WARN            2
    4040#define INFO            3
    41 //#define DEBUG           4
     41#define DEBUG           4
    4242#define vDEBUG          5
    4343
     
    7878  #define DEBUG_MODULE_OBJECT_MANAGER        2
    7979  #define DEBUG_MODULE_ANIM                  2
    80   #define DEBUG_MODULE_COLLISON_DETECTION    2
     80  #define DEBUG_MODULE_COLLISION_DETECTION   2
    8181  #define DEBUG_MODULE_SPATIAL_SEPARATION    2
    8282  #define DEBUG_MODULE_GUI                   2
  • trunk/src/lib/collision_detection/bounding_sphere.cc

    r4836 r7711  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "bounding_sphere.h"
     
    2424 *  standard constructor
    2525*/
    26 BoundingSphere::BoundingSphere () 
     26BoundingSphere::BoundingSphere ()
    2727{
    28    this->setClassID(CL_BOUNDING_SPHERE, "BoundingSphere"); 
     28   this->setClassID(CL_BOUNDING_SPHERE, "BoundingSphere");
    2929}
    3030
     
    3434
    3535*/
    36 BoundingSphere::~BoundingSphere () 
     36BoundingSphere::~BoundingSphere ()
    3737{
    3838  // delete what has to be deleted here
  • trunk/src/lib/collision_detection/bounding_volume.cc

    r5120 r7711  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "bounding_volume.h"
    19 #include "vector.h"
    2019
    2120using namespace std;
     
    2726BoundingVolume::BoundingVolume ()
    2827{
    29    this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume");
    30    this->center = new Vector();
    31    this->bOrigVertices = true;
    32    this->vertices = NULL;
     28  this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume");
     29  this->modelInf = NULL;
     30  this->triangleIndexes = NULL;
     31  this->triangleIndexesLength = 0;
    3332}
    3433
     
    4039BoundingVolume::~BoundingVolume ()
    4140{
    42   // delete what has to be deleted here
    43   delete this->center;
    44 
    45   if( this->vertices && !this->bOrigVertices)
    46     delete[] this->vertices;
     41  if( this->triangleIndexes)
     42    delete[] this->triangleIndexes;
    4743}
  • trunk/src/lib/collision_detection/bounding_volume.h

    r6022 r7711  
    1111#include "model.h"
    1212
    13 class Vector;
     13
    1414template<class T> class tList;
    1515
     
    2222    virtual ~BoundingVolume();
    2323
    24     inline const Vector* getCenter() const { return this->center; }
     24    inline const Vector& getCenter() const { return this->center; }
     25    inline const modelInfo* getModelInfo() const { return this->modelInf; }
    2526
    26     const sVec3D* getVertices() const { return this->vertices; }
    2727    virtual void mergeWith(const BoundingVolume &bv) = 0;
    2828
     
    3232
    3333  public:
    34     Vector*             center;                     //!< Center point of box
     34    Vector              center;                     //!< Weighter average center point of box
     35    Vector              arithCenter;                //!< Arithmetical center of the box
    3536
    36     const sVec3D*       vertices;                   //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred
    37     int                 numOfVertices;              //!< number of vertices in the vertices buffer
    38     bool                bOrigVertices;              //!< is true if the vertices pointer points to the original model data - only important for deleting
     37    const modelInfo*    modelInf;                   //!< Reference to the model's ModelInfo
     38    const int*          triangleIndexes;            //!< Array with the triangle indexes in modelInfo
     39    int                 triangleIndexesLength;      //!< length of the indexes array
    3940};
    4041
  • trunk/src/lib/collision_detection/bv_tree.cc

    r5693 r7711  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "bv_tree.h"
     
    2525 *  standard constructor
    2626*/
    27 BVTree::BVTree () 
     27BVTree::BVTree ()
    2828{
    29    this->setClassID(CL_BV_TREE, "BVTree"); 
     29   this->setClassID(CL_BV_TREE, "BVTree");
    3030
    3131}
     
    3636
    3737*/
    38 BVTree::~BVTree () 
     38BVTree::~BVTree ()
    3939{
    4040  // delete what has to be deleted here
  • trunk/src/lib/collision_detection/bv_tree.h

    r6022 r7711  
    1818class WorldEntity;
    1919
     20//! draw mode for the bounding volume
    2021typedef enum DrawMode
    2122{
     
    3334
    3435//! A class that represents a bounding volume tree
    35 class BVTree : public BaseObject {
     36class BVTree : public BaseObject
     37{
    3638
    37  public:
    38   BVTree();
    39   virtual ~BVTree();
     39  public:
     40    BVTree();
     41    virtual ~BVTree();
    4042
    41   virtual void spawnBVTree(int depth, sVec3D *verticesList, const int length) = 0;
    42   virtual void spawnBVTree(int depth, const modelInfo& modInfo) = 0;
    43   virtual void flushTree() = 0;
     43    virtual void spawnBVTree(const modelInfo& modelInf) = 0;
     44    virtual void flushTree() = 0;
    4445
    45   virtual void collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB) = 0;
    46   virtual void collideWith(WorldEntity* entity1, WorldEntity* entity2) = 0;
     46    virtual void collideWith(WorldEntity* entity1, WorldEntity* entity2) = 0;
    4747
    48   /** @param depth: depth, @param drawMode: how to draw the Model */
    49   virtual void drawBV(int depth, int drawMode) const = 0;
    50 
    51 
    52  protected:
    53   int numberOfVertices;
    54 
    55  private:
    56 
    57 
     48    virtual void drawBV(int depth, int drawMode) const = 0;
    5849};
    5950
  • trunk/src/lib/collision_detection/bv_tree_node.cc

    r4836 r7711  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "bv_tree_node.h"
  • trunk/src/lib/collision_detection/bv_tree_node.h

    r6022 r7711  
    88#define _BV_TREE_NODE_H
    99
     10
    1011#include "base_object.h"
    1112#include "model.h"
    1213#include "vector.h"
    1314
    14 // FORWARD DECLARATION
     15
     16// forward declarations
    1517class BoundingVolume;
    1618class BVTree;
     
    1921template<class T> class tList;
    2022
     23
    2124//! A class that represents a bounding volume tree
    2225class BVTreeNode : public BaseObject {
     26
    2327
    2428 public:
     
    2630  virtual ~BVTreeNode();
    2731
    28   virtual void spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length ) = 0;
    29   virtual void spawnBVTree(const int depth, const modelInfo& modInfo) = 0;
     32  virtual const BoundingVolume* getBV() const = 0;
     33  /** returns the index of this bounding volume tree node @returns index of this index */
     34  inline const int getIndex() const { return this->treeIndex; }
    3035
    31   virtual BoundingVolume* getBV(int index) const = 0;
    32   inline const int getIndex() { return this->treeIndex; }
    33 
     36  virtual void spawnBVTree(const modelInfo& modInfo, const int* triangleIndexes, int length) = 0;
    3437  virtual void collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) = 0;
    35 
    3638  virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const = 0;
    3739
  • trunk/src/lib/collision_detection/cd_engine.cc

    r7370 r7711  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "cd_engine.h"
     
    4040{
    4141  this->setClassID(CL_CD_ENGINE, "CDEngine");
     42
     43  this->bAbordOnFirstCollision = false;
    4244}
    4345
     
    5961
    6062/**
    61  *  this is the collision checking function
    62 
    63     there are some speed improvements that can be done here. a rewrite of the list a would be appropriate to
    64     be able to enhance iteration speed.
     63 *
    6564 */
    66 //void CDEngine::checkCollisions()
    67 //{
    68 //  this->checkCollisionObjects();
    69   //this->checkCollisionGround();
    70 //}
    71 
    72 /**
    73  *  this checks the collisions with the objects
    74  */
    75 //void CDEngine::checkCollisionObjects()
    76 //{
    77 //   BVTree* tree;
    78 //   tIterator<WorldEntity>* iterator1 = entityList->getIterator();
    79 //   tIterator<WorldEntity>* iterator2 = entityList->getIterator();
    80 //   WorldEntity* entity1 = iterator1->firstElement();
    81 //   WorldEntity* entity2 = iterator2->iteratorElement(iterator1);
    82 //   PRINTF(3)("checking for collisions\n");
    83 //   while( entity1 != NULL)
    84 //   {
    85 //     if( likely(entity1 != this->terrain))
    86 //     {
    87 //       entity2 = iterator2->nextElement();
    88 //
    89 //       while( entity2 != NULL)
    90 //       {
    91 //         if( likely(entity2 != this->terrain))
    92 //         {
    93 //           PRINTF(4)("checking object %s against %s\n", entity1->getName(), entity2->getName());
    94 //           tree = entity1->getOBBTree();
    95 //           if( likely(tree != NULL) && entity2->getOBBTree() != NULL) tree->collideWith(entity1, entity2);
    96 //         }
    97 //         entity2 = iterator2->nextElement();
    98 //       }
    99 //     }
    100 //     entity1 = iterator1->nextElement();
    101 //     entity2 = iterator2->iteratorElement(iterator1);
    102 //     entity2 = iterator2->nextElement();
    103 //   }
    104 //   delete iterator1;
    105 //   delete iterator2;
    106 //}
    107 
    10865void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2)
    10966{
    11067  BVTree* tree;
    11168  ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2;
    112   PRINTF(3)("checking for collisions\n");
     69  PRINTF(5)("checking for collisions\n");
    11370
    11471  pre1 = list1.begin();
     
    12683          PRINTF(4)("checking object %s against %s\n", (*entity1)->getName(), (*entity2)->getName());
    12784          tree = (*entity1)->getOBBTree();
    128           if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL) tree->collideWith(*entity1, *entity2);
     85          if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL)
     86            tree->collideWith(*entity1, *entity2);
    12987        }
    13088      }
     
    150108
    151109/**
    152  *  this draws the bounding volume tree
    153  * @param depth until which depth to draw the tree
    154  * @param drawMode mod which states how to draw it
    155  */
    156 void CDEngine::drawBV(int depth, int drawMode) const
    157 {
    158   /* this would operate on  worldList bases, for testing purposes, we only use one OBBTree */
    159   //this->rootTree->drawBV(depth, drawMode);
    160   /// FIXME
    161 /*  tIterator<WorldEntity>* iterator = entityList->getIterator();
    162   WorldEntity* entity = iterator->firstElement();
    163   while( entity != NULL)
    164   {
    165     entity->drawBVTree(depth, drawMode);
    166     entity = iterator->nextElement();
    167   }
    168   delete iterator;*/
    169 }
    170 
    171 
    172 /**
    173110 * some debug output on the class
    174111 */
     
    189126void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
    190127{
    191   if ( this->rootTree == NULL)
    192     this->rootTree = new OBBTree();
    193   this->rootTree->spawnBVTree(depth, vertices, numVertices);
     128//   if ( this->rootTree == NULL)
     129//     this->rootTree = new OBBTree(depth, vertices, numVertices);
    194130}
    195131
     
    199135  ObjectManager::EntityList::const_iterator entity;
    200136  for (entity = drawList.begin(); entity != drawList.end(); entity++)
    201     if ((*entity)->isVisible())
    202       (*entity)->drawBVTree(3, 226);
     137    (*entity)->drawBVTree(3, 226);
    203138}
    204139
     
    208143void CDEngine::debugDraw(int depth, int drawMode)
    209144{
    210   if(this-> rootTree != NULL)
    211     this->rootTree->drawBV(depth, drawMode);
     145//   if(this-> rootTree != NULL)
     146//     this->rootTree->drawBV(depth, drawMode);
    212147}
  • trunk/src/lib/collision_detection/cd_engine.h

    r6316 r7711  
    5050
    5151  inline void setTerrain(Terrain* terrain) { this->terrain = terrain; }
    52   //  inline void setPlayer(Player* player) { this->player = player; } /* only for debug purposes \todo: delete*/
    5352
    54   void drawBV(int depth, int drawMode) const;
    55 
    56 //  void checkCollisions();
    5753  void checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2);
    5854
     
    7672 private:
    7773  int                     state;                            //!< the current state of the cd engine
     74  bool                    bAbordOnFirstCollision;           //!< abords the collision detection on first collision event => more speed but less accurate infomations
    7875  OBBTree*                rootTree;                         //!< for testing purposes a root tree
    7976
    8077  Terrain*                terrain;                          //!< this it a ref to the terrain, serving as a ground for all WE
    81 //  Player*                 player;
    8278};
    8379
  • trunk/src/lib/collision_detection/collision.cc

    r4836 r7711  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "collision.h"
     
    2424 *  standard constructor
    2525*/
    26 Collision::Collision () 
     26Collision::Collision ()
    2727{
    28    this->setClassID(CL_COLLISION, "Collision"); 
     28   this->setClassID(CL_COLLISION, "Collision");
    2929
    3030}
     
    3535
    3636*/
    37 Collision::~Collision () 
     37Collision::~Collision ()
    3838{
    3939  // delete what has to be deleted here
  • trunk/src/lib/collision_detection/obb.cc

    r6222 r7711  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "obb.h"
     
    2828{
    2929   this->setClassID(CL_OBB, "OBB");
    30    this->axis = new Vector[3];
    31    this->halfLength = new float[3];
     30   this->halfLength[0] = this->halfLength[1] = this->halfLength[2] = 0.0f;
    3231   this->bCollided = false;
    3332}
     
    4039OBB::~OBB ()
    4140{
    42   delete [] this->axis;
    43   delete [] this->halfLength;
    4441}
    4542
  • trunk/src/lib/collision_detection/obb.h

    r5039 r7711  
    2121
    2222
    23   inline Vector* getAxis () const { return this->axis; }
     23  inline Vector getAxisX () const { return this->axis[0]; }
     24  inline Vector getAxisY () const { return this->axis[1]; }
     25  inline Vector getAxisZ () const { return this->axis[2]; }
     26
    2427  inline const float* getHalfLength() const { return this->halfLength; }
    2528
     
    3134
    3235 public:
    33   Vector*          axis;                       //!< Axes of oriented box [x,y,z]
    34   float*           halfLength;                 //!< Half lengths of the box along the axis
     36  Vector           axis[3];                    //!< Axes of oriented box [x,y,z]
     37  float            halfLength[3];              //!< Half lengths of the box along the axis
    3538  float            covarianceMatrix[3][3];     //!< the covariance matrix
    3639
  • trunk/src/lib/collision_detection/obb_tree.cc

    r5684 r7711  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION
    1717
    1818#include "obb_tree.h"
     
    3131 *  standard constructor
    3232*/
    33 OBBTree::OBBTree ()
     33OBBTree::OBBTree(int depth, const modelInfo* modelInf, WorldEntity* owner)
     34  : BVTree()
    3435{
     36  this->depth = depth;
    3537  this->init();
    36 }
    37 
    38 OBBTree::OBBTree(int depth, sVec3D *verticesList, const int length)
    39 {
    40   this->init();
    41   this->spawnBVTree(depth, verticesList, length);
    42 }
    43 
    44 OBBTree::OBBTree(int depth, const modelInfo& modInfo)
    45 {
    46   this->init();
    47   this->spawnBVTree(depth, modInfo);
     38  this->spawnBVTree(*modelInf);
     39  this->owner = owner;
    4840}
    4941
     
    5345{
    5446  this->setClassID(CL_OBB_TREE, "OBBTree");
    55 
    5647  this->rootNode = NULL;
    57 
    5848  this->id = 0;
    5949}
     
    6959
    7060
    71 void OBBTree::spawnBVTree(int depth, sVec3D *verticesList, const int length)
    72 {
    73   if( unlikely(this->rootNode != NULL))
    74     {
    75       PRINTF(2)("The BVTree has already been spawned, flushing and respawning again...\n");
    76       this->flushTree();
    77     }
    78   OBBTreeNode* node = new OBBTreeNode();
    79   this->rootNode = node;
    80   this->rootNode->setTreeRef(this);
    81   this->rootNode->spawnBVTree(--depth, verticesList, length);
    82 }
    83 
    84 
    85 void OBBTree::spawnBVTree(int depth, const modelInfo& modInfo)
     61/**
     62 *  this function creates a bv tree out of a modelInf structure
     63 * @param modelInf the model info of a model (modelInfo), containing vertices, triangle and normal infos
     64 */
     65void OBBTree::spawnBVTree(const modelInfo& modelInf)
    8666{
    8767  if( unlikely(this->rootNode != NULL))
     
    9070    this->flushTree();
    9171  }
    92   OBBTreeNode* node = new OBBTreeNode();
    93   this->rootNode = node;
    94   this->rootNode->setTreeRef(this);
    95   this->rootNode->spawnBVTree(--depth, modInfo);
     72  this->rootNode = new OBBTreeNode(*this, NULL, depth-1);
     73
     74  /* triangles indexes created */
     75  int* triangleIndexes = new int[modelInf.numTriangles];
     76  for( int i = 0; i < modelInf.numTriangles; ++i)
     77    triangleIndexes[i] = i;
     78
     79  this->rootNode->spawnBVTree(modelInf, triangleIndexes, modelInf.numTriangles);
    9680}
    9781
    9882
     83/**
     84 *  release the current bv tree if any
     85 */
    9986void OBBTree:: flushTree()
    10087{}
    10188
    10289
     90/**
     91 * this collides two bvtrees together. the trees are attached to pnodes Objects A and B
     92 * @param nodeA: PNode of object A
     93 * @param nodeB: Pnode of object B
     94 */
    10395void OBBTree::collideWith(WorldEntity* entity1, WorldEntity* entity2)
    10496{
     
    109101
    110102/**
    111  * this collides two bvtrees together. the trees are attached to pnodes Objects A and B
    112  * @param tree: the other tree to collide with (Object B)
    113  * @param nodeA: PNode of object A
    114  * @param nodeB: Pnode of object B
     103 *  draw bv tree
    115104 */
    116 void OBBTree::collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB)
    117 {
    118   this->rootNode->collideWith(((OBBTree*)tree)->getRootNode(), nodeA, nodeB);
    119 }
    120 
    121 
    122105void OBBTree::drawBV(int depth, int drawMode) const
    123106{
     
    129112
    130113
    131 
     114/**
     115 *  some debug output and creation function
     116 *
     117 * doesn't work at the moment
     118 */
    132119void OBBTree::debug()
    133120{
     
    153140    }
    154141
    155   this->spawnBVTree(3, vertList, length);
     142//   this->spawnBVTree(vertList, length);
    156143
    157144  PRINT(0)("=  Spawning Tree: Finished\n");
  • trunk/src/lib/collision_detection/obb_tree.h

    r6022 r7711  
    1515class OBBTreeNode;
    1616class PNode;
     17class WorldEntity;
    1718
    1819//! A class for representing an obb tree
    19 class OBBTree : public BVTree {
     20class OBBTree : public BVTree
     21{
    2022
    2123  public:
    22     OBBTree();
    23     OBBTree(int depth, sVec3D *verticesList, const int length);
    24     OBBTree(int depth, const modelInfo& modInfo);
     24    OBBTree(int depth, const modelInfo* modInfo, WorldEntity* entity);
    2525    virtual ~OBBTree();
    2626    void init();
    2727
    28     virtual void spawnBVTree(int depth, sVec3D *verticesList, const int length);
    29     virtual void spawnBVTree(int depth, const modelInfo& modInfo);
     28    virtual void spawnBVTree(const modelInfo& modelInf);
    3029    virtual void flushTree();
    3130
    32     virtual void collideWith(BVTree* tree, WorldEntity* nodeA, WorldEntity* nodeB);
    3331    virtual void collideWith(WorldEntity* entity1, WorldEntity* entity2);
    34 
    3532    virtual void drawBV(int depth, int drawMode) const;
    3633
    37     int getID() { return ++this->id;}
    38     inline OBBTreeNode* getRootNode() { return this->rootNode; }
     34    /** returns the next if for the obb tree node @return integer id number of the next node */
     35    inline const int getID() { return ++this->id;}
     36    /** returns the root node of the bounding volume tree @return reference to the root node */
     37    inline OBBTreeNode* getRootNode() const { return this->rootNode; }
     38    inline WorldEntity* getOwner() const { return this->owner; }
    3939
    4040    void debug();
     
    4242  private:
    4343    OBBTreeNode*         rootNode;                        //!< reference to the root node of the tree
    44     int                  id;
     44    int                  id;                              //!< the next id of a obb tree node
     45    int                  depth;                           //!< the depth of the tree to generate
     46    WorldEntity*         owner;                           //!< owner
    4547};
    4648
  • trunk/src/lib/collision_detection/obb_tree_node.cc

    r6617 r7711  
    1111### File Specific:
    1212   main-programmer: Patrick Boenzli
    13    co-programmer: ...
    1413*/
    1514
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
     15#define DEBUG_SPECIAL_MODULE 3/* DEBUG_MODULE_COLLISION_DETECTION*/
    1716
    1817#include "obb_tree_node.h"
    19 #include "list.h"
     18#include "obb_tree.h"
    2019#include "obb.h"
    21 #include "obb_tree.h"
     20
    2221#include "matrix.h"
    2322#include "model.h"
     
    2625
    2726#include "color.h"
    28 
     27#include "glincl.h"
     28
     29#include <list>
     30#include <vector>
    2931#include "debug.h"
    30 #include "glincl.h"
    3132
    3233
     
    3435using namespace std;
    3536
    36 OBBTree*  OBBTreeNode::obbTree = NULL;
    37 
    38 float**  OBBTreeNode::coMat = NULL;
    39 float**  OBBTreeNode::eigvMat = NULL;
    40 float*   OBBTreeNode::eigvlMat = NULL;
    41 int*     OBBTreeNode::rotCount = NULL;
     37
    4238GLUquadricObj* OBBTreeNode_sphereObj = NULL;
     39
    4340
    4441/**
    4542 *  standard constructor
     43 * @param tree: reference to the obb tree
     44 * @param depth: the depth of the obb tree to generate
    4645 */
    47 OBBTreeNode::OBBTreeNode ()
     46OBBTreeNode::OBBTreeNode (const OBBTree& tree, OBBTreeNode* prev, int depth)
     47    : BVTreeNode()
    4848{
    4949  this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
     50
     51  this->obbTree = &tree;
     52  this->nodePrev = prev;
     53  this->depth = depth;
     54  this->nextID = 0;
     55
    5056  this->nodeLeft = NULL;
    5157  this->nodeRight = NULL;
    5258  this->bvElement = NULL;
    5359
    54   if( OBBTreeNode::coMat == NULL)
    55   {
    56     OBBTreeNode::coMat = new float*[4];
    57     for(int i = 0; i < 4; i++)
    58       OBBTreeNode::coMat[i] = new float[4];
    59   }
    60   if( OBBTreeNode::eigvMat == NULL)
    61   {
    62     OBBTreeNode::eigvMat = new float*[4];
    63     for( int i = 0; i < 4; i++)
    64       OBBTreeNode::eigvMat[i] = new float[4];
    65   }
    66   if( OBBTreeNode::eigvlMat == NULL)
    67   {
    68     OBBTreeNode::eigvlMat = new float[4];
    69   }
    70   if( OBBTreeNode::rotCount == NULL)
    71     OBBTreeNode::rotCount = new int;
     60  this->triangleIndexList1 = NULL;
     61  this->triangleIndexList2 = NULL;
     62
     63  this->modelInf = NULL;
     64  this->triangleIndexes = NULL;
    7265
    7366  if( OBBTreeNode_sphereObj == NULL)
    7467    OBBTreeNode_sphereObj = gluNewQuadric();
     68
     69  this->owner = NULL;
     70
     71  /* debug ids */
     72  if( this->nodePrev)
     73    this->treeIndex = 100 * this->depth + this->nodePrev->getID();
     74  else
     75    this->treeIndex = 0;
    7576}
    7677
     
    8283{
    8384  if( this->nodeLeft)
    84   {
    8585    delete this->nodeLeft;
    86     this->nodeLeft = NULL;
    87   }
    8886  if( this->nodeRight)
    89   {
    9087    delete this->nodeRight;
    91     this->nodeRight = NULL;
    92   }
     88
    9389  if( this->bvElement)
    9490    delete this->bvElement;
    95   this->bvElement = NULL;
     91
     92//   if( this->triangleIndexList1 != NULL)
     93//     delete [] this->triangleIndexList1;
     94//   if( this->triangleIndexList2 != NULL)
     95//     delete [] this->triangleIndexList2;
    9696}
    9797
     
    105105 * on the triangle informations (triangle soup not polygon soup)
    106106 */
    107 void OBBTreeNode::spawnBVTree(const int depth, const modelInfo& modInfo)
    108 {
    109   int length = 0;
    110   sVec3D* verticesList;
    111 
    112   PRINT(3)("\n");
    113   this->treeIndex = this->obbTree->getID();
    114   PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);
     107void OBBTreeNode::spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, int length)
     108{
     109  PRINTF(3)("\n==============================Creating OBB Tree Node==================\n");
     110  PRINT(3)(" OBB Tree Infos: \n");
     111  PRINT(3)("\tDepth: %i \n\tTree Index: %i \n\tNumber of Triangles: %i\n", depth, this->treeIndex, length);
    115112  this->depth = depth;
    116113
    117 
    118114  this->bvElement = new OBB();
    119   this->bvElement->vertices = verticesList;
    120   this->bvElement->numOfVertices = length;
    121   PRINTF(3)("Created OBBox\n");
    122   this->calculateBoxCovariance(this->bvElement, modInfo);
    123   PRINTF(3)("Calculated attributes1\n");
    124   this->calculateBoxEigenvectors(this->bvElement, modInfo);
    125   PRINTF(3)("Calculated attributes2\n");
    126   this->calculateBoxAxis(this->bvElement,modInfo);
    127   PRINTF(3)("Calculated attributes3\n");
    128 
    129   /* if this is the first node, the vertices data are the original ones of the model itself, so dont delete them in cleanup */
    130   if( this->treeIndex == 1)
    131     this->bvElement->bOrigVertices = true;
    132 
     115  this->bvElement->modelInf = &modelInf;
     116  this->bvElement->triangleIndexes = triangleIndexes;
     117  this->bvElement->triangleIndexesLength = length;
     118
     119  // full debug output
     120
     121  //indexes debug
     122//   for( int i = 0; i < length; ++i)
     123//   {
     124//     PRINTF(2)("triangle[%i], index: %i\n", i, triangleIndexes[i]);
     125//   }
     126//   for( int i = 0; i < length; ++i)
     127//   {
     128//     PRINTF(2)("triangle[%i]\n", i);
     129//     for(int j = 0; j < 3; ++j)
     130//     {
     131//       PRINTF(2)("  vertex[%i]: %f, %f, %f\n", j,
     132//       (&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[j]])[0],
     133//       (&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[j]])[1],
     134//       (&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[j]])[2]);
     135//     }
     136//   }
     137//   PRINT(0)("\n\n\n");
     138//   for( int i = 0; i < this->bvElement->modelInf->numVertices*3; i+=3)
     139//     PRINTF(0)(  "vertex[%i]: %f, %f, %f\n", i, this->bvElement->modelInf->pVertices[i],
     140//                this->bvElement->modelInf->pVertices[i+1],
     141//                this->bvElement->modelInf->pVertices[i+2]);
     142
     143
     144
     145  /* create the bounding boxes in three steps */
     146  this->calculateBoxCovariance(*this->bvElement, modelInf, triangleIndexes, length);
     147  this->calculateBoxEigenvectors(*this->bvElement, modelInf, triangleIndexes, length);
     148//   this->calculateBoxAxis(*this->bvElement, modelInf, triangleIndexes, length);
     149//   this->calculateBoxAxis(*this->bvElement, modelInf, triangleIndexes, length);
     150  this->calculateBoxAxis(*this->bvElement, modelInf, triangleIndexes, length);
     151
     152  /* do we need to descent further in the obb tree?*/
    133153  if( likely( this->depth > 0))
    134154  {
    135     this->forkBox(this->bvElement);
    136 
    137 
    138 //     if(this->tmpLen1 > 2)
    139 //     {
    140 //       OBBTreeNode* node1 = new OBBTreeNode();
    141 //       this->nodeLeft = node1;
    142 //       this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
    143 //     }
    144 //     else
    145 //     {
    146 //       PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n");
    147 //     }
    148 //
    149 //     if( this->tmpLen2 > 2)
    150 //     {
    151 //       OBBTreeNode* node2 = new OBBTreeNode();
    152 //       this->nodeRight = node2;
    153 //       this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
    154 //     }
    155 //     else
    156 //     {
    157 //       PRINTF(3)("Abording tree walk: less than 3 vertices left\n");
    158 //     }
    159 
    160   }
    161 }
     155    this->forkBox(*this->bvElement);
     156
     157    if( this->triangleIndexLength1 >= 3)
     158    {
     159      this->nodeLeft = new OBBTreeNode(*this->obbTree, this, depth - 1);
     160      this->nodeLeft->spawnBVTree(modelInf, this->triangleIndexList1, this->triangleIndexLength1);
     161    }
     162    if( this->triangleIndexLength2 >= 3)
     163    {
     164      this->nodeRight = new OBBTreeNode(*this->obbTree, this, depth - 1);
     165      this->nodeRight->spawnBVTree(modelInf, this->triangleIndexList2, this->triangleIndexLength2);
     166    }
     167  }
     168}
     169
    162170
    163171
    164172/**
    165  *  creates a new BVTree or BVTree partition
    166  * @param depth: how much more depth-steps to go: if == 1 don't go any deeper!
    167  * @param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle
    168  *
    169  * this function creates an Bounding Volume tree from a vertices soup (no triangle data)
     173 *  calculate the box covariance matrix
     174 * @param box: reference to the box
     175 * @param modelInf: the model info structure of the model
     176 * @param tirangleIndexes: an array with the indexes of the triangles inside this
     177 * @param length: the length of the indexes array
    170178 */
    171 void OBBTreeNode::spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length)
    172 {
    173   PRINT(3)("\n");
    174   this->treeIndex = this->obbTree->getID();
    175   PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);
    176   this->depth = depth;
    177 
    178 
    179   this->bvElement = new OBB();
    180   this->bvElement->vertices = verticesList;
    181   this->bvElement->numOfVertices = length;
    182   PRINTF(3)("Created OBBox\n");
    183   this->calculateBoxCovariance(this->bvElement, verticesList, length);
    184   PRINTF(3)("Calculated attributes1\n");
    185   this->calculateBoxEigenvectors(this->bvElement, verticesList, length);
    186   PRINTF(3)("Calculated attributes2\n");
    187   this->calculateBoxAxis(this->bvElement, verticesList, length);
    188   PRINTF(3)("Calculated attributes3\n");
    189 
    190   /* if this is the first node, the vertices data are the original ones of the model itself, so dont delete them in cleanup */
    191   if( this->treeIndex == 1)
    192     this->bvElement->bOrigVertices = true;
    193 
    194   if( likely( this->depth > 0))
    195   {
    196     this->forkBox(this->bvElement);
    197 
    198 
    199     if(this->tmpLen1 > 2)
    200     {
    201       OBBTreeNode* node1 = new OBBTreeNode();
    202       this->nodeLeft = node1;
    203       this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
    204     }
    205     else
    206     {
    207       PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n");
    208     }
    209 
    210     if( this->tmpLen2 > 2)
    211     {
    212       OBBTreeNode* node2 = new OBBTreeNode();
    213       this->nodeRight = node2;
    214       this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
    215     }
    216     else
    217     {
    218       PRINTF(3)("Abording tree walk: less than 3 vertices left\n");
    219     }
    220   }
    221 }
    222 
    223 
    224 void OBBTreeNode::calculateBoxCovariance(OBB* box, const modelInfo& modInfo)
    225 {}
    226 
    227 
    228 void OBBTreeNode::calculateBoxCovariance(OBB* box, const sVec3D* verticesList, unsigned int length)
     179void OBBTreeNode::calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, int length)
    229180{
    230181  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
     
    235186  Vector    t1, t2;                                  //!< temporary values
    236187  float     covariance[3][3] = {0,0,0, 0,0,0, 0,0,0};//!< the covariance matrix
    237   int       mode = 0;                                //!< mode = 0: vertex soup, no connections, mode = 1: 3 following verteces build a triangle
    238 
    239   this->numOfVertices = length;
    240   this->vertices = verticesList;
    241 
    242 
    243   if( likely(mode == 0))
    244   {
    245     /* fist compute all the convex hull face/facelets and centroids */
    246     for( int i = 0; i+3 < length ; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    247     {
    248       p = verticesList[i];
    249       q = verticesList[i + 1];
    250       r = verticesList[i + 2];
    251 
    252       t1 = p - q; t2 = p - r;
    253 
    254       /* finding the facelet surface via cross-product */
    255       facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
    256       /* update the entire convex hull surface */
    257       face += facelet[i];
    258 
    259       /* calculate the cetroid of the hull triangles */
    260       centroid[i] = (p + q + r) * 1/3;
    261       /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
    262       center += centroid[i] * facelet[i];
    263     }
    264     /* take the average of the centroid sum */
    265     center /= face;
    266     PRINTF(3)("-- Calculated Center\n");
    267 
    268 
    269     /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
    270     for( int j = 0; j < 3; ++j)
    271     {
    272       for( int k = 0; k < 3; ++k)
     188  const float*   tmpVec = NULL;                           //!< a temp saving place for sVec3Ds
     189
     190  /* fist compute all the convex hull face/facelets and centroids */
     191  for( int i = 0; i < length ; ++i)
     192  {
     193    p = &modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[0]];
     194    q = &modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[1]];
     195    r = &modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[2]];
     196
     197    /* finding the facelet surface via cross-product */
     198    t1 = p - q;
     199    t2 = p - r;
     200    facelet[i] = 0.5f * /*fabs*/( t1.cross(t2).len() );
     201    /* update the entire convex hull surface */
     202    face += facelet[i];
     203
     204    /* calculate the cetroid of the hull triangles */
     205    centroid[i] = (p + q + r) / 3.0f;
     206    /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
     207    center += centroid[i] * facelet[i];
     208    /* the arithmetical center */
     209  }
     210  /* take the average of the centroid sum */
     211  center /= face;
     212
     213
     214  /* now calculate the covariance matrix - if not written in three for-loops,
     215     it would compute faster: minor */
     216  for( int j = 0; j < 3; ++j)
     217  {
     218    for( int k = 0; k < 3; ++k)
     219    {
     220      for( int i = 0; i < length; ++i)
    273221      {
    274         for( int i = 0; i + 3 < length; i+=3)
    275         {
    276           p = verticesList[i];
    277           q = verticesList[i + 1];
    278           r = verticesList[i + 2];
    279 
    280           covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] +
    281               q[j] * q[k] + r[j] * r[k]) - center[j] * center[k];
    282         }
     222        p = (&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[0]]);
     223        q = (&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[1]]);
     224        r = (&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[i]].indexToVertices[2]]);
     225
     226        covariance[j][k] = facelet[i] * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] +
     227                           q[j] * q[k] + r[j] * r[k]);
    283228      }
    284     }
    285     PRINTF(3)("-- Calculated Covariance\n");
    286   }
    287   else if( mode == 1)
    288   {
    289     for( int i = 0; i + 3 < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    290     {
    291       p = verticesList[i];
    292       q = verticesList[i + 1];
    293       r = verticesList[i + 2];
    294 
    295       centroid[i] = (p + q + r) / 3.0f;
    296       center += centroid[i];
    297     }
    298     center /= length;
    299 
    300     for( int j = 0; j < 3; ++j)
    301     {
    302       for( int k = 0; k < 3; ++k)
    303       {
    304         for( int i = 0; i + 3 < length; i+=3)
    305         {
    306           p = verticesList[i];
    307           q = verticesList[i +1];
    308           r = verticesList[i + 2];
    309 
    310           covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
    311         }
    312         covariance[j][k] /= (3.0f * length);
    313       }
    314     }
    315     PRINTF(3)("-- Calculated Covariance\n");
    316   }
    317   else if( mode == 2)
    318   {
    319     /* fist compute all the convex hull face/facelets and centroids */
    320     for(int i = 0; i + 3 < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    321     {
    322       p = verticesList[i];
    323       q = verticesList[i + 1];
    324       r = verticesList[i + 2];
    325 
    326       t1 = p - q; t2 = p - r;
    327 
    328       /* finding the facelet surface via cross-product */
    329       facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
    330       /* update the entire convex hull surface */
    331       face += facelet[i];
    332 
    333       /* calculate the cetroid of the hull triangles */
    334       centroid[i] = (p + q + r) * 1/3;
    335       /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
    336       center += centroid[i] * facelet[i];
    337     }
    338     /* take the average of the centroid sum */
    339     center /= face;
    340     PRINTF(3)("-- Calculated Center\n");
    341 
    342     for( int j = 0; j < 3; ++j)
    343     {
    344       for( int k = 0; k < 3; ++k)
    345       {
    346         for( int i = 0; i + 3 < length; i+=3)
    347         {
    348           p = verticesList[i];
    349           q = verticesList[i +1];
    350           r = verticesList[i + 2];
    351 
    352           covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
    353         }
    354         covariance[j][k] /= (3.0f * length);
    355       }
    356     }
    357     PRINTF(3)("-- Calculated Covariance\n");
    358   }
    359   else
    360   {
    361     for( int i = 0; i < length; ++i)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    362     {
    363       center += verticesList[i];
    364     }
    365     center /= length;
    366 
    367     for( int j = 0; j < 3; ++j)
    368     {
    369       for( int k = 0; k < 3; ++k)
    370       {
    371         for( int i = 0; i + 3 < length; i+=3)
    372         {
    373           p = verticesList[i];
    374           q = verticesList[i +1];
    375           r = verticesList[i + 2];
    376 
    377           covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
    378         }
    379         covariance[j][k] /= (3.0f * length);
    380       }
    381     }
    382     PRINTF(3)("-- Calculated Covariance\n");
    383   }
    384 
    385   PRINTF(3)("\nVertex Data:\n");
    386   for(int i = 0; i < length; i++)
    387   {
    388     PRINTF(3)("vertex %i: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]);
    389   }
    390 
    391 
    392   PRINTF(3)("\nCovariance Matrix:\n");
     229      covariance[j][k] = covariance[j][k] / (12.0f * face) - center[j] * center[k];
     230    }
     231  }
     232  for( int i = 0; i < 3; ++i)
     233  {
     234    box.covarianceMatrix[i][0] = covariance[i][0];
     235    box.covarianceMatrix[i][1] = covariance[i][1];
     236    box.covarianceMatrix[i][2] = covariance[i][2];
     237  }
     238  box.center = center;
     239
     240  /* debug output section*/
     241  PRINTF(3)("\nOBB Covariance Matrix:\n");
    393242  for(int j = 0; j < 3; ++j)
    394243  {
    395     PRINT(3)(" |");
     244    PRINT(3)("\t\t");
    396245    for(int k = 0; k < 3; ++k)
    397246    {
    398       PRINT(3)(" \b%f ", covariance[j][k]);
    399     }
    400     PRINT(3)(" |\n");
    401   }
    402 
    403   PRINTF(3)("center: %f, %f, %f\n", center.x, center.y, center.z);
    404 
    405 
    406   for(int i = 0; i < 3; ++i)
    407   {
    408     box->covarianceMatrix[i][0] = covariance[i][0];
    409     box->covarianceMatrix[i][1] = covariance[i][1];
    410     box->covarianceMatrix[i][2] = covariance[i][2];
    411   }
    412   *box->center = center;
    413   PRINTF(3)("-- Written Result to obb\n");
    414 }
    415 
    416 
    417 void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const modelInfo& modInfo)
    418 {}
    419 
    420 void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const sVec3D* verticesList, unsigned int length)
    421 {
    422 
    423   /* now getting spanning vectors of the sub-space:
     247      PRINT(3)("%11.4f\t", covariance[j][k]);
     248    }
     249    PRINT(3)("\n");
     250  }
     251  PRINTF(3)("\nWeighteed OBB Center:\n\t\t%11.4f\t %11.4f\t %11.4f\n", center.x, center.y, center.z);
     252//   PRINTF(3)("\nArithmetical OBB Center:\n\t\t%11.4f\t %11.4f\t %11.4f\n", box.arithCenter.x, box.arithCenter.y, box.arithCenter.z);
     253
     254  /* write back the covariance matrix data to the object oriented bouning box */
     255}
     256
     257
     258
     259/**
     260 *  calculate the eigenvectors for the object oriented box
     261 * @param box: reference to the box
     262 * @param modelInf: the model info structure of the model
     263 * @param tirangleIndexes: an array with the indexes of the triangles inside this
     264 * @param length: the length of the indexes array
     265 */
     266void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const modelInfo& modelInf,
     267    const int* triangleIndexes, int length)
     268{
     269
     270  Vector         axis[3];                            //!< the references to the obb axis
     271  Matrix         covMat(  box.covarianceMatrix  );   //!< covariance matrix (in the matrix dataform)
     272
     273  /*
     274  now getting spanning vectors of the sub-space:
    424275  the eigenvectors of a symmertric matrix, such as the
    425276  covarience matrix are mutually orthogonal.
     
    427278  vectors
    428279  */
    429   Vector*              axis = new Vector[3];                //!< the references to the obb axis
    430 
    431   Matrix covMat(  box->covarianceMatrix  );
     280
     281  /* calculate the axis */
    432282  covMat.getEigenVectors(axis[0], axis[1], axis[2] );
    433 
    434 
    435   /* new jacobi tests */
    436 //  JacobI(OBBTreeNode::coMat, OBBTreeNode::eigvlMat, OBBTreeNode::eigvMat, OBBTreeNode::rotCount);
    437 //  PRINTF(3)("-- Done Jacobi Decomposition\n");
    438 
    439 
    440 //   PRINTF(0)("Jacobi\n");
    441 //   for(int j = 0; j < 3; ++j)
    442 //   {
    443 //     printf(" |");
    444 //     for(int k = 0; k < 3; ++k)
    445 //     {
    446 //       printf(" \t%f ", OBBTreeNode::OBBTreeNode::eigvMat[j][k]);
    447 //     }
    448 //     printf(" |\n");
    449 //   }
    450 
    451 /*  axis[0].x = OBBTreeNode::eigvMat[0][0]; axis[0].y = OBBTreeNode::eigvMat[1][0]; axis[0].z = OBBTreeNode::eigvMat[2][0];
    452   axis[1].x = OBBTreeNode::eigvMat[0][1]; axis[1].y = OBBTreeNode::eigvMat[1][1]; axis[1].z = OBBTreeNode::eigvMat[2][1];
    453   axis[2].x = OBBTreeNode::eigvMat[0][2]; axis[2].y = OBBTreeNode::eigvMat[1][2]; axis[2].z = OBBTreeNode::eigvMat[2][2];
    454   axis[0].normalize();
    455   axis[1].normalize();
    456   axis[2].normalize();*/
    457   box->axis = axis;
    458 
    459 //   PRINTF(0)("-- Got Axis\n");
    460 //
    461 //   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0].x, box->axis[0].y, box->axis[0].z);
    462 //   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1].x, box->axis[1].y, box->axis[1].z);
    463 //   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2].x, box->axis[2].y, box->axis[2].z);
    464 }
    465 
    466 
    467 void OBBTreeNode::calculateBoxAxis(OBB* box, const modelInfo& modInfo)
    468 {
    469   this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices);
    470 }
    471 
    472 
    473 
    474 void OBBTreeNode::calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length)
    475 {
    476 
     283  box.axis[0] = axis[0];
     284  box.axis[1] = axis[1];
     285  box.axis[2] = axis[2];
     286
     287//   box.axis[0] = Vector(1,0,0);
     288//   box.axis[1] = Vector(0,1,0);
     289//   box.axis[2] = Vector(0,0,1);
     290
     291  PRINTF(3)("Eigenvectors:\n");
     292  PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z);
     293  PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z);
     294  PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z);
     295}
     296
     297
     298
     299
     300/**
     301 *  calculate the eigenvectors for the object oriented box
     302 * @param box: reference to the box
     303 * @param modelInf: the model info structure of the model
     304 * @param tirangleIndexes: an array with the indexes of the triangles inside this
     305 * @param length: the length of the indexes array
     306 */
     307void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, int length)
     308{
     309
     310  PRINTF(3)("Calculate Box Axis\n");
    477311  /* now get the axis length */
    478   Line                ax[3];                                 //!< the axis
    479   float*              halfLength = new float[3];             //!< half length of the axis
     312  float               halfLength[3];                         //!< half length of the axis
    480313  float               tmpLength;                             //!< tmp save point for the length
    481   Plane               p0(box->axis[0], *box->center);       //!< the axis planes
    482   Plane               p1(box->axis[1], *box->center);
    483   Plane               p2(box->axis[2], *box->center);
    484   float               maxLength[3];
    485   float               minLength[3];
    486 
    487 
    488   /* get a bad bounding box */
    489   halfLength[0] = -1.0f;
    490   for(int j = 0; j < length; ++j)
    491     {
    492       tmpLength = fabs(p0.distancePoint(vertices[j]));
    493       if( tmpLength > halfLength[0])
    494         halfLength[0] = tmpLength;
    495     }
    496 
    497   halfLength[1] = -1.0f;
    498   for(int j = 0; j < length; ++j)
    499     {
    500       tmpLength = fabs(p1.distancePoint(vertices[j]));
    501       if( tmpLength > halfLength[1])
    502         halfLength[1] = tmpLength;
    503     }
    504 
    505   halfLength[2] = -1.0f;
    506   for(int j = 0; j < length; ++j)
    507     {
    508       tmpLength = fabs(p2.distancePoint(vertices[j]));
    509       if( tmpLength > halfLength[2])
    510         halfLength[2] = tmpLength;
    511     }
    512 
    513 
     314  Plane               p0(box.axis[0], box.center);           //!< the axis planes
     315  Plane               p1(box.axis[1], box.center);           //!< the axis planes
     316  Plane               p2(box.axis[2], box.center);           //!< the axis planes
     317  float               maxLength[3];                          //!< maximal lenth of the axis
     318  float               minLength[3];                          //!< minimal length of the axis
     319  const float*        tmpVec;                                //!< variable taking tmp vectors
     320  float               centerOffset[3];
    514321
    515322  /* get the maximal dimensions of the body in all directions */
    516     maxLength[0] = p0.distancePoint(vertices[0]);
    517     minLength[0] = p0.distancePoint(vertices[0]);
    518    for(int j = 0; j < length; ++j)
    519    {
    520      tmpLength = p0.distancePoint(vertices[j]);
    521      if( tmpLength > maxLength[0])
    522        maxLength[0] = tmpLength;
    523      else if( tmpLength < minLength[0])
    524        minLength[0] = tmpLength;
    525    }
    526 
    527    maxLength[1] = p1.distancePoint(vertices[0]);
    528    minLength[1] = p1.distancePoint(vertices[0]);
    529    for(int j = 0; j < length; ++j)
    530    {
    531      tmpLength = p1.distancePoint(vertices[j]);
    532      if( tmpLength > maxLength[1])
    533        maxLength[1] = tmpLength;
    534      else if( tmpLength < minLength[1])
    535        minLength[1] = tmpLength;
    536    }
    537 
    538    maxLength[2] = p2.distancePoint(vertices[0]);
    539    minLength[2] = p2.distancePoint(vertices[0]);
    540    for(int j = 0; j < length; ++j)
    541    {
    542      tmpLength = p2.distancePoint(vertices[j]);
    543      if( tmpLength > maxLength[2])
    544        maxLength[2] = tmpLength;
    545      else if( tmpLength < minLength[2])
    546        minLength[2] = tmpLength;
    547    }
    548 
    549 
    550    /* calculate the real centre of the body by using the axis length */
    551    float centerOffset[3];
    552    float newHalfLength[3];
    553    for(int i = 0; i < 3; ++i)
    554      {
    555        PRINTF(3)("max: %f, min: %f \n", maxLength[i], minLength[i]);
    556        centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f;       // min length is negatie
    557        newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f;      // min length is negative
    558        *box->center +=  (box->axis[i] * centerOffset[i]);            // update the new center vector
    559        halfLength[i] = newHalfLength[i];
    560      }
    561 
    562 
    563 
    564   box->halfLength = halfLength;
    565   PRINTF(3)("-- Written Axis to obb\n");
    566   PRINTF(3)("-- Finished Calculating Attributes\n");
     323  /* for the initialisation the value just has to be inside of the polygon soup -> first vertices (rand) */
     324  for( int k = 0; k  < 3; k++)
     325  {
     326    tmpVec = (&modelInf.pVertices[modelInf.pTriangles[triangleIndexes[0]].indexToVertices[0]]);
     327    Plane* p;
     328    if( k == 0)
     329      p = &p0;
     330    else if( k == 1)
     331      p = &p1;
     332    else
     333      p = &p2;
     334    maxLength[k] = p->distancePoint(tmpVec);
     335    minLength[k] = p->distancePoint(tmpVec);
     336
     337    for( int j = 0; j < length; ++j) {
     338      for( int i = 0; i < 3; ++i) {
     339        tmpVec = &modelInf.pVertices[modelInf.pTriangles[triangleIndexes[j]].indexToVertices[i]];
     340        tmpLength = p->distancePoint(tmpVec);
     341
     342        if( tmpLength > maxLength[k])
     343          maxLength[k] = tmpLength;
     344        else if( tmpLength < minLength[k])
     345          minLength[k] = tmpLength;
     346      }
     347    }
     348  }
     349
     350
     351
     352  /* calculate the real centre of the body by using the axis length */
     353  for( int i = 0; i < 3; ++i)
     354  {
     355    if( maxLength[i] > 0.0f && minLength[i] > 0.0f)  // both axis positiv
     356      centerOffset[i] = minLength[i] + (maxLength[i] - minLength[i]) / 2.0f;
     357    else if( maxLength[i] > 0.0f && maxLength[i] < 0.0f) // positiv and negativ
     358      centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f;
     359    else //both negativ
     360     centerOffset[i] = minLength[i] + (maxLength[i] - minLength[i]) / 2.0f;
     361
     362    box.halfLength[i] = (maxLength[i] - minLength[i]) / 2.0f;
     363  }
     364
     365  box.center += (box.axis[0] * centerOffset[0]);
     366  box.center += (box.axis[1] * centerOffset[1]);
     367  box.center += (box.axis[2] * centerOffset[2]);
     368
     369
     370  PRINTF(3)("\n");
     371  PRINT(3)("\tAxis halflength x: %11.2f (max: %11.2f, \tmin: %11.2f), offset: %11.2f\n", box.halfLength[0], maxLength[0], minLength[0], centerOffset[0]);
     372  PRINT(3)("\tAxis halflength y: %11.2f (max: %11.2f, \tmin: %11.2f), offset: %11.2f\n", box.halfLength[1], maxLength[1], minLength[1], centerOffset[1] );
     373  PRINT(3)("\tAxis halflength z: %11.2f (max: %11.2f, \tmin: %11.2f), offset: %11.2f\n", box.halfLength[2], maxLength[2], minLength[2], centerOffset[2]);
    567374}
    568375
     
    570377
    571378/**
    572   \brief this separates an ob-box in the middle
    573 * @param box: the box to separate
    574 
    575   this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
     379 * this separates an ob-box in the middle
     380 * @param box: the box to separate
     381 *
     382 * this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
    576383 */
    577 void OBBTreeNode::forkBox(OBB* box)
    578 {
     384void OBBTreeNode::forkBox(OBB& box)
     385{
     386
     387  PRINTF(3)("Fork Box\n");
     388  PRINTF(4)("Calculating the longest Axis\n");
    579389  /* get the longest axis of the box */
    580   float               aLength = -1.0f;                     //!< the length of the longest axis
    581   int                 axisIndex = 0;                       //!< this is the nr of the longest axis
    582 
    583   for(int i = 0; i < 3; ++i)
    584   {
    585     if( aLength < box->halfLength[i])
    586     {
    587       aLength = box->halfLength[i];
    588       axisIndex = i;
    589     }
    590   }
    591 
    592    PRINTF(3)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
    593 
    594 
     390  float               longestAxis = -1.0f;                 //!< the length of the longest axis
     391  int                 longestAxisIndex = 0;                //!< this is the nr of the longest axis
     392
     393
     394  /* now get the longest axis of the three exiting */
     395  for( int i = 0; i < 3; ++i)
     396  {
     397    if( longestAxis < box.halfLength[i])
     398    {
     399      longestAxis = box.halfLength[i];
     400      longestAxisIndex = i;
     401    }
     402  }
     403  PRINTF(3)("\nLongest Axis is: Nr %i with a half-length of:%11.2f\n", longestAxisIndex, longestAxis);
     404
     405
     406  PRINTF(4)("Separating along the longest axis\n");
    595407  /* get the closest vertex near the center */
    596408  float               dist = 999999.0f;                    //!< the smallest distance to each vertex
    597   float               tmpDist;                             //!< temporary distance
    598   int                 vertexIndex;
    599   Plane               middlePlane(box->axis[axisIndex], *box->center); //!< the middle plane
    600 
    601   vertexIndex = 0;
    602   for(int i = 0; i < box->numOfVertices; ++i)
    603   {
    604     tmpDist = fabs(middlePlane.distancePoint(box->vertices[i]));
    605     if( tmpDist < dist)
    606     {
    607       dist = tmpDist;
    608       vertexIndex = i;
    609     }
    610   }
    611 
    612   PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
     409  float               tmpDist;                             //!< variable to save diverse distances temporarily
     410  int                 vertexIndex;                         //!< index of the vertex near the center
     411  Plane               middlePlane(box.axis[longestAxisIndex], box.center); //!< the middle plane
     412  const sVec3D*       tmpVec;                              //!< temp simple 3D vector
    613413
    614414
     
    616416  the points depending on which side they are located
    617417  */
    618   tList<const sVec3D>      partition1;                           //!< the vertex partition 1
    619   tList<const sVec3D>      partition2;                           //!< the vertex partition 2
    620 
    621 
    622   PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box->numOfVertices);
    623   this->separationPlane = new Plane(box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
    624   this->sepPlaneCenter = &box->vertices[vertexIndex];
    625   this->longestAxisIndex = axisIndex;
    626 
    627   for(int i = 0; i < box->numOfVertices; ++i)
    628   {
    629     if( i == vertexIndex) continue;
    630     tmpDist = this->separationPlane->distancePoint(box->vertices[i]);
    631     if( tmpDist > 0.0)
    632       partition1.add(&box->vertices[i]); /* positive numbers plus zero */
    633     else
    634       partition2.add(&box->vertices[i]); /* negatice numbers */
    635   }
    636   partition1.add(&box->vertices[vertexIndex]);
    637   partition2.add(&box->vertices[vertexIndex]);
    638 
    639   PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
     418  std::list<int>           partition1;                           //!< the vertex partition 1
     419  std::list<int>           partition2;                           //!< the vertex partition 2
     420  float*                   triangleCenter = new float[3];        //!< the center of the triangle
     421  const float*             a;                                    //!< triangle  edge a
     422  const float*             b;                                    //!< triangle  edge b
     423  const float*             c;                                    //!< triangle  edge c
     424
     425
     426  /* find the center of the box */
     427  this->separationPlane = Plane(box.axis[longestAxisIndex], box.center);
     428  this->sepPlaneCenter[0] = box.center.x;
     429  this->sepPlaneCenter[1] = box.center.y;
     430  this->sepPlaneCenter[2] = box.center.z;
     431  this->longestAxisIndex = longestAxisIndex;
     432
     433  for( int i = 0; i < box.triangleIndexesLength; ++i)
     434  {
     435    /* first calculate the middle of the triangle */
     436    a = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[0]];
     437    b = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[1]];
     438    c = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[2]];
     439
     440    triangleCenter[0] = (a[0] + b[0] + c[0]) / 3.0f;
     441    triangleCenter[1] = (a[1] + b[1] + c[1]) / 3.0f;
     442    triangleCenter[2] = (a[2] + b[2] + c[2]) / 3.0f;
     443    tmpDist = this->separationPlane.distancePoint(*((sVec3D*)triangleCenter));
     444
     445    if( tmpDist > 0.0f)
     446      partition1.push_back(box.triangleIndexes[i]); /* positive numbers plus zero */
     447    else if( tmpDist < 0.0f)
     448      partition2.push_back(box.triangleIndexes[i]); /* negatice numbers */
     449    else {
     450      partition1.push_back(box.triangleIndexes[i]); /* 0.0f? unprobable... */
     451      partition2.push_back(box.triangleIndexes[i]);
     452    }
     453  }
     454  PRINTF(3)("\nPartition1: got \t%i Vertices \nPartition2: got \t%i Vertices\n", partition1.size(), partition2.size());
    640455
    641456
    642457  /* now comes the separation into two different sVec3D arrays */
    643   tIterator<const sVec3D>* iterator;                       //!< the iterator to go through the lists
    644   const sVec3D*      element;                              //!< the elements
    645458  int                index;                                //!< index storage place
    646   sVec3D*            vertList1;                            //!< the vertex list 1
    647   sVec3D*            vertList2;                            //!< the vertex list 2
    648 
    649   vertList1 = new sVec3D[partition1.getSize()];
    650   vertList2 = new sVec3D[partition2.getSize()];
    651 
    652   iterator = partition1.getIterator();
    653   element = iterator->firstElement();
    654   index = 0;
    655   while( element != NULL)
    656   {
    657     vertList1[index][0] = element[0][0];
    658     vertList1[index][1] = element[0][1];
    659     vertList1[index][2] = element[0][2];
    660     ++index;
    661     element = iterator->nextElement();
    662   }
    663 
    664 //   PRINTF(0)("\npartition 1:\n");
    665 //   for(int i = 0; i < partition1.getSize(); ++i)
    666 //   {
    667 //     PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList1[i][0], i, vertList1[i][1], i, vertList1[i][2]);
    668 //   }
    669 
    670   iterator = partition2.getIterator();
    671   element = iterator->firstElement();
    672   index = 0;
    673   while( element != NULL)
    674   {
    675     vertList2[index][0] = element[0][0];
    676     vertList2[index][1] = element[0][1];
    677     vertList2[index][2] = element[0][2];
    678     ++index;
    679     element = iterator->nextElement();
    680   }
    681 
    682   this->tmpVert1 = vertList1;
    683   this->tmpVert2 = vertList2;
    684   this->tmpLen1 = partition1.getSize();
    685   this->tmpLen2 = partition2.getSize();
    686 
    687   delete iterator;
    688 
    689 //   PRINTF(0)("\npartition 2:\n");
    690 //   for(int i = 0; i < partition2.getSize(); ++i)
    691 //   {
    692 //     PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList2[i][0], i,  vertList2[i][1], i, vertList2[i][2]);
    693 //   }
     459  int*               triangleIndexList1;                   //!< the vertex list 1
     460  int*               triangleIndexList2;                   //!< the vertex list 2
     461  std::list<int>::iterator element;                        //!< the list iterator
     462
     463  triangleIndexList1 = new int[partition1.size()];
     464  triangleIndexList2 = new int[partition2.size()];
     465
     466  for( element = partition1.begin(), index = 0; element != partition1.end(); element++, index++)
     467    triangleIndexList1[index] = (*element);
     468
     469  for( element = partition2.begin(), index = 0; element != partition2.end(); element++, index++)
     470    triangleIndexList2[index] = (*element);
     471
     472  if( this->triangleIndexList1!= NULL)
     473    delete[] this->triangleIndexList1;
     474  this->triangleIndexList1 = triangleIndexList1;
     475  this->triangleIndexLength1 = partition1.size();
     476
     477  if( this->triangleIndexList2 != NULL)
     478    delete[] this->triangleIndexList2;
     479  this->triangleIndexList2 = triangleIndexList2;
     480  this->triangleIndexLength2 = partition2.size();
    694481}
    695482
     
    699486void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB)
    700487{
    701   PRINTF(3)("collideWith\n");
     488  if( unlikely(treeNode == NULL))
     489    return;
     490
     491  PRINTF(4)("collideWith\n");
    702492  /* if the obb overlap, make subtests: check which node is realy overlaping  */
    703   PRINT(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
    704   if( unlikely(treeNode == NULL)) return;
    705 
    706   if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
    707   {
    708     PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight);
     493  PRINTF(4)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
     494  //   if( unlikely(treeNode == NULL)) return;
     495
     496
     497  if( this->overlapTest(*this->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
     498  {
     499    PRINTF(4)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight);
    709500
    710501    /* check if left node overlaps */
    711502    if( likely( this->nodeLeft != NULL))
    712503    {
    713       PRINT(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
    714       if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
     504      PRINTF(4)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
     505      if( this->overlapTest(*this->nodeLeft->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
    715506      {
    716         this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);
    717         this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);
     507        this->nodeLeft->collideWith((((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB);
     508        this->nodeLeft->collideWith((((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB);
    718509      }
    719510    }
     
    721512    if( likely( this->nodeRight != NULL))
    722513    {
    723       PRINT(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
    724       if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
     514      PRINTF(4)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
     515      if(this->overlapTest(*this->nodeRight->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
    725516      {
    726        this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);
    727        this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);
     517        this->nodeRight->collideWith((((const OBBTreeNode*)treeNode)->nodeLeft), nodeA, nodeB);
     518        this->nodeRight->collideWith((((const OBBTreeNode*)treeNode)->nodeRight), nodeA, nodeB);
    728519      }
    729520    }
    730521
    731522    /* so there is a collision and this is the last box in the tree (i.e. leaf) */
     523    /* FIXME: If we would choose || insead of && there would also be asymmetrical cases supported */
    732524    if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL))
    733525    {
    734       nodeA->collidesWith(nodeB, *((OBBTreeNode*)treeNode)->bvElement->center);
    735 
    736       nodeB->collidesWith(nodeA, *this->bvElement->center);
    737     }
    738 
    739   }
    740 }
    741 
    742 
    743 
    744 bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB)
    745 {
     526      nodeA->collidesWith(nodeB, (((const OBBTreeNode*)&treeNode)->bvElement->center));
     527
     528      nodeB->collidesWith(nodeA, this->bvElement->center);
     529    }
     530
     531  }
     532}
     533
     534
     535
     536bool OBBTreeNode::overlapTest(OBB& boxA, OBB& boxB, WorldEntity* nodeA, WorldEntity* nodeB)
     537{
     538  //HACK remove this again
     539  this->owner = nodeA;
     540  //   if( boxB == NULL || boxA == NULL)
     541  //     return false;
     542
    746543  /* first check all axis */
    747544  Vector t;
     
    752549  Vector rotAxisB[3];
    753550
    754   rotAxisA[0] =  nodeA->getAbsDir().apply(boxA->axis[0]);
    755   rotAxisA[1] =  nodeA->getAbsDir().apply(boxA->axis[1]);
    756   rotAxisA[2] =  nodeA->getAbsDir().apply(boxA->axis[2]);
    757 
    758   rotAxisB[0] =  nodeB->getAbsDir().apply(boxB->axis[0]);
    759   rotAxisB[1] =  nodeB->getAbsDir().apply(boxB->axis[1]);
    760   rotAxisB[2] =  nodeB->getAbsDir().apply(boxB->axis[2]);
    761 
    762   t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(*boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(*boxB->center));
    763 
    764 //   printf("\n");
    765 //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z);
    766 //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z);
    767 //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z);
    768 //
    769 //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z);
    770 //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z);
    771 //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z);
     551  rotAxisA[0] =  nodeA->getAbsDir().apply(boxA.axis[0]);
     552  rotAxisA[1] =  nodeA->getAbsDir().apply(boxA.axis[1]);
     553  rotAxisA[2] =  nodeA->getAbsDir().apply(boxA.axis[2]);
     554
     555  rotAxisB[0] =  nodeB->getAbsDir().apply(boxB.axis[0]);
     556  rotAxisB[1] =  nodeB->getAbsDir().apply(boxB.axis[1]);
     557  rotAxisB[2] =  nodeB->getAbsDir().apply(boxB.axis[2]);
     558
     559
     560  t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(boxA.center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(boxB.center));
     561
     562  //   printf("\n");
     563  //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z);
     564  //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z);
     565  //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z);
     566  //
     567  //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z);
     568  //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z);
     569  //   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z);
    772570
    773571
     
    779577    l = rotAxisA[j];
    780578
    781     rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
    782     rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
    783     rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
    784 
    785     rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
    786     rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
    787     rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    788 
    789     PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     579    rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
     580    rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
     581    rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
     582
     583    rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
     584    rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
     585    rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
     586
     587    PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
    790588
    791589    if( (rA + rB) < fabs(t.dot(l)))
    792590    {
    793       PRINT(3)("no Collision\n");
     591      PRINTF(4)("no Collision\n");
    794592      return false;
    795593    }
     
    803601    l = rotAxisB[j];
    804602
    805     rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
    806     rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
    807     rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
    808 
    809     rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
    810     rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
    811     rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    812 
    813     PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     603    rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
     604    rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
     605    rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
     606
     607    rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
     608    rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
     609    rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
     610
     611    PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
    814612
    815613    if( (rA + rB) < fabs(t.dot(l)))
    816614    {
    817       PRINT(3)("no Collision\n");
     615      PRINTF(4)("no Collision\n");
    818616      return false;
    819617    }
     
    831629      l = rotAxisA[j].cross(rotAxisB[k]);
    832630
    833       rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
    834       rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
    835       rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
    836 
    837       rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
    838       rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
    839       rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
    840 
    841       PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     631      rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
     632      rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
     633      rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
     634
     635      rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
     636      rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
     637      rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
     638
     639      PRINTF(5)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
    842640
    843641      if( (rA + rB) < fabs(t.dot(l)))
    844642      {
    845         PRINT(3)("keine Kollision\n");
     643        PRINTF(4)("keine Kollision\n");
    846644        return false;
    847645      }
     
    849647  }
    850648
    851 
    852   boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */
    853   boxB->bCollided = true;
    854   PRINT(3)("Kollision!\n");
     649  /* FIXME: there is no collision mark set now */
     650     boxA.bCollided = true; /* use this ONLY(!!!!) for drawing operations */
     651     boxB.bCollided = true;
     652
     653
     654  PRINTF(4)("Kollision!\n");
    855655  return true;
    856656}
     
    860660
    861661
     662
     663
     664
     665
     666
     667/**
     668 *
     669 * draw the BV tree - debug mode
     670 */
    862671void OBBTreeNode::drawBV(int depth, int drawMode, const Vector& color,  bool top) const
    863672{
    864 
    865   /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */
    866   if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL)
    867   {
    868     if( !(drawMode & DRAW_SINGLE && depth != 0))
    869     {
    870       if( drawMode & DRAW_POINTS)
     673  /* this function can be used to draw the triangles and/or the points only  */
     674  if( 1 /*drawMode & DRAW_MODEL || drawMode & DRAW_ALL*/)
     675  {
     676    if( depth == 0/*!(drawMode & DRAW_SINGLE && depth != 0)*/)
     677    {
     678      if( 1 /*drawMode & DRAW_POINTS*/)
     679      {
    871680        glBegin(GL_POINTS);
    872       for(int i = 0; i < this->bvElement->numOfVertices; ++i)
    873       {
    874         if( drawMode & DRAW_POINTS)
    875           glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
    876         else
    877         {
    878           glPushMatrix();
    879           glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
    880           gluSphere(OBBTreeNode_sphereObj, 0.1, 10, 10);
    881           glPopMatrix();
    882         }
     681        glColor3f(0.3, 0.8, 0.54);
     682        for( int i = 0; i < this->bvElement->modelInf->numVertices*3; i+=3)
     683          glVertex3f(this->bvElement->modelInf->pVertices[i],
     684                     this->bvElement->modelInf->pVertices[i+1],
     685                     this->bvElement->modelInf->pVertices[i+2]);
     686        glEnd();
    883687      }
    884       if( drawMode & DRAW_POINTS)
    885         glEnd();
    886688    }
    887689  }
     
    897699
    898700  /* draw world axes */
    899   if( drawMode & DRAW_BV_AXIS)
     701  if( 1 /*drawMode & DRAW_BV_AXIS*/)
    900702  {
    901703    glBegin(GL_LINES);
     
    915717
    916718
    917   if( drawMode & DRAW_BV_AXIS || drawMode & DRAW_ALL)
    918   {
    919     if( !(drawMode & DRAW_SINGLE && depth != 0))
     719  if( 1/*drawMode & DRAW_BV_AXIS || drawMode & DRAW_ALL*/)
     720  {
     721    if( 1/*drawMode & DRAW_SINGLE && depth != 0*/)
    920722    {
    921723      /* draw the obb axes */
    922724      glBegin(GL_LINES);
    923       glColor3f(0.0, 0.4, 0.3);
    924       glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    925       glVertex3f(this->bvElement->center->x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
    926                  this->bvElement->center->y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
    927                  this->bvElement->center->z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
    928 
    929       glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    930       glVertex3f(this->bvElement->center->x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
    931                  this->bvElement->center->y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
    932                  this->bvElement->center->z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
    933 
    934       glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
    935       glVertex3f(this->bvElement->center->x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
    936                  this->bvElement->center->y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
    937                  this->bvElement->center->z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
     725      glColor3f(1.0, 0.0, 0.0);
     726      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
     727      glVertex3f(this->bvElement->center.x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
     728                 this->bvElement->center.y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
     729                 this->bvElement->center.z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
     730
     731      glColor3f(0.0, 1.0, 0.0);
     732      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
     733      glVertex3f(this->bvElement->center.x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
     734                 this->bvElement->center.y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
     735                 this->bvElement->center.z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
     736
     737      glColor3f(0.0, 0.0, 1.0);
     738      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
     739      glVertex3f(this->bvElement->center.x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
     740                 this->bvElement->center.y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
     741                 this->bvElement->center.z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
    938742      glEnd();
    939743    }
     
    950754    }
    951755
    952     if(this->nodeLeft == NULL || this->nodeRight == NULL)
     756    if( this->nodeLeft == NULL && this->nodeRight == NULL)
    953757      depth = 0;
    954     if( !(drawMode & DRAW_SINGLE && depth != 0))
    955     {
    956     Vector cen = *this->bvElement->center;
    957     Vector* axis = this->bvElement->axis;
    958     float* len = this->bvElement->halfLength;
    959 
    960     if( this->bvElement->bCollided)
    961     {
    962       glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR
    963     }
    964     else if( drawMode & DRAW_BV_BLENDED)
    965     {
    966       glColor4f(color.x, color.y, color.z, .5);
    967     }
    968 
    969     /* draw bounding box */
    970     if( drawMode & DRAW_BV_BLENDED)
    971       glBegin(GL_QUADS);
    972     else
    973       glBegin(GL_LINE_LOOP);
    974     glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
    975                cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
    976                cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
    977     glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
    978                cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
    979                cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
    980     glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
    981                cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
    982                cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
    983     glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
    984                cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
    985                cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    986     glEnd();
    987 
    988     if( drawMode & DRAW_BV_BLENDED)
    989       glBegin(GL_QUADS);
    990     else
    991       glBegin(GL_LINE_LOOP);
    992     glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
    993                cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
    994                cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    995     glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
    996                cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
    997                cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
    998     glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
    999                cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
    1000                cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
    1001     glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
    1002                cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
    1003                cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    1004     glEnd();
    1005 
    1006     if( drawMode & DRAW_BV_BLENDED)
    1007       glBegin(GL_QUADS);
    1008     else
    1009       glBegin(GL_LINE_LOOP);
    1010     glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
    1011                cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
    1012                cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    1013     glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
    1014                cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
    1015                cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
    1016     glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
    1017                cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
    1018                cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
    1019     glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
    1020                cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
    1021                cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
    1022     glEnd();
    1023 
    1024     if( drawMode & DRAW_BV_BLENDED)
    1025       glBegin(GL_QUADS);
    1026     else
    1027       glBegin(GL_LINE_LOOP);
    1028     glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
    1029                cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
    1030                cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
    1031     glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
    1032                cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
    1033                cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
    1034     glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
    1035                cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
    1036                cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
    1037     glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
    1038                cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
    1039                cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
    1040     glEnd();
    1041 
    1042 
    1043     if( drawMode & DRAW_BV_BLENDED)
    1044     {
    1045       glBegin(GL_QUADS);
    1046       glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
    1047                  cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
    1048                  cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
     758
     759    if( depth == 0 /*!(drawMode & DRAW_SINGLE && depth != 0)*/)
     760    {
     761
     762
     763      Vector cen = this->bvElement->center;
     764      Vector* axis = this->bvElement->axis;
     765      float* len = this->bvElement->halfLength;
     766
     767      if( this->bvElement->bCollided)
     768      {
     769        glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR
     770      }
     771      else if( drawMode & DRAW_BV_BLENDED)
     772      {
     773        glColor4f(color.x, color.y, color.z, .5);
     774      }
     775
     776      // debug out
     777      if( this->obbTree->getOwner() != NULL)
     778      {
     779        PRINTF(4)("debug poly draw: depth: %i, mode: %i, entity-name: %s, class: %s\n", depth, drawMode, this->obbTree->getOwner()->getName(), this->obbTree->getOwner()->getClassName());
     780      }
     781      else
     782        PRINTF(4)("debug poly draw: depth: %i, mode: %i\n", depth, drawMode);
     783
     784
     785      /* draw bounding box */
     786      if( drawMode & DRAW_BV_BLENDED)
     787        glBegin(GL_QUADS);
     788      else
     789        glBegin(GL_LINE_LOOP);
     790      glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     791                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     792                 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
    1049793      glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
    1050794                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     
    1053797                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
    1054798                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     799      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     800                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     801                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     802      glEnd();
     803
     804      if( drawMode & DRAW_BV_BLENDED)
     805        glBegin(GL_QUADS);
     806      else
     807        glBegin(GL_LINE_LOOP);
     808      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     809                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     810                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     811      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     812                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     813                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
    1055814      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
    1056815                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
    1057816                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     817      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     818                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     819                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    1058820      glEnd();
    1059821
    1060       glBegin(GL_QUADS);
     822      if( drawMode & DRAW_BV_BLENDED)
     823        glBegin(GL_QUADS);
     824      else
     825        glBegin(GL_LINE_LOOP);
     826      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     827                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     828                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     829      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     830                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     831                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     832      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     833                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     834                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
     835      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     836                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     837                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
     838      glEnd();
     839
     840      if( drawMode & DRAW_BV_BLENDED)
     841        glBegin(GL_QUADS);
     842      else
     843        glBegin(GL_LINE_LOOP);
     844      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     845                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     846                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
    1061847      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
    1062848                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     
    1065851                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
    1066852                 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
    1067       glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
    1068                  cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
    1069                  cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
    1070       glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
    1071                  cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
    1072                  cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     853      glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     854                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     855                 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
    1073856      glEnd();
    1074     }
    1075 
    1076 
    1077     if( drawMode & DRAW_BV_BLENDED)
    1078       glColor3f(color.x, color.y, color.z);
    1079     }
    1080 
     857
     858
     859      if( drawMode & DRAW_BV_BLENDED)
     860      {
     861        glBegin(GL_QUADS);
     862        glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     863                   cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     864                   cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
     865        glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
     866                   cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
     867                   cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
     868        glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     869                   cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     870                   cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     871        glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
     872                   cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
     873                   cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
     874        glEnd();
     875
     876        glBegin(GL_QUADS);
     877        glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     878                   cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     879                   cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
     880        glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
     881                   cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
     882                   cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
     883        glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     884                   cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     885                   cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     886        glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
     887                   cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
     888                   cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
     889        glEnd();
     890      }
     891
     892      if( drawMode & DRAW_BV_BLENDED)
     893        glColor3f(color.x, color.y, color.z);
     894    }
    1081895  }
    1082896
     
    1089903        glColor4f(color.x, color.y, color.z, .6);
    1090904
    1091     /* now draw the separation plane */
    1092     Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];
    1093     Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];
    1094     Vector c = *this->bvElement->center;
    1095     float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
    1096     float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
    1097     glBegin(GL_QUADS);
    1098     glVertex3f(c.x + a1.x * l1 + a2.x * l2, c.y + a1.y * l1+ a2.y * l2, c.z + a1.z * l1 + a2.z * l2);
    1099     glVertex3f(c.x - a1.x * l1 + a2.x * l2, c.y - a1.y * l1+ a2.y * l2, c.z - a1.z * l1 + a2.z * l2);
    1100     glVertex3f(c.x - a1.x * l1 - a2.x * l2, c.y - a1.y * l1- a2.y * l2, c.z - a1.z * l1 - a2.z * l2);
    1101     glVertex3f(c.x + a1.x * l1 - a2.x * l2, c.y + a1.y * l1- a2.y * l2, c.z + a1.z * l1 - a2.z * l2);
    1102     glEnd();
    1103 
    1104     if( drawMode & DRAW_BV_BLENDED)
    1105       glColor4f(color.x, color.y, color.z, 1.0);
     905      /* now draw the separation plane */
     906      Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];
     907      Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];
     908      Vector c = this->bvElement->center;
     909      float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
     910      float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
     911      glBegin(GL_QUADS);
     912      glVertex3f(c.x + a1.x * l1 + a2.x * l2, c.y + a1.y * l1+ a2.y * l2, c.z + a1.z * l1 + a2.z * l2);
     913      glVertex3f(c.x - a1.x * l1 + a2.x * l2, c.y - a1.y * l1+ a2.y * l2, c.z - a1.z * l1 + a2.z * l2);
     914      glVertex3f(c.x - a1.x * l1 - a2.x * l2, c.y - a1.y * l1- a2.y * l2, c.z - a1.z * l1 - a2.z * l2);
     915      glVertex3f(c.x + a1.x * l1 - a2.x * l2, c.y + a1.y * l1- a2.y * l2, c.z + a1.z * l1 - a2.z * l2);
     916      glEnd();
     917
     918      if( drawMode & DRAW_BV_BLENDED)
     919        glColor4f(color.x, color.y, color.z, 1.0);
    1106920
    1107921    }
     
    1127941void OBBTreeNode::debug() const
    1128942{
    1129 
    1130   /*
    1131   for(int i = 0; i < length; i++)
    1132   {
    1133   PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
    1134 }
    1135   */
    1136 }
     943  PRINT(0)("========OBBTreeNode::debug()=====\n");
     944  PRINT(0)(" Current depth: %i", this->depth);
     945  PRINT(0)(" ");
     946  PRINT(0)("=================================\n");
     947}
  • trunk/src/lib/collision_detection/obb_tree_node.h

    r5693 r7711  
    11/*!
    22 * @file bv_tree.h
    3   *  Definition of a bounding volume tree
    4 
     3 *  Definition of a bounding volume tree
    54 */
    65
     
    87#define _OBB_TREE_NODE_H
    98
     9
    1010#include "bv_tree_node.h"
     11#include "plane.h"
    1112
    12 
    13 
    14 // FORWARD DECLARATION
    1513class BoundingVolume;
    1614class OBB;
     
    1816class Plane;
    1917class PNode;
    20 //struct sVec3D;
     18
    2119
    2220//! A class that represents a bounding volume tree
    23 class OBBTreeNode : public BVTreeNode {
     21class OBBTreeNode : public BVTreeNode
     22{
    2423
    2524
    2625  public:
    27     OBBTreeNode();
     26    OBBTreeNode(const OBBTree& tree, OBBTreeNode* prev, int depth);
    2827    virtual ~OBBTreeNode();
    2928
    30     virtual void spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length);
    31     virtual void spawnBVTree(const int depth, const modelInfo& modInfo);
     29    /**  this function returns the bounding volume of this tree node @return: returns the BV */
     30    virtual inline const BoundingVolume* getBV() const { return (BoundingVolume*)this->bvElement; }
    3231
    33     BoundingVolume* getBV(int index) const { return (BoundingVolume*)this->bvElement; }
    34     inline const int getIndex() { return this->treeIndex; }
    35     inline void setTreeRef(OBBTree* tree) { this->obbTree = tree;}
     32    virtual void spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, int length);
    3633
    3734    virtual void collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB);
    38 
    3935    virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const;
    40 
    4136    void debug() const;
    4237
    43   private:
    44     void calculateBoxCovariance(OBB* box, const sVec3D* verticesList, unsigned int length);
    45     void calculateBoxEigenvectors(OBB* box, const sVec3D* verticesList, unsigned int length);
    46     void calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length);
    47 
    48     void calculateBoxCovariance(OBB* box, const modelInfo& modInfo);
    49     void calculateBoxEigenvectors(OBB* box, const modelInfo& modInfo);
    50     void calculateBoxAxis(OBB* box, const modelInfo& modInfo);
     38    /**  gets the id of the current child @return id of the child */
     39    inline const int getID() { return this->nextID++; }
    5140
    5241
    53     void forkBox(OBB* box);
     42  private:
     43    void calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length);
    5444
    55     bool overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB);
     45    void calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, int length);
     46    void calculateBoxEigenvectors(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, int length);
     47    void calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, int length);
     48    void forkBox(OBB& box);
     49
     50    bool overlapTest(OBB& boxA, OBB& boxB, WorldEntity* nodeA, WorldEntity* nodeB);
     51
    5652
    5753  protected:
    5854    OBB*                bvElement;                  //!< the obb element
     55    OBBTreeNode*        nodePrev;                   //!< ref to the previous (parent) tree node = NULL if first
    5956    OBBTreeNode*        nodeLeft;                   //!< ref to the left tree node
    6057    OBBTreeNode*        nodeRight;                  //!< ref to the right tree node
    6158
     59
    6260  private:
    63     unsigned int        treeIndex;                  //!< Index number of the BV in the tree
    64     const sVec3D*       vertices;                   //!< pointer to the vertices data
    65     int                 numOfVertices;              //!< number of vertices in vertices data
     61    int                 treeIndex;                  //!< Index number of the BV in the tree
     62    int                 nextID;                     //!< the id of the next child
    6663    int                 depth;                      //!< the depth of the node in the tree
    67     static OBBTree*     obbTree;                    //!< reference to the obb tree
    68     Plane*              separationPlane;            //!< the separation plane of the obb
    69     const sVec3D*       sepPlaneCenter;             //!< only needed to draw plane
     64    const OBBTree*      obbTree;                    //!< reference to the obb tree
     65
     66    const modelInfo*    modelInf;                   //!< pointer to the models modelInfo object
     67    const int*          triangleIndexes;            //!< indexes to the used model triangles
     68
     69    Plane               separationPlane;            //!< the separation plane of the obb
     70    sVec3D              sepPlaneCenter;             //!< only needed to draw plane
    7071    int                 longestAxisIndex;           //!< only needed to draw plane
    7172
    7273    /* tmp saving place for obb variables */
    73     sVec3D*             tmpVert1;                   //!< pointer to the vert data of obbox1
    74     sVec3D*             tmpVert2;                   //!< pointer to the vert data of obbox1
    75     int                 tmpLen1;                    //!< len vert data obbox1
    76     int                 tmpLen2;                    //!< len vert data obbox2
     74    int*                triangleIndexList1;         //!< pointer to the vert data of obbox1
     75    int*                triangleIndexList2;         //!< pointer to the vert data of obbox1
     76    int                 triangleIndexLength1;       //!< len vert data obbox1
     77    int                 triangleIndexLength2;       //!< len vert data obbox2
    7778
    78     static float**      coMat;
    79     static float**      eigvMat;
    80     static float*       eigvlMat;
    81     static int*         rotCount;
     79    WorldEntity*        owner;
    8280};
    8381
  • trunk/src/lib/graphics/importer/static_model.cc

    r7676 r7711  
    196196  this->buildTriangleList();
    197197
     198  // write out the modelInfo data used for the collision detection!
    198199  this->pModelInfo.pVertices = &this->vertices[0];
    199200  this->pModelInfo.pNormals = &this->normals[0];
     
    805806    this->buildVertexNormals();
    806807
    807   int index = 0;                   //!< the counter for the triangle array
    808   ModelFaceElement* tmpElem;       //!< the temporary faceelement reference
    809   ModelFace* tmpFace;              //!< the temporary face referece
     808  int                index = 0;                   //!< the counter for the triangle array
     809  ModelFaceElement*  tmpElem;       //!< the temporary faceelement reference
     810  ModelFace*         tmpFace;              //!< the temporary face referece
    810811
    811812  bool warned = false;
     813
     814  this->pModelInfo.numTriangles = 0;
    812815
    813816  /* count the number of triangles */
     
    819822    while( tmpFace != NULL)
    820823    {
    821 
    822824      /* if its a triangle just add it to the list */
    823       if( tmpFace->vertexCount == 3)
    824       {
     825      if( tmpFace->vertexCount == 3){
    825826        ++this->pModelInfo.numTriangles;
    826827      } /* if the polygon is a quad */
    827       else if( tmpFace->vertexCount == 4)
    828       {
     828      else if( tmpFace->vertexCount == 4) {
    829829        this->pModelInfo.numTriangles += 2;
    830830      }
    831       else if( tmpFace->vertexCount > 4)
    832       {
    833         if (!warned)
    834         {
     831      else if( tmpFace->vertexCount > 4) {
     832        if (!warned)        {
    835833          PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName());
    836834          warned = true;
    837835        }
    838         //exit(0);
    839836      }
    840837      tmpFace = tmpFace->next;
     
    859856  while( this->currentGroup != NULL)
    860857  {
    861     // Putting Faces to GL
    862858    tmpFace = this->currentGroup->firstFace;
    863859    while( tmpFace != NULL)
     
    870866        for( int j = 0; j < 3; ++j)
    871867        {
    872           this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber /* * 3 */;
    873           this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber /* * 3 */;
    874           this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber /* * 3 */;
     868          this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;
     869          this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;
     870          this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;
    875871          tmpElem = tmpElem->next;
     872
    876873        }
    877874        ++index;
     
    880877      {
    881878
    882         this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber;
    883         this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber;
    884         this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber;
    885 
    886         this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber;
    887         this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber;
    888         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber;
     879        this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
     880        this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
     881        this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
     882
     883        this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;
     884        this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;
     885        this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;
    889886        tmpElem = tmpElem->next;
    890887
    891         this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber;
    892         this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber;
    893         this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber;
     888        this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
     889        this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
     890        this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    894891        tmpElem = tmpElem->next;
    895892
    896         this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber;
    897         this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber;
    898         this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber;
    899 
    900         this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber;
    901         this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber;
    902         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber;
     893        this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
     894        this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
     895        this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
     896
     897        this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;
     898        this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;
     899        this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;
    903900        tmpElem = tmpElem->next;
    904901
    905         this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber;
    906         this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber;
    907         this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber;
     902        this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;
     903        this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;
     904        this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;
    908905
    909906        index += 2;
  • trunk/src/lib/math/matrix.cc

    r5696 r7711  
    244244
    245245    eigVc3 = eigVc1.cross(eigVc2);
     246
     247    eigVc2 = eigVc3.cross(eigVc1);
    246248  }
    247249  else if (eigenValuesCount == 1)
     
    254256  eigVc2.normalize();
    255257  eigVc3.normalize();
     258
     259  if (!(eigVc1.cross(eigVc3) == eigVc2))
     260  {
     261    eigVc3.cross(eigVc1);
     262//     eigVc2.debug();
     263  }
     264/*  printf("ok\n")*/;
    256265}
    257266
  • trunk/src/lib/math/plane.cc

    r6617 r7711  
    222222}
    223223
     224
    224225/**
    225226 *  calculate the two points of minimal distance of two lines
     
    267268{
    268269  n = (a-b).cross(c-b);
    269   k = -(n.x*b.x+n.y*b.y+n.z*b.z);
     270  k = n.dot(a) / n.len();
    270271}
    271272
     
    278279{
    279280  n = norm;
    280   k = -(n.x*p.x+n.y*p.y+n.z*p.z);
     281  k = n.dot(p) / n.len();
    281282}
    282283
     
    291292  Vector p(g[0], g[1], g[2]);
    292293  n = norm;
    293   k = -(n.x*p.x+n.y*p.y+n.z*p.z);
     294  k = n.dot(p) / n.len();
    294295}
    295296
     
    315316  float l = n.len();
    316317  if( l == 0.0) return 0.0;
    317   return (n.dot(p) + k) / n.len();
     318  return (n.dot(p) / n.len() - k);
    318319}
    319320
     
    324325 * @return the distance between the plane and the point (can be negative)
    325326 */
    326 float Plane::distancePoint (const sVec3D& p) const
     327// float Plane::distancePoint (const sVec3D& p) const
     328// {
     329//   Vector s(p[0], p[1], p[2]);
     330//   float l = n.len();
     331//   if( l == 0.0) return 0.0;
     332//   return (n.dot(s) + k) / n.len();
     333// }
     334
     335
     336/**
     337 *  returns the distance between the plane and a point
     338 * @param p: a Point
     339 * @return the distance between the plane and the point (can be negative)
     340 */
     341float Plane::distancePoint (const float* p) const
    327342{
    328343  Vector s(p[0], p[1], p[2]);
     344
    329345  float l = n.len();
    330346  if( l == 0.0) return 0.0;
    331   return (n.dot(s) + k) / n.len();
     347  return (n.dot(s) / n.len() - k);
    332348}
    333349
  • trunk/src/lib/math/plane.h

    r6617 r7711  
    5151  Vector intersectLine (const Line& l) const;
    5252  float distancePoint (const Vector& p) const;
    53   float distancePoint (const sVec3D& p) const;
     53//   float distancePoint (const sVec3D& p) const;
     54  float distancePoint (const float* p) const;
    5455  float locatePoint (const Vector& p) const;
    5556};
  • trunk/src/lib/math/vector.h

    r7191 r7711  
    8585  /** copy constructor* @param v the sVec3D to assign to this vector. @returns the vector v */
    8686  inline const Vector& operator= (const sVec3D& v) { this->x = v[0]; this->y = v[1]; this->z = v[2]; }
     87  inline const Vector& operator= (const float* v) { this->x = v[0]; this->y = v[1]; this->z = v[2]; }
    8788  /** @param v: the other vector \return the dot product of the vectors */
    8889  float dot (const Vector& v) const { return x*v.x+y*v.y+z*v.z; };
  • trunk/src/lib/util/executor/executor_specials.h

    r7474 r7711  
    88
    99#include "executor.h"
     10#include "compiler.h"
    1011
    1112#include "compiler.h"
  • trunk/src/lib/util/executor/functor_list.h

    r7331 r7711  
    140140
    141141  FUNCTOR_LIST(3)(l_STRING, l_FLOAT, l_UINT);
    142 
     142  FUNCTOR_LIST(4)(l_STRING, l_FLOAT, l_UINT, l_UINT);
    143143
    144144#endif /* FUNCTOR_LIST */
  • trunk/src/orxonox.cc

    r7677 r7711  
    6464#include <string.h>
    6565
    66 int verbose = 4;
     66int verbose = 5;
    6767
    6868using namespace std;
  • trunk/src/subprojects/collision_detection/collision_detection.cc

    r7157 r7711  
    4848//Terrain* c;
    4949bool animateModel = false;
     50
     51
    5052
    5153void Framework::moduleInit(int argc, char** argv)
     
    7678//   CDEngine::getInstance()->debugSpawnTree(9, (sVec3D*)mod->getVertexArray(), mod->getVertexArrayCount());
    7779
    78 
    79 
    80   entityList = new tList<WorldEntity>();
    81 
    82 //   a = new TestEntity(); a->setName("Clown1");
    83    b = new CollisionTestEntity(); b->setName("Jaeger");
     80   entityList = new tList<WorldEntity>();
     81
    8482   if (argc > 1)
    8583   {
    8684     printf("Loading model %s\n", argv[1]);
    87      b->loadModel(argv[1]);
     85     b = new CollisionTestEntity(argv[1]); b->setName("Jaeger");
    8886   }
    89 //   a = new Terrain();
    90 
     87   else
     88   {
     89     printf("----------------------- WARNING ---------------------\n\n");
     90     printf("no path specified, using default model: models/ships/fighter.obj\n\n");
     91     printf("----------------------- WARNING ---------------------\n");
     92     b = new CollisionTestEntity("models/test/cd_test_0.obj"); b->setName("Jaeger");
     93   }
    9194//   b->setRelCoor(0.0, 0.0, -20.0);
    9295//   b->setRelDir(Quaternion(-M_PI/2.0f, Vector(0.0, 1.0, 0.0)));
    93 
    94   entityList->add(b);
     96   if(b != NULL)
     97     printf("model successfully loaded\n");
     98   entityList->add(b);
     99
     100
     101//   a = new Terrain();
     102
     103
    95104//   entityList->add(b);
    96105
     
    261270      entity->draw();
    262271    entity->drawBVTree(depth, drawMode);
    263     printf("%i, %i\n", depth, drawMode);
     272   // printf("%i, %i\n", depth, drawMode);
    264273    entity = iterator->nextElement();
    265274  }
  • trunk/src/subprojects/collision_detection/collision_test_entity.cc

    r7193 r7711  
    3131 *  creates an environment
    3232*/
    33 CollisionTestEntity::CollisionTestEntity () : WorldEntity()
     33CollisionTestEntity::CollisionTestEntity (const char* modelName) : WorldEntity()
    3434{
    3535  this->init();
    36   this->loadModel("models/ships/reaplow.obj");
    37   //  this->loadModel("models/ships/figther.obj");
     36  this->loadModel(modelName, 1.0f, 0, 10);
     37/*  this->buildObbTree(0);*/
    3838
    39   this->buildObbTree(10);
    4039}
    4140
     
    8180void CollisionTestEntity::tick (float time) {}
    8281
    83 
  • trunk/src/subprojects/collision_detection/collision_test_entity.h

    r7157 r7711  
    1919
    2020 public:
    21   CollisionTestEntity ();
     21  CollisionTestEntity (const char* modelName);
    2222  CollisionTestEntity (const TiXmlElement* root);
    2323  virtual ~CollisionTestEntity ();
  • trunk/src/subprojects/framework.cc

    r7256 r7711  
    3434  LightManager::getInstance();
    3535
    36   const char* dataPath;
    37   if ((dataPath = Preferences::getInstance()->getString(CONFIG_SECTION_DATA, CONFIG_NAME_DATADIR, ""))!= NULL)
     36  std::string dataPath = //Preferences::getInstance()->getString(CONFIG_SECTION_DATA, CONFIG_NAME_DATADIR, "");
     37      "/home/boenzlip/orxonox/data/trunk/";
     38  printf("%s\n", dataPath.c_str());
     39  if (!dataPath.empty())
    3840  {
    3941    if (!ResourceManager::getInstance()->setDataDir(dataPath))
     
    4850    PRINTF(1)("The DataDirectory %s could not be verified\n" \
    4951        "  Please Change in File %s Section %s Entry %s to a suitable value\n",
    50     ResourceManager::getInstance()->getDataDir(),
     52    ResourceManager::getInstance()->getDataDir().c_str(),
    5153    DEFAULT_CONFIG_FILE,
    5254    CONFIG_SECTION_DATA,
  • trunk/src/world_entities/environment.cc

    r7193 r7711  
    3737  this->init();
    3838  this->loadModel("models/ships/bolido.obj");
     39//   if(this->obbTree == NULL)
     40//     this->obbTree = new OBBTree(4, (sVec3D*)this->model->getVertexArray(), this->model->getVertexCount());
    3941}
    4042
  • trunk/src/world_entities/test_entity.cc

    r7488 r7711  
    4141{
    4242  this->init();
     43  this->md2Model = new MD2Model("models/droidika.md2", "models/droideka.pcx");
    4344}
    4445
     46
     47//   this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx");
     48// this->md2Model = new MD2Model("models/goblin.md2", "maps/goblin.bmp");
     49//   this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices);
    4550
    4651
  • trunk/src/world_entities/world_entity.cc

    r7230 r7711  
    3636SHELL_COMMAND(model, WorldEntity, loadModel)
    3737->describe("sets the Model of the WorldEntity")
    38 ->defaultValues("models/ships/fighter.obj", 1.0);
     38->defaultValues("models/ships/fighter.obj", 1.0f);
    3939
    4040SHELL_COMMAND(debugEntity, WorldEntity, debugWE);
     
    118118 * @param fileName the name of the model to load
    119119 * @param scaling the Scaling of the model
    120  */
    121 void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber)
     120 *
     121 * FIXME
     122 * @todo: separate the obb tree generation from the model
     123 */
     124void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber, unsigned int obbTreeDepth)
    122125{
    123126  this->modelLODName = fileName;
     
    154157
    155158      if( modelNumber == 0)
    156         this->buildObbTree(4);
     159        this->buildObbTree(obbTreeDepth);
    157160    }
    158161    else if(fileName.find(".md2") != std::string::npos)
     
    164167
    165168      if( m != NULL)
    166         this->buildObbTree(4);
     169        this->buildObbTree(obbTreeDepth);
    167170    }
    168171  }
     
    207210 * @param depth the depth to calculate
    208211 */
    209 bool WorldEntity::buildObbTree(unsigned int depth)
     212bool WorldEntity::buildObbTree(int depth)
    210213{
    211214  if (this->obbTree)
     
    214217  if (this->models[0] != NULL)
    215218  {
    216     PRINTF(4)("creating obb tree\n");
    217 
    218 
    219     this->obbTree = new OBBTree(depth, (sVec3D*)this->models[0]->getVertexArray(), this->models[0]->getVertexCount());
     219    this->obbTree = new OBBTree(depth, models[0]->getModelInfo(), this);
    220220    return true;
    221221  }
    222222  else
    223223  {
    224     PRINTF(2)("could not create obb-tree, because no model was loaded yet\n");
     224    PRINTF(1)("could not create obb-tree, because no model was loaded yet\n");
    225225    this->obbTree = NULL;
    226226    return false;
     
    468468 * @param drawMode the mode to draw this entity under
    469469 */
    470 void WorldEntity::drawBVTree(unsigned int depth, int drawMode) const
     470void WorldEntity::drawBVTree(int depth, int drawMode) const
    471471{
    472472  glMatrixMode(GL_MODELVIEW);
     
    480480  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    481481
     482
    482483  if (this->obbTree)
    483484    this->obbTree->drawBV(depth, drawMode);
     485
     486
    484487  glPopMatrix();
    485488}
     
    571574    std::string name = getModel( 0 )->getName();
    572575
    573     if (  name.find( ResourceManager::getInstance()->getDataDir() ) == 0 ) 
     576    if (  name.find( ResourceManager::getInstance()->getDataDir() ) == 0 )
    574577    {
    575578      name.erase(ResourceManager::getInstance()->getDataDir().size());
  • trunk/src/world_entities/world_entity.h

    r7460 r7711  
    22 * @file world_entity.h
    33 * Definition of the basic WorldEntity
    4 */
     4 */
    55
    66#ifndef _WORLD_ENTITY_H
     
    3535  virtual void loadParams(const TiXmlElement* root);
    3636
    37   void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0);
     37  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
    3838  void setModel(Model* model, unsigned int modelNumber = 0);
    3939  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
    4040
    4141  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
    42 
    43   bool buildObbTree(unsigned int depth);
    44   /** @returns a reference to the obb tree of this worldentity */
    45   BVTree* getOBBTree() const { return this->obbTree; };
    4642
    4743  /** @param visibility if the Entity should be visible (been draw) */
     
    5753
    5854  virtual void tick (float time);
    59 
    6055  virtual void draw () const;
    6156
     57  bool buildObbTree(int depth);
    6258  virtual void collidesWith (WorldEntity* entity, const Vector& location);
    63   void drawBVTree(unsigned int depth, int drawMode) const;
    64 
     59  /** @returns a reference to the obb tree of this worldentity */
     60  inline BVTree* getOBBTree() const { return this->obbTree; };
     61  void drawBVTree(int depth, int drawMode) const;
    6562
    6663  void debugWE() { this->debugEntity(); }
     
    7774
    7875  void toList(OM_LIST list);
     76
    7977
    8078  /** @returns a Reference to the objectListNumber to set. */
     
    10199  void setHealthMax(float healthMax);
    102100  void createHealthWidget();
     101
    103102  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
    104103private:
Note: See TracChangeset for help on using the changeset viewer.