Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc @ 4915

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

oxonox/trunk: now swapping the coordinates

File size: 3.0 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_SPATIAL_SEPARATION
17
18#include "quadtree.h"
19#include "quadtree_node.h"
20#include "material.h"
21
22using namespace std;
23
24
25/**
26 *  standard constructor
27   @todo this constructor is not jet implemented - do it
28*/
29Quadtree::Quadtree (modelInfo* pModelInfo, const int treeDepth)
30{
31   this->setClassID(CL_QUADTREE, "Quadtree");
32   this->pModelInfo = pModelInfo;
33   this->treeDepth = treeDepth;
34
35   /* initialize the materials for debug draw */
36   this->materials = new Material*[4];
37   for(int i = 0; i < 4; ++i)
38   {
39     materials[i] = new Material();
40     materials[i]->setIllum(3);
41   }
42   materials[0]->setAmbient(0.0, 0.3, 0.0);
43   materials[1]->setAmbient(0.4, 0.0, 0.2);
44   materials[2]->setAmbient(1.0, 0.0, 0.0);
45   materials[3]->setAmbient(5.0, 3.0, 1.0);
46
47   /* build the tree */
48   this->rootNode = new QuadtreeNode(this->pModelInfo, this, this->treeDepth);
49
50   /* make an array with access to the leafs of the Quad-Tree */
51   this->nodes = new QuadtreeNode*[(int)pow(4, treeDepth)];
52   int* index = new int; *index = 0;
53   for(int i = 0; i < (int)pow(2, treeDepth); ++i)
54   {
55     printf("============================\n");
56     this->rootNode->buildHashTable(this->nodes, index);
57   }
58}
59
60
61/**
62 *  standard deconstructor
63
64*/
65Quadtree::~Quadtree ()
66{
67  // delete what has to be deleted here
68  delete [] this->nodes;
69  delete this->rootNode;
70}
71
72
73/**
74
75  since the original matrix is counted from the right upper edge to the right lower one, we have to reorganize the elements
76  to be able to easily correlate the hashtable array indexes with the coorindates.
77 */
78void Quadtree::revertHashTable(QuadtreeNode** nodes)
79{
80  int                  len         = (int)pow(2, this->treeDepth);          //!< the length of a quadtree side
81  int                  iterator    = 0;                                     //!< iterator used for mapping
82  QuadtreeNode*        tmpNode     = NULL;                                  //!< temp saving place
83  int                  offset      = 0;                                     //!< offset used in the calc
84
85  for(int i = len - 1; i >= 0; --i)
86  {
87    for(int j = len - 1; j >= 0; --j)
88    {
89      offset = j * len + i;
90      /* only swap the elements in one direction */
91      if( offset > iterator)
92      {
93        tmpNode = nodes[offset];
94        nodes[offset] = nodes[iterator];
95        nodes[iterator] = tmpNode;
96      }
97      ++iterator;
98    }
99  }
100}
101
102
103/**
104 *  draws the debug quadtree boxes around the model
105 */
106void Quadtree::drawTree(int depth, int drawMode) const
107{
108  //this->rootNode->drawTree(depth, drawMode);
109  for(int i = 0; i < (int)pow(4, this->treeDepth); ++i)
110  {
111    this->nodes[i]->drawTree(0, 0);
112  }
113
114
115}
Note: See TracBrowser for help on using the repository browser.