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.h" |
---|
19 | #include "obb_tree_node.h" |
---|
20 | #include "obb.h" |
---|
21 | #include "debug.h" |
---|
22 | #include "compiler.h" |
---|
23 | #include "material.h" |
---|
24 | |
---|
25 | using namespace std; |
---|
26 | |
---|
27 | |
---|
28 | /** |
---|
29 | \brief standard constructor |
---|
30 | */ |
---|
31 | OBBTree::OBBTree () |
---|
32 | { |
---|
33 | this->setClassID(CL_OBB_TREE, "OBBTree"); |
---|
34 | |
---|
35 | material = new Material*[5]; |
---|
36 | for(int i = 0; i < 5; ++i) |
---|
37 | { |
---|
38 | material[i] = new Material(); |
---|
39 | material[i]->setIllum(3); |
---|
40 | } |
---|
41 | material[0]->setAmbient(0.0, 0.3, 0.0); |
---|
42 | material[1]->setAmbient(0.4, 0.0, 0.2); |
---|
43 | material[2]->setAmbient(1.0, 0.0, 0.0); |
---|
44 | material[3]->setAmbient(5.0, 3.0, 1.0); |
---|
45 | material[4]->setAmbient(1.0, 0.0, 7.0); |
---|
46 | |
---|
47 | |
---|
48 | transparentMaterial = new Material*[5]; |
---|
49 | for(int i = 0; i < 5; ++i) |
---|
50 | { |
---|
51 | transparentMaterial[i] = new Material(); |
---|
52 | transparentMaterial[i]->setIllum(3); |
---|
53 | transparentMaterial[i]->setTransparency(0.5); |
---|
54 | } |
---|
55 | transparentMaterial[0]->setAmbient(0.0, 0.3, 0.0); |
---|
56 | transparentMaterial[1]->setAmbient(0.4, 0.0, 0.2); |
---|
57 | transparentMaterial[2]->setAmbient(1.0, 0.0, 0.0); |
---|
58 | transparentMaterial[3]->setAmbient(5.0, 3.0, 1.0); |
---|
59 | transparentMaterial[4]->setAmbient(1.0, 0.0, 7.0); |
---|
60 | |
---|
61 | this->id = 0; |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | /** |
---|
66 | \brief standard deconstructor |
---|
67 | |
---|
68 | */ |
---|
69 | OBBTree::~OBBTree () |
---|
70 | { |
---|
71 | // delete what has to be deleted here |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | void OBBTree::spawnBVTree(int depth, sVec3D *verticesList, const int length) |
---|
76 | { |
---|
77 | if( unlikely(this->rootNode != NULL)) |
---|
78 | { |
---|
79 | PRINTF(2)("The BVTree has already been spawned, flushing and respawning again...\n"); |
---|
80 | this->flushTree(); |
---|
81 | } |
---|
82 | OBBTreeNode* node = new OBBTreeNode(); |
---|
83 | this->rootNode = node; |
---|
84 | this->rootNode->setTreeRef(this); |
---|
85 | this->rootNode->spawnBVTree(--depth, verticesList, length); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | void OBBTree:: flushTree() |
---|
90 | {} |
---|
91 | |
---|
92 | |
---|
93 | void OBBTree::collideWith(const OBBTree &tree) |
---|
94 | {} |
---|
95 | |
---|
96 | |
---|
97 | void OBBTree::drawBV(int depth, int drawMode) const |
---|
98 | { |
---|
99 | if( likely(this->rootNode != NULL)) |
---|
100 | { |
---|
101 | this->rootNode->drawBV(depth, drawMode); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | void OBBTree::debug() |
---|
108 | { |
---|
109 | PRINT(0)("\n==============================| OBBTree::debug() |===\n"); |
---|
110 | PRINT(0)("= Spawning Tree: Start\n"); |
---|
111 | |
---|
112 | /* generate some test vertices */ |
---|
113 | int const length = 9; |
---|
114 | sVec3D* vertList = new sVec3D[length]; |
---|
115 | // sVec3D data[length] = {{0.0, 0.0, 0.0},{1.0, 2.0, 5.0},{0.0, 6.0, 9.0}, |
---|
116 | // {1.0, 4.0, 12.0}, {1.0, 2.0, 16.0}, {0.0, 0.0, 19.0}, |
---|
117 | // {0.0, 3.0, 23.0}, {1.0, 5.0, 30.0}, {0.0, 10.0, 35.0}}; |
---|
118 | |
---|
119 | sVec3D data[length] = {{0.0, 0.0, 0.0},{1.0, 2.0, 5.0},{1.0, 5.0, 30.0}, |
---|
120 | {0.0, 3.0, 23.0}, {0.0, 6.0, 9.0}, {0.0, 10.0, 35.0}, |
---|
121 | {1.0, 4.0, 12.0}, {1.0, 2.0, 16.0}, {0.0, 0.0, 19.0}}; |
---|
122 | |
---|
123 | for(int i = 0; i < length; ++i) |
---|
124 | { |
---|
125 | vertList[i][0] = data[i][0]; |
---|
126 | vertList[i][1] = data[i][1]; |
---|
127 | vertList[i][2] = data[i][2]; |
---|
128 | } |
---|
129 | |
---|
130 | this->spawnBVTree(3, vertList, length); |
---|
131 | |
---|
132 | PRINT(0)("= Spawning Tree: Finished\n"); |
---|
133 | PRINT(0)("=======================================================\n"); |
---|
134 | |
---|
135 | } |
---|