Browse Source

Created BoundingBox class

Thomas Buck 10 years ago
parent
commit
e116fe3fa3
9 changed files with 129 additions and 184 deletions
  1. 2
    0
      ChangeLog.md
  2. 1
    1
      include/Render.h
  3. 2
    2
      include/Room.h
  4. 13
    9
      include/RoomData.h
  5. 1
    48
      include/ViewVolume.h
  6. 1
    1
      src/Render.cpp
  7. 1
    1
      src/Room.cpp
  8. 108
    106
      src/RoomData.cpp
  9. 0
    16
      src/ViewVolume.cpp

+ 2
- 0
ChangeLog.md View File

8
       - Audio output optional, added Null Sound implementation
8
       - Audio output optional, added Null Sound implementation
9
       - Added support for getting home folder location in Windows
9
       - Added support for getting home folder location in Windows
10
       - Added support for recursively looking for level paks in Windows
10
       - Added support for recursively looking for level paks in Windows
11
+    * Removed unused BoundingVolume, Box, Sphere from ViewVolume,
12
+      split double used Box class into Box and BoundingBox.
11
 
13
 
12
     [ 20140505 ]
14
     [ 20140505 ]
13
     * Moved setup of Room, Portal, Box, Sector, ... into their
15
     * Moved setup of Room, Portal, Box, Sector, ... into their

+ 1
- 1
include/Render.h View File

146
      */
146
      */
147
     bool isVisible(float x, float y, float z, float radius);
147
     bool isVisible(float x, float y, float z, float radius);
148
 
148
 
149
-    bool isVisible(Box &box);
149
+    bool isVisible(BoundingBox &box);
150
 
150
 
151
     /*!
151
     /*!
152
      * \brief Renders a mesh.
152
      * \brief Renders a mesh.

+ 2
- 2
include/Room.h View File

24
     Room(TombRaider &tr, unsigned int index);
24
     Room(TombRaider &tr, unsigned int index);
25
     ~Room();
25
     ~Room();
26
 
26
 
27
-    Box &getBoundingBox();
27
+    BoundingBox &getBoundingBox();
28
     Mesh &getMesh();
28
     Mesh &getMesh();
29
     void display(bool alpha);
29
     void display(bool alpha);
30
 
30
 
64
     unsigned int numZSectors;
64
     unsigned int numZSectors;
65
     vec3_t pos;
65
     vec3_t pos;
66
 
66
 
67
-    Box bbox;
67
+    BoundingBox bbox;
68
     Mesh mesh;
68
     Mesh mesh;
69
 
69
 
70
     std::vector<int> adjacentRooms;
70
     std::vector<int> adjacentRooms;

+ 13
- 9
include/RoomData.h View File

14
 #include "math/Matrix.h"
14
 #include "math/Matrix.h"
15
 #include "TombRaider.h"
15
 #include "TombRaider.h"
16
 
16
 
17
+class BoundingBox {
18
+public:
19
+    BoundingBox();
20
+    void getBoundingBox(vec3_t box[2]);
21
+    void setBoundingBox(vec3_t min, vec3_t max);
22
+    void display(bool points, const vec4_t c1, const vec4_t c2);
23
+    bool inBox(vec_t x, vec_t y, vec_t z);
24
+    bool inBoxPlane(vec_t x, vec_t z);
25
+
26
+private:
27
+    vec3_t a, b;
28
+};
29
+
17
 class Light {
30
 class Light {
18
 public:
31
 public:
19
     /*!
32
     /*!
75
 
88
 
76
 class Box {
89
 class Box {
77
 public:
90
 public:
78
-    // For use as bounding box
79
-    Box();
80
-    void getBoundingBox(vec3_t box[2]);
81
-    void setBoundingBox(vec3_t min, vec3_t max);
82
-    void display(bool points, const vec4_t c1, const vec4_t c2);
83
-    bool inBox(vec_t x, vec_t y, vec_t z);
84
-    bool inBoxPlane(vec_t x, vec_t z);
85
-
86
-    // For use as box in rooms
87
     Box(TombRaider &tr, unsigned int room, unsigned int index);
91
     Box(TombRaider &tr, unsigned int room, unsigned int index);
88
 
92
 
89
 private:
93
 private:

+ 1
- 48
include/ViewVolume.h View File

9
 #define _VIEWVOLUME_H_
9
 #define _VIEWVOLUME_H_
10
 
10
 
11
 #include "math/Matrix.h"
11
 #include "math/Matrix.h"
12
-
13
-/*!
14
- * \brief Defines a 3D sphere.
15
- */
16
-class BoundingSphere {
17
-public:
18
-    vec3_t mCenter; //!< Center of bounding sphere
19
-    vec_t mRadius; //!< Raduis of bounding sphere
20
-};
21
-
22
-/*!
23
- * \brief Defines a 3D rectangle.
24
- */
25
-class BoundingBox {
26
-public:
27
-    vec3_t mMin; //!< Bounding box MIN point
28
-    vec3_t mMax; //!< Bounding box MAX point
29
-};
30
-
31
-/*!
32
- * \brief Defines a 3D sphere and/or rectangle.
33
- */
34
-class BoundingVolume {
35
-public:
36
-    BoundingSphere mSphere; //!< Bounding sphere of this volume
37
-    BoundingBox mBox; //!< Bounding box of this volume
38
-};
12
+#include "RoomData.h"
39
 
