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 | #include "abstract_model.h" |
---|
23 | |
---|
24 | #include <math.h> |
---|
25 | |
---|
26 | using namespace std; |
---|
27 | |
---|
28 | |
---|
29 | /** |
---|
30 | \brief standard constructor |
---|
31 | */ |
---|
32 | OBBTreeNode::OBBTreeNode () |
---|
33 | { |
---|
34 | this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); |
---|
35 | |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | /** |
---|
40 | \brief standard deconstructor |
---|
41 | |
---|
42 | */ |
---|
43 | OBBTreeNode::~OBBTreeNode () |
---|
44 | { |
---|
45 | // delete what has to be deleted here |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | \brief creates a new BVTree or BVTree partition |
---|
52 | \param depth: the depth of the tree |
---|
53 | \param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle |
---|
54 | */ |
---|
55 | void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length) |
---|
56 | { |
---|
57 | float facelet[length]; //!< surface area of the i'th triangle of the convex hull |
---|
58 | float face; //!< surface area of the entire convex hull |
---|
59 | Vector centroid[length]; //!< centroid of the i'th convex hull |
---|
60 | Vector centre; //!< the centre of the entire hull |
---|
61 | OBB* obb = new OBB(); //!< the new obb to add |
---|
62 | Vector p, q, r; //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d |
---|
63 | Vector t1, t2; //!< temporary values |
---|
64 | float covariance[3][3]; //!< the covariance matrix |
---|
65 | |
---|
66 | /* fist compute all the convex hull face/facelets and centroids */ |
---|
67 | for(int i = 0; i < length; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ |
---|
68 | { |
---|
69 | p = *(verticesList + i); |
---|
70 | q = *(verticesList + i + 1); |
---|
71 | r = *(verticesList + i + 2); |
---|
72 | |
---|
73 | t1 = p - q; t2 = p - r; |
---|
74 | |
---|
75 | /* finding the facelet surface via cross-product */ |
---|
76 | facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); |
---|
77 | /* update the entire convex hull surface */ |
---|
78 | face += facelet[i]; |
---|
79 | |
---|
80 | |
---|
81 | /* calculate the cetroid of the hull triangles */ |
---|
82 | centroid[i] = (p + q + r) * 1/3; |
---|
83 | /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ |
---|
84 | centre += centroid[i] * facelet[i]; |
---|
85 | } |
---|
86 | /* take the average of the centroid sum */ |
---|
87 | centre /= face; |
---|
88 | |
---|
89 | /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */ |
---|
90 | for(int j = 0; j < 3; ++j) |
---|
91 | { |
---|
92 | for(int k = 0; k < 3; ++k) |
---|
93 | { |
---|
94 | for(int i = 0; i < length; i+=3) |
---|
95 | { |
---|
96 | p = *(verticesList + i); |
---|
97 | q = *(verticesList + i + 1); |
---|
98 | r = *(verticesList + i + 2); |
---|
99 | |
---|
100 | covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] + |
---|
101 | q[j] * q[k] + r[j]*r[k]) - centre[j] * centre[k]; |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void OBBTreeNode::collideWith(const BVTree &tree) |
---|
109 | {} |
---|
110 | |
---|
111 | |
---|
112 | void OBBTreeNode::drawBV(int currentDepth, const int depth) const |
---|
113 | {} |
---|
114 | |
---|
115 | |
---|
116 | void OBBTreeNode::drawBVPolygon(int currentDepth, const int depth) const |
---|
117 | {} |
---|
118 | |
---|
119 | |
---|
120 | void OBBTreeNode::drawBVBlended(int currentDepth, const int depth) const |
---|
121 | {} |
---|