Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: a collision is now marked with a white box, not yet fully functional, since there are mission some axis to check

File size: 3.8 KB
RevLine 
[4573]1/*
[4510]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:
[4511]12   main-programmer: Patrick Boenzli
[4510]13   co-programmer: ...
14*/
15
[4511]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
[4510]17
[4511]18#include "obb_tree.h"
[4550]19#include "obb_tree_node.h"
[4531]20#include "obb.h"
[4546]21#include "debug.h"
[4550]22#include "compiler.h"
[4616]23#include "material.h"
[4700]24#include "p_node.h"
[4510]25
26using namespace std;
27
28
29/**
30   \brief standard constructor
31*/
[4573]32OBBTree::OBBTree ()
[4510]33{
[4682]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{
[4616]47  this->setClassID(CL_OBB_TREE, "OBBTree");
[4622]48
[4638]49  material = new Material*[5];
50  for(int i = 0; i < 5; ++i)
[4622]51  {
52    material[i] = new Material();
[4638]53    material[i]->setIllum(3);
[4622]54  }
55  material[0]->setAmbient(0.0, 0.3, 0.0);
[4638]56  material[1]->setAmbient(0.4, 0.0, 0.2);
[4622]57  material[2]->setAmbient(1.0, 0.0, 0.0);
[4638]58  material[3]->setAmbient(5.0, 3.0, 1.0);
59  material[4]->setAmbient(1.0, 0.0, 7.0);
60
[4670]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);
[4671]67    transparentMaterial[i]->setTransparency(0.2);
[4670]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
[4702]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
[4638]80  this->id = 0;
[4510]81}
82
83/**
84   \brief standard deconstructor
85
86*/
[4573]87OBBTree::~OBBTree ()
[4510]88{
89  // delete what has to be deleted here
90}
[4528]91
92
[4551]93void OBBTree::spawnBVTree(int depth, sVec3D *verticesList, const int length)
[4531]94{
[4551]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;
[4622]102  this->rootNode->setTreeRef(this);
[4626]103  this->rootNode->spawnBVTree(--depth, verticesList, length);
[4531]104}
[4528]105
106
107void OBBTree:: flushTree()
108{}
109
110
[4700]111void OBBTree::collideWith(BVTree* tree, PNode* nodeA, PNode* nodeB)
[4695]112{
[4700]113  this->rootNode->collideWith(((OBBTree*)tree)->getRootNode(), nodeA, nodeB);
[4695]114}
[4528]115
116
[4635]117void OBBTree::drawBV(int depth, int drawMode) const
[4550]118{
119  if( likely(this->rootNode != NULL))
[4581]120  {
[4635]121    this->rootNode->drawBV(depth, drawMode);
[4581]122  }
[4550]123}
[4528]124
125
126
[4546]127void OBBTree::debug()
128{
129  PRINT(0)("\n==============================| OBBTree::debug() |===\n");
130  PRINT(0)("=  Spawning Tree: Start\n");
[4573]131
[4551]132  /* generate some test vertices */
[4638]133  int const length = 9;
[4589]134  sVec3D* vertList = new sVec3D[length];
[4668]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}};
[4551]138
[4668]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
[4589]143  for(int i = 0; i < length; ++i)
[4553]144    {
145      vertList[i][0] = data[i][0];
146      vertList[i][1] = data[i][1];
147      vertList[i][2] = data[i][2];
148    }
149
[4638]150  this->spawnBVTree(3, vertList, length);
[4551]151
[4546]152  PRINT(0)("=  Spawning Tree: Finished\n");
[4573]153  PRINT(0)("=======================================================\n");
[4546]154
155}
Note: See TracBrowser for help on using the repository browser.