13
 
40
 /*!
14
 /*!
41
  * \brief Viewing Volume for culling use
15
  * \brief Viewing Volume for culling use
71
     ViewVolume();
45
     ViewVolume();
72
 
46
 
73
     /*!
47
     /*!
74
-     * \brief Check if bounding volume is in view volume
75
-     * \param bvol bounding volume to check
76
-     * \returns true if frustum contains the given bounding volume
77
-     */
78
-    bool isBoundingVolumeInFrustum(BoundingVolume bvol);
79
-
80
-    /*!
81
-     * \brief Check if bounding sphere is in view volume
82
-     * \param bvol bounding sphere to check
83
-     * \returns true if frustum contains the given bounding volume
84
-     */
85
-    bool isBoundingSphereInFrustum(BoundingSphere bvol);
86
-
87
-    /*!
88
-     * \brief Check if bounding box is in view volume
89
-     * \param bvol bounding box to check
90
-     * \returns true if frustum contains the given bounding volume
91
-     */
92
-    bool isBoundingBoxInFrustum(BoundingBox bvol);
93
-
94
-    /*!
95
      * \brief Check if point is in view volume
48
      * \brief Check if point is in view volume
96
      * \param x X coordinate of point
49
      * \param x X coordinate of point
97
      * \param y Y coordinate of point
50
      * \param y Y coordinate of point

+ 1
- 1
src/Render.cpp View File

1190
     mViewVolume.updateFrame(proj, mdl);
1190
     mViewVolume.updateFrame(proj, mdl);
1191
 }
1191
 }
1192
 
1192
 
1193
-bool Render::isVisible(Box &box) {
1193
+bool Render::isVisible(BoundingBox &box) {
1194
     vec3_t bbox[2];
1194
     vec3_t bbox[2];
1195
     box.getBoundingBox(bbox);
1195
     box.getBoundingBox(bbox);
1196
     // For debugging purposes
1196
     // For debugging purposes

+ 1
- 1
src/Room.cpp View File

602
     return *sprites.at(index);
602
     return *sprites.at(index);
603
 }
603
 }
604
 
604
 
605
-Box &Room::getBoundingBox() {
605
+BoundingBox &Room::getBoundingBox() {
606
     return bbox;
606
     return bbox;
607
 }
607
 }
608
 
608
 

+ 108
- 106
src/RoomData.cpp View File

16
 #include "main.h"
16
 #include "main.h"
17
 #include "RoomData.h"
17
 #include "RoomData.h"
18
 
18
 
19
+BoundingBox::BoundingBox() {
20
+    a[0] = a[1] = a[2] = 0;
21
+    b[0] = b[1] = b[2] = 0;
22
+}
23
+
24
+void BoundingBox::getBoundingBox(vec3_t box[2]) {
25
+    box[0][0] = a[0];
26
+    box[1][0] = b[0];
27
+    box[0][1] = a[1];
28
+    box[1][1] = b[1];
29
+    box[0][2] = a[2];
30
+    box[1][2] = b[2];
31
+}
32
+
33
+void BoundingBox::setBoundingBox(vec3_t min, vec3_t max) {
34
+    a[0] = min[0];
35
+    b[0] = max[0];
36
+    a[1] = min[1];
37
+    b[1] = max[1];
38
+    a[2] = min[2];
39
+    b[2] = max[2];
40
+}
41
+
42
+bool BoundingBox::inBox(vec_t x, vec_t y, vec_t z) {
43
+    return ((y > a[1]) && (y < b[1]) && inBoxPlane(x, z));
44
+}
45
+
46
+bool BoundingBox::inBoxPlane(vec_t x, vec_t z) {
47
+    return ((x > a[0]) && (x < b[0])
48
+            && (z > a[2]) && (z < b[2]));
49
+}
50
+
51
+void BoundingBox::display(bool points, const vec4_t c1, const vec4_t c2) {
52
+    // Bind before entering now
53
+    //glBindTexture(GL_TEXTURE_2D, 1);
54
+    glPointSize(4.0);
55
+    //glLineWidth(1.25);
56
+
57
+    //! \fixme Need to make custom color key for this
58
+    glColor3fv(c1);
59
+
60
+    glBegin(GL_POINTS);
61
+    glVertex3f(b[0], b[1], b[2]);
62
+    glVertex3f(a[0], a[1], a[2]);
63
+
64
+    if (points)
65
+    {
66
+        glVertex3f(b[0], a[1], b[2]);
67
+        glVertex3f(a[0], b[1], b[2]);
68
+        glVertex3f(b[0], b[1], a[2]);
69
+        glVertex3f(a[0], a[1], b[2]);
70
+        glVertex3f(a[0], b[1], a[2]);
71
+        glVertex3f(b[0], a[1], a[2]);
72
+    }
73
+
74
+    glEnd();
75
+
76
+    glColor3fv(c2);
77
+
78
+    glBegin(GL_LINES);
79
+    // max, top quad
80
+    glVertex3f(b[0], b[1], b[2]);
81
+    glVertex3f(b[0], a[1], b[2]);
82
+
83
+    glVertex3f(b[0], b[1], b[2]);
84
+    glVertex3f(a[0], b[1], b[2]);
85
+
86
+    glVertex3f(b[0], b[1], b[2]);
87
+    glVertex3f(b[0], b[1], a[2]);
88
+
89
+    // max-min, vertical quads
90
+    glVertex3f(a[0], b[1], b[2]);
91
+    glVertex3f(a[0], b[1], a[2]);
92
+
93
+    glVertex3f(b[0], a[1], b[2]);
94
+    glVertex3f(b[0], a[1], a[2]);
95
+
96
+    glVertex3f(b[0], a[1], b[2]);
97
+    glVertex3f(a[0], a[1], b[2]);
98
+
99
+    // min-max, vertical quads
100
+    glVertex3f(b[0], b[1], a[2]);
101
+    glVertex3f(b[0], a[1], a[2]);
102
+
103
+    glVertex3f(b[0], b[1], a[2]);
104
+    glVertex3f(a[0], b[1], a[2]);
105
+
106
+    glVertex3f(a[0], b[1], b[2]);
107
+    glVertex3f(a[0], a[1], b[2]);
108
+
109
+
110
+    // min, bottom quad
111
+    glVertex3f(a[0], a[1], a[2]);
112
+    glVertex3f(a[0], b[1], a[2]);
113
+
114
+    glVertex3f(a[0], a[1], a[2]);
115
+    glVertex3f(b[0], a[1], a[2]);
116
+
117
+    glVertex3f(a[0], a[1], a[2]);
118
+    glVertex3f(a[0], a[1], b[2]);
119
+    glEnd();
120
+
121
+    glPointSize(1.0);
122
+    //glLineWidth(1.0);
123
+}
124
+
125
+// ----------------------------------------------------------------------------
126
+
19
 Light::Light(TombRaider &tr, unsigned int room, unsigned int index) {
127
 Light::Light(TombRaider &tr, unsigned int room, unsigned int index) {
20
     unsigned int lightFlags, lightType;
128
     unsigned int lightFlags, lightType;
21
 
129
 
130
 
238
 
131
 // ----------------------------------------------------------------------------
239
 // ----------------------------------------------------------------------------
132
 
240
 
133
-Box::Box() {
134
-    a[0] = a[1] = a[2] = 0;
135
-    b[0] = b[1] = b[2] = 0;
136
-}
137
-
138
-void Box::getBoundingBox(vec3_t box[2]) {
139
-    box[0][0] = a[0];
140
-    box[1][0] = b[0];
141
-    box[0][1] = a[1];
142
-    box[1][1] = b[1];
143
-    box[0][2] = a[2];
144
-    box[1][2] = b[2];
145
-}
146
-
147
-void Box::setBoundingBox(vec3_t min, vec3_t max) {
148
-    a[0] = min[0];
149
-    b[0] = max[0];
150
-    a[1] = min[1];
151
-    b[1] = max[1];
152
-    a[2] = min[2];
153
-    b[2] = max[2];
154
-}
155
-
156
-bool Box::inBox(vec_t x, vec_t y, vec_t z) {
157
-    return ((y > a[1]) && (y < b[1]) && inBoxPlane(x, z));
158
-}
159
-
160
-bool Box::inBoxPlane(vec_t x, vec_t z) {
161
-    return ((x > a[0]) && (x < b[0])
162
-            && (z > a[2]) && (z < b[2]));
163
-}
164
-
165
-void Box::display(bool points, const vec4_t c1, const vec4_t c2) {
166
-    // Bind before entering now
167
-    //glBindTexture(GL_TEXTURE_2D, 1);
168
-    glPointSize(4.0);
169
-    //glLineWidth(1.25);
170
-
171
-    //! \fixme Need to make custom color key for this
172
-    glColor3fv(c1);
173
-
174
-    glBegin(GL_POINTS);
175
-    glVertex3f(b[0], b[1], b[2]);
176
-    glVertex3f(a[0], a[1], a[2]);
177
-
178
-    if (points)
179
-    {
180
-        glVertex3f(b[0], a[1], b[2]);
181
-        glVertex3f(a[0], b[1], b[2]);
182
-        glVertex3f(b[0], b[1], a[2]);
183
-        glVertex3f(a[0], a[1], b[2]);
184
-        glVertex3f(a[0], b[1], a[2]);
185
-        glVertex3f(b[0], a[1], a[2]);
186
-    }
187
-
188
-    glEnd();
189
-
190
-    glColor3fv(c2);
191
-
192
-    glBegin(GL_LINES);
193
-    // max, top quad
194
-    glVertex3f(b[0], b[1], b[2]);
195
-    glVertex3f(b[0], a[1], b[2]);
196
-
197
-    glVertex3f(b[0], b[1], b[2]);
198
-    glVertex3f(a[0], b[1], b[2]);
199
-
200
-    glVertex3f(b[0], b[1], b[2]);
201
-    glVertex3f(b[0], b[1], a[2]);
202
-
203
-    // max-min, vertical quads
204
-    glVertex3f(a[0], b[1], b[2]);
205
-    glVertex3f(a[0], b[1], a[2]);
206
-
207
-    glVertex3f(b[0], a[1], b[2]);
208
-    glVertex3f(b[0], a[1], a[2]);
209
-
210
-    glVertex3f(b[0], a[1], b[2]);
211
-    glVertex3f(a[0], a[1], b[2]);
212
-
213
-    // min-max, vertical quads
214
-    glVertex3f(b[0], b[1], a[2]);
215
-    glVertex3f(b[0], a[1], a[2]);
216
-
217
-    glVertex3f(b[0], b[1], a[2]);
218
-    glVertex3f(a[0], b[1], a[2]);
219
-
220
-    glVertex3f(a[0], b[1], b[2]);
221
-    glVertex3f(a[0], a[1], b[2]);
222
-
223
-
224
-    // min, bottom quad
225
-    glVertex3f(a[0], a[1], a[2]);
226
-    glVertex3f(a[0], b[1], a[2]);
227
-
228
-    glVertex3f(a[0], a[1], a[2]);
229
-    glVertex3f(b[0], a[1], a[2]);
230
-
231
-    glVertex3f(a[0], a[1], a[2]);
232
-    glVertex3f(a[0], a[1], b[2]);
233
-    glEnd();
234
-
235
-    glPointSize(1.0);
236
-    //glLineWidth(1.0);
237
-}
238
-
239
 Box::Box(TombRaider &tr, unsigned int room, unsigned int index) {
241
 Box::Box(TombRaider &tr, unsigned int room, unsigned int index) {
240
     tr.getRoomBox(room, index, a, b, c, d);
242
     tr.getRoomBox(room, index, a, b, c, d);
241
 }
243
 }

+ 0
- 16
src/ViewVolume.cpp View File

20
     mFrustum[5][0] = mFrustum[5][1] = mFrustum[5][2] = mFrustum[5][3] = 0.0f;
20
     mFrustum[5][0] = mFrustum[5][1] = mFrustum[5][2] = mFrustum[5][3] = 0.0f;
21
 }
21
 }
22
 
22
 
23
-bool ViewVolume::isBoundingVolumeInFrustum(BoundingVolume bvol) {
24
-    return (isBoundingSphereInFrustum(bvol.mSphere) &&
25
-            isBoundingBoxInFrustum(bvol.mBox));
26
-}
27
-
28
-bool ViewVolume::isBoundingSphereInFrustum(BoundingSphere bvol) {
29
-    return (isSphereInFrustum(bvol.mCenter[0],
30
-                bvol.mCenter[1],
31
-                bvol.mCenter[2],
32
-                bvol.mRadius));
33
-}
34
-
35
-bool ViewVolume::isBoundingBoxInFrustum(BoundingBox bvol) {
36
-    return (isBboxInFrustum(bvol.mMin, bvol.mMax));
37
-}
38
-
39
 bool ViewVolume::isPointInFrustum(vec_t x, vec_t y, vec_t z) {
23
 bool ViewVolume::isPointInFrustum(vec_t x, vec_t y, vec_t z) {
40
     for (unsigned int p = 0; p < 6; ++p) {
24
     for (unsigned int p = 0; p < 6; ++p) {
41
         if (mFrustum[p][0] * x + mFrustum[p][1] * y + mFrustum[p][2] * z +
25
         if (mFrustum[p][0] * x + mFrustum[p][1] * y + mFrustum[p][2] * z +

Loading…
Cancel
Save