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_SPATIAL_SEPARATION |
---|
17 | |
---|
18 | #include "quadtree_node.h" |
---|
19 | #include "list.h" |
---|
20 | #include "vector.h" |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | * standard constructor |
---|
27 | */ |
---|
28 | QuadtreeNode::QuadtreeNode (sTriangleExt* triangles, int numTriangles, Quadtree* quadtree) |
---|
29 | { |
---|
30 | this->setClassID(CL_QUADTREE_NODE, "QuadtreeNode"); |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | /** |
---|
35 | * standard constructor |
---|
36 | */ |
---|
37 | QuadtreeNode::QuadtreeNode(modelInfo* pModelInfo) |
---|
38 | { |
---|
39 | this->pModelInfo = pModelInfo; |
---|
40 | this->pDimension = this->getDimension(this->pModelInfo); |
---|
41 | |
---|
42 | /* create an array of triangle references */ |
---|
43 | this->pTriangles = new sTriangleExt*[this->pModelInfo->numTriangles]; |
---|
44 | this->numTriangles = this->pModelInfo->numTriangles; |
---|
45 | this->pVertices = this->pModelInfo->pVertices; |
---|
46 | for( int i = 0; i < this->pModelInfo->numTriangles; ++i) |
---|
47 | this->pTriangles[i] = &this->pModelInfo->pTriangles[i]; |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * standard deconstructor |
---|
54 | |
---|
55 | */ |
---|
56 | QuadtreeNode::~QuadtreeNode () |
---|
57 | { |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | /** |
---|
62 | * gives the signal to separate the model into a quadtree |
---|
63 | * @param treeDepth the max depth, the steps to go if treeDept == 0 leaf reached |
---|
64 | */ |
---|
65 | void QuadtreeNode::separateNode(int treeDepth) |
---|
66 | {} |
---|
67 | |
---|
68 | |
---|
69 | /** |
---|
70 | * gives the signal to separate the model into a quadtree |
---|
71 | * @param treeDepth the max depth, the steps to go if treeDept == 0 leaf reached |
---|
72 | */ |
---|
73 | void QuadtreeNode::separateNode(float minLength) |
---|
74 | {} |
---|
75 | |
---|
76 | |
---|
77 | /** |
---|
78 | * gives the signal to separate the model into a quadtree |
---|
79 | * @param treeDepth the max depth, the steps to go if treeDept == 0 leaf reached |
---|
80 | */ |
---|
81 | void QuadtreeNode::separateNode() |
---|
82 | { |
---|
83 | tList<sTriangleExt*>* listA = new tList<sTriangleExt*>(); //!< triangle list of nodeA |
---|
84 | tList<sTriangleExt*>* listB = new tList<sTriangleExt*>(); //!< triangle list of nodeB |
---|
85 | tList<sTriangleExt*>* listC = new tList<sTriangleExt*>(); //!< triangle list of nodeC |
---|
86 | tList<sTriangleExt*>* listD = new tList<sTriangleExt*>(); //!< triangle list of nodeD |
---|
87 | const float* pVert; //!< pointer to the vertices |
---|
88 | const Vector* rectCenter; //!< vector to the center of the rect |
---|
89 | |
---|
90 | rectCenter = this->pDimension->getCenter(); |
---|
91 | for( int i = 0; i < this->numTriangles; ++i) |
---|
92 | { |
---|
93 | for( int j = 0; j < 3; ++j) |
---|
94 | { |
---|
95 | pVert = &this->pVertices[this->pTriangles[i]->indexToVertices[j]]; |
---|
96 | if( pVert[0] > rectCenter->x + this->offset && pVert[2] > rectCenter->z + this->offset) |
---|
97 | printf(""); |
---|
98 | |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | /** |
---|
105 | * draws the debug quadtree boxes around the model |
---|
106 | */ |
---|
107 | void QuadtreeNode::drawTree(int depth, int drawMode) const |
---|
108 | {} |
---|
109 | |
---|
110 | |
---|
111 | /** |
---|
112 | \brief gets the maximal dimension of a model |
---|
113 | * @param playerModel the model that this measurement is based on |
---|
114 | \return the dimension of the AbstractModel as a Rectangle |
---|
115 | |
---|
116 | The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the |
---|
117 | size of 999999.0, there probably will be some errors in the dimensions calculations. Write an email to |
---|
118 | patrick@orxonox.ethz.ch if you will ever encounter a model bigger than 999999.0 units, I will realy be |
---|
119 | happy to see orxonox used to extensivly :) |
---|
120 | */ |
---|
121 | Rectangle* QuadtreeNode::getDimension(modelInfo* pModelInfo) |
---|
122 | { |
---|
123 | float maxX, maxY; //!< the maximal coordinates axis |
---|
124 | float minX, minY; //!< minimal axis coorindates |
---|
125 | const float* pVertices; //!< pointer to the current vertices |
---|
126 | |
---|
127 | maxX = -999999; maxY = -999999; |
---|
128 | minX = 999999; minY = 999999; |
---|
129 | /* get maximal/minimal x/y */ |
---|
130 | for( int i = 0; i < pModelInfo->numVertices; ++i) |
---|
131 | { |
---|
132 | pVertices = &pModelInfo->pVertices[i * 3]; |
---|
133 | if( pVertices[0] > maxX) |
---|
134 | maxX = pVertices[0]; |
---|
135 | if( pVertices[2] > maxY) |
---|
136 | maxY = pVertices[2]; |
---|
137 | |
---|
138 | if( pVertices[0] < minX) |
---|
139 | minX = pVertices[0]; |
---|
140 | if( pVertices[2] < minY) |
---|
141 | minY = pVertices[2]; |
---|
142 | } |
---|
143 | |
---|
144 | Rectangle* rect = new Rectangle(); |
---|
145 | rect->setCenter((maxX + minX) / 2.0f, 0.0f, (maxY + minY) / 2.0f); /* this is little strange, since y is in opengl the up vector */ |
---|
146 | rect->setAxis(fmax(((fabs(maxX) + fabs(minX)) / 2.0f), ((fabs(maxY) + fabs(minY)) / 2.0f))); |
---|
147 | |
---|
148 | PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY); |
---|
149 | return rect; |
---|
150 | } |
---|
151 | |
---|