2
Copyright (C) 2006 Parallel Realities
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include "../headers.h"
23
BoundingBox::BoundingBox()
31
plane[LEFT].normal.x = -1;
32
plane[LEFT].normal.y = 0;
33
plane[LEFT].normal.z = 0;
35
plane[RIGHT].normal.x = 1;
36
plane[RIGHT].normal.y = 0;
37
plane[RIGHT].normal.z = 0;
39
plane[TOP].normal.x = 0;
40
plane[TOP].normal.y = 1;
41
plane[TOP].normal.z = 0;
43
plane[BOTTOM].normal.x = 0;
44
plane[BOTTOM].normal.y = -1;
45
plane[BOTTOM].normal.z = 0;
47
plane[FRONT].normal.x = 0;
48
plane[FRONT].normal.y = 0;
49
plane[FRONT].normal.z = -1;
51
plane[BACK].normal.x = 0;
52
plane[BACK].normal.y = 0;
53
plane[BACK].normal.z = 1;
58
BoundingBox::~BoundingBox()
62
int BoundingBox::getSize()
66
size = max((int)mins.x, (int)maxs.x);
68
size = max((int)size, (int)mins.y);
69
size = max((int)size, (int)maxs.y);
71
size = max((int)size, (int)mins.z);
72
size = max((int)size, (int)maxs.z);
77
printf("ERROR: BoundingBox::getSize() - Size is %d. Must be > 0\n", size);
84
int BoundingBox::getDrawSize()
88
drawSize = getSize() * 250;
94
int BoundingBox::getHorizontalSize()
96
if (horizontalSize == -1)
98
horizontalSize = max((int)mins.x, (int)maxs.x);
100
horizontalSize = max((int)size, (int)mins.y);
101
horizontalSize = max((int)size, (int)maxs.y);
104
if (horizontalSize <= 0)
106
printf("ERROR: BoundingBox::getHorizontalSize() - Size is %d. Must be > 0\n", size);
110
return horizontalSize;
113
void BoundingBox::update(Vector position)
117
/* Calculate Distance for Left Face */
119
point1.x = position.x + mins.x;
120
point1.y = position.y + maxs.y;
121
point1.z = position.z + maxs.z;
123
plane[LEFT].d = Geometry::getPlaneDistance(plane[LEFT].normal, point1);
125
/* Calculate Distance for Right Face */
127
point1.x = position.x + maxs.x;
128
point1.y = position.y + maxs.y;
129
point1.z = position.z + mins.z;
131
plane[RIGHT].d = Geometry::getPlaneDistance(plane[RIGHT].normal, point1);
133
/* Calculate Distance for Top Face */
135
point1.x = position.x + mins.x;
136
point1.y = position.y + maxs.y;
137
point1.z = position.z + maxs.z;
139
plane[TOP].d = Geometry::getPlaneDistance(plane[TOP].normal, point1);
141
/* Calculate Distance for Bottom Face */
143
point1.x = position.x + mins.x;
144
point1.y = position.y + mins.y;
145
point1.z = position.z + maxs.z;
147
plane[BOTTOM].d = Geometry::getPlaneDistance(plane[BOTTOM].normal, point1);
149
/* Calculate Distance for Front Face */
151
point1.x = position.x + mins.x;
152
point1.y = position.y + maxs.y;
153
point1.z = position.z + mins.z;
155
plane[FRONT].d = Geometry::getPlaneDistance(plane[FRONT].normal, point1);
157
/* Calculate Distance for Back Face */
159
point1.x = position.x + maxs.x;
160
point1.y = position.y + maxs.y;
161
point1.z = position.z + maxs.z;
163
plane[BACK].d = Geometry::getPlaneDistance(plane[BACK].normal, point1);