Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc @ 4548

Last change on this file since 4548 was 4548, checked in by patrick, 19 years ago

orxonox/trunk: removed the fastmath lib once and for all

File size: 3.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
17
18#include "obb_tree_node.h"
19#include "list.h"
20#include "obb.h"
21#include "vector.h"
22
23#include <math.h>
24
25using namespace std;
26
27
28/**
29   \brief standard constructor
30*/
31OBBTreeNode::OBBTreeNode () 
32{
33   this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); 
34
35}
36
37
38/**
39   \brief standard deconstructor
40
41*/
42OBBTreeNode::~OBBTreeNode () 
43{
44  // delete what has to be deleted here
45}
46
47
48
49/**
50   \brief creates a new BVTree or BVTree partition
51   \param depth: the depth of the tree
52   \param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle
53*/
54void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length)
55{
56  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
57  float     face;                                    //!< surface area of the entire convex hull
58  Vector    centroid[length];                        //!< centroid of the i'th convex hull 
59  Vector    centre;                                  //!< the centre of the entire hull
60  OBB*      obb = new OBB();                         //!< the new obb to add
61  Vector    p, q, r;                                 //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d
62  Vector    t1, t2;                                  //!< temporary values
63  float     covariance[3][3];                        //!< the covariance matrix
64   
65  /* fist compute all the convex hull face/facelets and centroids */
66  for(int i = 0; i < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
67    {
68      p = *(verticesList + i);
69      q = *(verticesList + i + 1);
70      r = *(verticesList + i + 2);
71     
72      t1 = p - q; t2 = p - r;
73     
74      /* finding the facelet surface via cross-product */
75      facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
76      /* update the entire convex hull surface */
77      face += facelet[i];
78
79
80      /* calculate the cetroid of the hull triangles */
81      centroid[i] = (p + q + r) * 1/3;
82      /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
83      centre += centroid[i] * facelet[i];
84    }
85  /* take the average of the centroid sum */
86  centre /= face;
87 
88  /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
89  for(int j = 0; j < 3; ++j)
90    {
91      for(int k = 0; k < 3; ++k)
92        {
93          for(int i = 0; i < length; i+=3)
94            {
95              p = *(verticesList + i);
96              q = *(verticesList + i + 1);
97              r = *(verticesList + i + 2);
98
99              covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
100                                                                q[j] * q[k] + r[j]*r[k]) - centre[j] * centre[k];
101            }
102        }
103    }
104}
105
106
107void OBBTreeNode::collideWith(const BVTree &tree)
108{}
109
110
111void OBBTreeNode::drawBV(int currentDepth, const int depth) const
112{}
113
114
115void OBBTreeNode::drawBVPolygon(int currentDepth, const int depth) const
116{}
117
118
119void OBBTreeNode::drawBVBlended(int currentDepth, const int depth) const
120{}
Note: See TracBrowser for help on using the repository browser.