Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4700 in orxonox.OLD for orxonox/trunk/src/lib/collision_detection


Ignore:
Timestamp:
Jun 26, 2005, 12:37:38 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: 3 axis get checked:) 12 to go…

Location:
orxonox/trunk/src/lib/collision_detection
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/collision_detection/bv_tree.h

    r4695 r4700  
    1515class BoundingVolume;
    1616class BVTreeNode;
     17class PNode;
    1718
    1819typedef enum DrawMode
     
    3940  virtual void flushTree() = NULL;
    4041
    41   virtual void collideWith(BVTree* tree) = NULL;
     42  virtual void collideWith(BVTree* tree, PNode* nodeA, PNode* nodeB) = NULL;
    4243
    4344  virtual void drawBV(int depth, int drawMode) const = NULL;
  • orxonox/trunk/src/lib/collision_detection/bv_tree_node.h

    r4695 r4700  
    1414class BoundingVolume;
    1515class BVTree;
    16 //struct sVec3D;
     16class PNode;
    1717template<class T> class tList;
    1818
     
    2929  inline const int getIndex() { return this->treeIndex; }
    3030
    31   virtual void collideWith(BVTreeNode* treeNode) = NULL;
     31  virtual void collideWith(BVTreeNode* treeNode, PNode* nodeA, PNode* nodeB) = NULL;
    3232
    3333  virtual void drawBV(int depth, int drawMode) const = NULL;
  • orxonox/trunk/src/lib/collision_detection/obb_tree.cc

    r4696 r4700  
    2222#include "compiler.h"
    2323#include "material.h"
     24#include "p_node.h"
    2425
    2526using namespace std;
     
    103104
    104105
    105 void OBBTree::collideWith(BVTree* tree)
     106void OBBTree::collideWith(BVTree* tree, PNode* nodeA, PNode* nodeB)
    106107{
    107   this->rootNode->collideWith(((OBBTree*)tree)->getRootNode());
     108  this->rootNode->collideWith(((OBBTree*)tree)->getRootNode(), nodeA, nodeB);
    108109}
    109110
  • orxonox/trunk/src/lib/collision_detection/obb_tree.h

    r4696 r4700  
    1414class Material;
    1515class OBBTreeNode;
     16class PNode;
    1617
    1718//! A class for representing an obb tree
     
    2728    virtual void flushTree();
    2829
    29     virtual void collideWith(BVTree* tree);
     30    virtual void collideWith(BVTree* tree, PNode* nodeA, PNode* nodeB);
    3031
    3132    virtual void drawBV(int depth, int drawMode) const;
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc

    r4696 r4700  
    2222#include "vector.h"
    2323#include "abstract_model.h"
     24#include "p_node.h"
    2425
    2526#include <math.h>
     
    604605
    605606
    606 void OBBTreeNode::collideWith(BVTreeNode* treeNode)
    607 {
    608   PRINTF(0)("collideWith");
     607void OBBTreeNode::collideWith(BVTreeNode* treeNode, PNode* nodeA, PNode* nodeB)
     608{
     609  PRINTF(0)("collideWith\n");
    609610  /* if the obb overlap, make subtests: check which node is realy overlaping  */
    610   if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement))
     611  if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
    611612  {
    612613    /* check if left node overlaps */
    613614    if( unlikely( this->nodeLeft != NULL))
    614       if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement))
    615         this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft);
     615      if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
     616        this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);
    616617    /* check if right node overlaps */
    617618    if( unlikely( this->nodeRight != NULL))
    618       if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement))
    619         this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight);
    620   }
    621 }
    622 
    623 
    624 
    625 bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB)
    626 {
     619      if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
     620        this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);
     621  }
     622}
     623
     624
     625
     626bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, PNode* nodeA, PNode* nodeB)
     627{
     628 
     629 
    627630  /* first check all axis */
    628   float r = 0.0f;
    629   Vector l = boxA->axis[0];
    630   for(int i = 0; i < 3; ++i)
    631   {
    632     r += boxA->halfLength[i] * boxA->axis[i].dot(l);
    633   }
    634 
    635   printf("r = %f\n", r);
    636   /* now check all orthogonals from the axis */
     631  Vector t = nodeA->getAbsCoor() + *boxA->center - ( nodeB->getAbsCoor() + *boxB->center);
     632  float rA = 0.0f;
     633  float rB = 0.0f;
     634  Vector l;
     635
     636  for(int j = 0; j < 3; ++j)
     637    {
     638      rA = 0.0f;
     639      rB = 0.0f;
     640      l = boxA->axis[j];
     641
     642      for(int i = 0; i < 3; ++i)
     643        {
     644          rA += fabs(boxA->halfLength[i] * boxA->axis[i].dot(l));
     645        }
     646 
     647      for(int i = 0; i < 3; ++i)
     648        {
     649          rB += fabs(boxB->halfLength[i] * boxB->axis[i].dot(l));
     650        }
     651 
     652      PRINTF(0)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
     653
     654      if( (rA + rB) < fabs(t.dot(l)))
     655        PRINTF(0)(" - The Boxes are disjoint!\n");
     656      else
     657        PRINTF(0)(" - The Boxes are not disjoint\n");
     658 
     659      PRINTF(0)("rA = %f, rB = %f\n", rA, rB);
     660
     661
     662      /* now check all orthogonals from the axis */
     663
     664    }
     665  return false;
    637666}
    638667
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.h

    r4695 r4700  
    1717class OBBTree;
    1818class Plane;
     19class PNode;
    1920//struct sVec3D;
    2021
     
    3334    inline void setTreeRef(OBBTree* tree) { this->obbTree = tree;}
    3435
    35     virtual void collideWith(BVTreeNode* treeNode);
     36    virtual void collideWith(BVTreeNode* treeNode, PNode* nodeA, PNode* nodeB);
    3637
    3738    virtual void drawBV(int depth, int drawMode) const;
     
    4546    void forkBox(OBB* box);
    4647
    47     bool overlapTest(OBB* boxA, OBB* boxB);
     48    bool overlapTest(OBB* boxA, OBB* boxB, PNode* nodeA, PNode* nodeB);
    4849
    4950  protected:
Note: See TracChangeset for help on using the changeset viewer.