Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/collision_detection/obb_tree.cc @ 4861

Last change on this file since 4861 was 4836, checked in by bensch, 19 years ago

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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