Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: calculating dimension of an object. not linking now

File size: 3.5 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 "spatial_separation.h"
19#include "abstract_model.h"
20#include "quadtree.h"
21
22using namespace std;
23
24
25/**
26 *  standard constructor
27 * @param model the model that is to be separated
28 * @param overlapSize each box will overlap for a given size
29
30   The boxes are overlaping because this makes collision detection a lot simpler
31
32*/
33SpatialSeparation::SpatialSeparation (AbstractModel* model, float overlapSize)
34{
35   this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");
36
37}
38
39/**
40 *  standard constructor
41 * @param model the model that is to be separated
42 * @param overlapSize each box will overlap for a given size
43
44   The boxes are overlaping because this makes collision detection a lot simpler
45
46 */
47SpatialSeparation::SpatialSeparation (AbstractModel* model, AbstractModel* playerModel)
48{
49  this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");
50
51}
52
53
54/**
55 *  standard deconstructor
56
57*/
58SpatialSeparation::~SpatialSeparation ()
59{
60}
61
62
63/**
64  \brief creates a quadtree
65* @param model the model to do a quadtree on
66* @param minLength the minimal length of a quadtree node
67  \return the new quadtree
68 */
69Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model, float minLength)
70{
71  this->minLength = minLength;
72
73}
74
75
76/**
77  \brief creates a quadtree
78* @param model the model to do a quadtree on
79* @param minLength the minimal length of a quadtree node
80  \return the new quadtree
81 */
82Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model, int treeDepth)
83{
84  this->treeDepth = treeDepth;
85}
86
87
88/**
89  \brief creates a quadtree
90* @param model the model to do a quadtree on
91* @param minLength the minimal length of a quadtree node
92  \return the new quadtree
93*/
94Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model)
95{
96  this->quadtree = new Quadtree(model->getModelInfo());
97  this->quadtree->separate();
98
99  return this->quadtree;
100}
101
102
103/**
104  \brief gets the maximal dimension of a model
105* @param playerModel the model that this measurement is based on
106  \return the dimension of the AbstractModel as a Rectangle
107
108  The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the
109  size of 999999.0, there probably will be some errors in the dimensions calculations.
110 */
111Rectangle* SpatialSeparation::getDimension(AbstractModel* playerModel)
112{
113  float            maxX, maxY;                       //!< the maximal coordinates axis
114  float            minX, minY;                       //!< minimal axis coorindates
115  const float*     pVertices;                        //!< pointer to the current vertices
116
117  maxX = -999999; maxY = -999999;
118  minX =  999999; minY =  999999;
119  /* get maximal/minimal x/y */
120  for( int i = 0; i < playerModel->getModelInfo()->numVertices; ++i)
121  {
122    pVertices = &playerModel->getModelInfo()->pVertices[i * 3];
123    if( pVertices[0] > maxX)
124      maxX = pVertices[0];
125    if( pVertices[2] > maxY)
126      maxY = pVertices[2];
127
128    if( pVertices[0] < minX)
129      minX = pVertices[0];
130    if( pVertices[2] < minY)
131      minY = pVertices[2];
132
133    PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY);
134  }
135}
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Note: See TracBrowser for help on using the repository browser.