~ubuntu-branches/ubuntu/oneiric/blobandconquer/oneiric

« back to all changes in this revision

Viewing changes to src/3d/CBoundingBox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Guus Sliepen
  • Date: 2008-06-15 12:04:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080615120429-5ss7cbb4z9mpywj5
Tags: 0.95-1
New upstream release. Closes: #486310

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Copyright (C) 2006 Parallel Realities
3
 
 
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.
8
 
 
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.
12
 
 
13
 
See the GNU General Public License for more details.
14
 
 
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.
18
 
 
19
 
*/
20
 
 
21
 
#include "../headers.h"
22
 
 
23
 
BoundingBox::BoundingBox()
24
 
{
25
 
        size = -1;
26
 
        
27
 
        horizontalSize = -1;
28
 
        
29
 
        drawSize = -1;
30
 
        
31
 
        plane[LEFT].normal.x   = -1;
32
 
        plane[LEFT].normal.y   =  0;
33
 
        plane[LEFT].normal.z   =  0;
34
 
 
35
 
        plane[RIGHT].normal.x  =  1;
36
 
        plane[RIGHT].normal.y  =  0;
37
 
        plane[RIGHT].normal.z  =  0;
38
 
 
39
 
        plane[TOP].normal.x    =  0;
40
 
        plane[TOP].normal.y    =  1;
41
 
        plane[TOP].normal.z    =  0;
42
 
 
43
 
        plane[BOTTOM].normal.x =  0;
44
 
        plane[BOTTOM].normal.y = -1;
45
 
        plane[BOTTOM].normal.z =  0;
46
 
 
47
 
        plane[FRONT].normal.x  =  0;
48
 
        plane[FRONT].normal.y  =  0;
49
 
        plane[FRONT].normal.z  = -1;
50
 
 
51
 
        plane[BACK].normal.x   =  0;
52
 
        plane[BACK].normal.y   =  0;
53
 
        plane[BACK].normal.z   =  1;
54
 
 
55
 
        boxType = BOX_SOLID;
56
 
}
57
 
 
58
 
BoundingBox::~BoundingBox()
59
 
{
60
 
}
61
 
 
62
 
int BoundingBox::getSize()
63
 
{
64
 
        if (size == -1)
65
 
        {
66
 
                size = max((int)mins.x, (int)maxs.x);
67
 
                
68
 
                size = max((int)size, (int)mins.y);
69
 
                size = max((int)size, (int)maxs.y);
70
 
                
71
 
                size = max((int)size, (int)mins.z);
72
 
                size = max((int)size, (int)maxs.z);
73
 
        }
74
 
        
75
 
        if (size <= 0)
76
 
        {
77
 
                printf("ERROR: BoundingBox::getSize() - Size is %d. Must be > 0\n", size);
78
 
                //abort();
79
 
        }
80
 
        
81
 
        return size;
82
 
}
83
 
 
84
 
int BoundingBox::getDrawSize()
85
 
{
86
 
        if (drawSize == -1)
87
 
        {
88
 
                drawSize = getSize() * 250;
89
 
        }
90
 
        
91
 
        return drawSize;
92
 
}
93
 
 
94
 
int BoundingBox::getHorizontalSize()
95
 
{
96
 
        if (horizontalSize == -1)
97
 
        {
98
 
                horizontalSize = max((int)mins.x, (int)maxs.x);
99
 
                
100
 
                horizontalSize = max((int)size, (int)mins.y);
101
 
                horizontalSize = max((int)size, (int)maxs.y);
102
 
        }
103
 
        
104
 
        if (horizontalSize <= 0)
105
 
        {
106
 
                printf("ERROR: BoundingBox::getHorizontalSize() - Size is %d. Must be > 0\n", size);
107
 
                //abort();
108
 
        }
109
 
        
110
 
        return horizontalSize;
111
 
}
112
 
 
113
 
void BoundingBox::update(Vector position)
114
 
{
115
 
        Vector point1;
116
 
 
117
 
        /* Calculate Distance for Left Face */
118
 
 
119
 
        point1.x = position.x + mins.x;
120
 
        point1.y = position.y + maxs.y;
121
 
        point1.z = position.z + maxs.z;
122
 
 
123
 
        plane[LEFT].d = Geometry::getPlaneDistance(plane[LEFT].normal, point1);
124
 
 
125
 
        /* Calculate Distance for Right Face */
126
 
 
127
 
        point1.x = position.x + maxs.x;
128
 
        point1.y = position.y + maxs.y;
129
 
        point1.z = position.z + mins.z;
130
 
 
131
 
        plane[RIGHT].d = Geometry::getPlaneDistance(plane[RIGHT].normal, point1);
132
 
 
133
 
        /* Calculate Distance for Top Face */
134
 
 
135
 
        point1.x = position.x + mins.x;
136
 
        point1.y = position.y + maxs.y;
137
 
        point1.z = position.z + maxs.z;
138
 
 
139
 
        plane[TOP].d = Geometry::getPlaneDistance(plane[TOP].normal, point1);
140
 
 
141
 
        /* Calculate Distance for Bottom Face */
142
 
 
143
 
        point1.x = position.x + mins.x;
144
 
        point1.y = position.y + mins.y;
145
 
        point1.z = position.z + maxs.z;
146
 
 
147
 
        plane[BOTTOM].d = Geometry::getPlaneDistance(plane[BOTTOM].normal, point1);
148
 
 
149
 
        /* Calculate Distance for Front Face */
150
 
 
151
 
        point1.x = position.x + mins.x;
152
 
        point1.y = position.y + maxs.y;
153
 
        point1.z = position.z + mins.z;
154
 
 
155
 
        plane[FRONT].d = Geometry::getPlaneDistance(plane[FRONT].normal, point1);
156
 
 
157
 
        /* Calculate Distance for Back Face */
158
 
 
159
 
        point1.x = position.x + maxs.x;
160
 
        point1.y = position.y + maxs.y;
161
 
        point1.z = position.z + maxs.z;
162
 
 
163
 
        plane[BACK].d = Geometry::getPlaneDistance(plane[BACK].normal, point1);
164
 
}