浏览代码

Using Box as BoundingBox

Thomas Buck 10 年前
父节点
当前提交
b8794b216d
共有 9 个文件被更改,包括 250 次插入315 次删除
  1. 2
    0
      ChangeLog.md
  2. 16
    36
      include/Render.h
  3. 9
    11
      include/Room.h
  4. 9
    0
      include/RoomData.h
  5. 0
    51
      src/Command.cpp
  6. 15
    193
      src/Render.cpp
  7. 90
    21
      src/Room.cpp
  8. 106
    0
      src/RoomData.cpp
  9. 3
    3
      src/World.cpp

+ 2
- 0
ChangeLog.md 查看文件

@@ -6,6 +6,8 @@
6 6
     * Moved setup of Room, Portal, Box, Sector, ... into their
7 7
       Constructors.
8 8
     * Fixed menu play button
9
+    * Removed Render flags fSprite, fRoomModel, fPortals
10
+    * Room BoundingBox now using Box object
9 11
 
10 12
     [ 20140504 ]
11 13
     * Forcing use of new Room and Sprite classes in World.

+ 16
- 36
include/Render.h 查看文件

@@ -19,6 +19,7 @@
19 19
 #include "Mesh.h"
20 20
 #include "Texture.h"
21 21
 #include "Camera.h"
22
+#include "RoomData.h"
22 23
 
23 24
 /*!
24 25
  * \brief OpenRaider Renderer class
@@ -36,21 +37,18 @@ public:
36 37
     } RenderMode;
37 38
 
38 39
     typedef enum {
39
-        fPortals                = (1 << 0),
40
-        fRoomAlpha              = (1 << 1),
41
-        fViewModel              = (1 << 2),
42
-        fSprites                = (1 << 3),
43
-        fRoomModels             = (1 << 4),
44
-        fEntityModels           = (1 << 5),
45
-        fFog                    = (1 << 6),
46
-        fUsePortals             = (1 << 7),
47
-        fGL_Lights              = (1 << 8),
48
-        fOneRoom                = (1 << 9),
49
-        fRenderPonytail         = (1 << 10),
50
-        // fMultiTexture           = (1 << 11), //! \todo Whats up with Multitexture stuff? Where is it needed?
51
-        fUpdateRoomListPerFrame = (1 << 12),
52
-        fAnimateAllModels       = (1 << 13),
53
-        fAllRooms               = (1 << 14)
40
+        fRoomAlpha              = (1 << 0),
41
+        fViewModel              = (1 << 1),
42
+        fEntityModels           = (1 << 2),
43
+        fFog                    = (1 << 3),
44
+        fUsePortals             = (1 << 4),
45
+        fGL_Lights              = (1 << 5),
46
+        fOneRoom                = (1 << 6),
47
+        fRenderPonytail         = (1 << 7),
48
+        // fMultiTexture           = (1 << 8), //! \todo Whats up with Multitexture stuff? Where is it needed?
49
+        fUpdateRoomListPerFrame = (1 << 9),
50
+        fAnimateAllModels       = (1 << 10),
51
+        fAllRooms               = (1 << 11)
54 52
     } RenderFlags;
55 53
 
56 54
     /*!
@@ -130,14 +128,6 @@ public:
130 128
     unsigned int getFlags();
131 129
 
132 130
     /*!
133
-     * \brief Check if a bounding box is in the View Volume
134
-     * \param bboxMin Start coordinates of a valid bounding box
135
-     * \param bboxMax End coordinates of a valid bounding box
136
-     * \returns true if bounding box is visible
137
-     */
138
-    bool isVisible(float bboxMin[3], float bboxMax[3]);
139
-
140
-    /*!
141 131
      * \brief Check if a point is in the View Volume
142 132
      * \param x X coordinate
143 133
      * \param y Y coordinate
@@ -156,6 +146,8 @@ public:
156 146
      */
157 147
     bool isVisible(float x, float y, float z, float radius);
158 148
 
149
+    bool isVisible(Box &box);
150
+
159 151
     /*!
160 152
      * \brief Renders a mesh.
161 153
      *
@@ -168,6 +160,7 @@ public:
168 160
 
169 161
     ViewVolume mViewVolume; //!< View Volume for frustum culling
170 162
     std::vector<SkeletalModel *> mModels;
163
+    Texture mTexture;                     //!< Texture subsystem
171 164
 
172 165
 private:
173 166
 
@@ -210,17 +203,6 @@ private:
210 203
     void drawModel(SkeletalModel *model);
211 204
 
212 205
     /*!
213
-     * Renders a room in 2 seperate passes to handle alpha.
214
-     *
215
-     * Currently doesnt sort alpha but looks pretty good.
216
-     * Texture must be initialized.
217
-     * Draw all rooms with alpha false, then again with alpha true.
218
-     * \param rRoom room to render
219
-     * \param draw_alpha once false, once true
220
-     */
221
-    void drawRoom(Room &rRoom, bool draw_alpha);
222
-
223
-    /*!
224 206
      * \brief Updates View Volume. Call once per render frame.
225 207
      */
226 208
     void updateViewVolume();
@@ -228,8 +210,6 @@ private:
228 210
     //! \fixme Let them eat cake...? O.o
229 211
     void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
230 212
 
231
-    Texture mTexture;                     //!< Texture subsystem
232
-
233 213
     std::vector<Room *> mRoomRenderList;
234 214
 
235 215
     unsigned int mFlags;                  //!< Rendering flags

+ 9
- 11
include/Room.h 查看文件

@@ -24,18 +24,16 @@ public:
24 24
     Room(TombRaider &tr, unsigned int index);
25 25
     ~Room();
26 26
 
27
-    void setFlags(unsigned int f);
28
-    unsigned int getFlags();
27
+    Box &getBoundingBox();
28
+    Mesh &getMesh();
29
+    void display(bool alpha);
29 30
 
30 31
     unsigned int getNumXSectors();
31
-
32 32
     unsigned int getNumZSectors();
33
-
34 33
     void getPos(vec3_t p);
35 34
 
36
-    void getBoundingBox(vec3_t box[2]);
37
-    bool inBox(vec_t x, vec_t y, vec_t z);
38
-    bool inBoxPlane(vec_t x, vec_t z);
35
+    void setFlags(unsigned int f);
36
+    unsigned int getFlags();
39 37
 
40 38
     unsigned int sizeAdjacentRooms();
41 39
     int getAdjacentRoom(unsigned int index);
@@ -51,7 +49,6 @@ public:
51 49
 
52 50
     unsigned int sizeModels();
53 51
     StaticModel &getModel(unsigned int index);
54
-    void sortModels();
55 52
 
56 53
     unsigned int sizeLights();
57 54
     Light &getLight(unsigned int index);
@@ -59,14 +56,15 @@ public:
59 56
     unsigned int sizeSprites();
60 57
     Sprite &getSprite(unsigned int index);
61 58
 
62
-    Mesh &getMesh();
63
-
64 59
 private:
60
+    void sortModels();
61
+
65 62
     unsigned int flags;
66 63
     unsigned int numXSectors;
67 64
     unsigned int numZSectors;
68 65
     vec3_t pos;
69
-    vec3_t bbox[2];
66
+
67
+    Box bbox;
70 68
     Mesh mesh;
71 69
 
72 70
     std::vector<int> adjacentRooms;

+ 9
- 0
include/RoomData.h 查看文件

@@ -75,6 +75,15 @@ private:
75 75
 
76 76
 class Box {
77 77
 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
78 87
     Box(TombRaider &tr, unsigned int room, unsigned int index);
79 88
 
80 89
 private:

+ 0
- 51
src/Command.cpp 查看文件

@@ -299,22 +299,6 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
299 299
             getConsole().print("Invalid use of ralpha-command!");
300 300
             return -25;
301 301
         }
302
-    } else if (strcmp(command, "portal") == 0) {
303
-        if (args->size() > 0) {
304
-            bool b;
305
-            if (readBool(args->at(0), &b) < 0) {
306
-                getConsole().print("Pass BOOL to portal command!");
307
-                return -26;
308
-            }
309
-            if (b)
310
-                getRender().setFlags(Render::fPortals);
311
-            else
312
-                getRender().clearFlags(Render::fPortals);
313
-            getConsole().print("Portals are now %s", b ? "on" : "off");
314
-        } else {
315
-            getConsole().print("Invalid use of portal-command!");
316
-            return -27;
317
-        }
318 302
     } else if (strcmp(command, "vis") == 0) {
319 303
         if (args->size() > 0) {
320 304
             bool b;
@@ -347,38 +331,6 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
347 331
             getConsole().print("Invalid use of upf-command!");
348 332
             return -31;
349 333
         }
350
-    } else if (strcmp(command, "sprite") == 0) {
351
-        if (args->size() > 0) {
352
-            bool b;
353
-            if (readBool(args->at(0), &b) < 0) {
354
-                getConsole().print("Pass BOOL to sprite command!");
355
-                return -34;
356
-            }
357
-            if (b)
358
-                getRender().setFlags(Render::fSprites);
359
-            else
360
-                getRender().clearFlags(Render::fSprites);
361
-            getConsole().print("Sprites are now %s", b ? "on" : "off");
362
-        } else {
363
-            getConsole().print("Invalid use of sprite-command!");
364
-            return -35;
365
-        }
366
-    } else if (strcmp(command, "roommodel") == 0) {
367
-        if (args->size() > 0) {
368
-            bool b;
369
-            if (readBool(args->at(0), &b) < 0) {
370
-                getConsole().print("Pass BOOL to roommodel command!");
371
-                return -36;
372
-            }
373
-            if (b)
374
-                getRender().setFlags(Render::fRoomModels);
375
-            else
376
-                getRender().clearFlags(Render::fRoomModels);
377
-            getConsole().print("Roommodels are now %s", b ? "on" : "off");
378
-        } else {
379
-            getConsole().print("Invalid use of roommodel-command!");
380
-            return -37;
381
-        }
382 334
     } else if (strcmp(command, "entmodel") == 0) {
383 335
         if (args->size() > 0) {
384 336
             bool b;
@@ -500,11 +452,8 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
500 452
             getConsole().print("  pos       - Print position info");
501 453
             getConsole().print("  vmodel    - BOOL - View Model");
502 454
             getConsole().print("  ralpha    - BOOL - Room Alpha");
503
-            getConsole().print("  portal    - BOOL");
504 455
             getConsole().print("  vis       - BOOL - Use Portals");
505 456
             getConsole().print("  upf       - BOOL - Update Room List Per Frame");
506
-            getConsole().print("  sprite    - BOOL");
507
-            getConsole().print("  roommodel - BOOL");
508 457
             getConsole().print("  entmodel  - BOOL");
509 458
             getConsole().print("  oneroom   - BOOL");
510 459
             getConsole().print("  allrooms  - BOOL");

+ 15
- 193
src/Render.cpp 查看文件

@@ -54,8 +54,8 @@ Render::Render()
54 54
     mSkyMeshRotation = false;
55 55
     mMode = Render::modeDisabled;
56 56
     mLock = 0;
57
-    mFlags = (fRoomAlpha | fViewModel | fSprites |
58
-            fRoomModels | fEntityModels | fRenderPonytail |
57
+    mFlags = (fRoomAlpha | fViewModel |
58
+            fEntityModels | fRenderPonytail |
59 59
             fUsePortals | fUpdateRoomListPerFrame);
60 60
 }
61 61
 
@@ -496,7 +496,7 @@ void Render::display()
496 496
             lightRoom(room);
497 497
         }
498 498
 
499
-        drawRoom(room, false);
499
+        room.display(false);
500 500
     }
501 501
 
502 502
     // Draw all visible enities
@@ -561,7 +561,7 @@ void Render::display()
561 561
     {
562 562
         for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
563 563
         {
564
-            drawRoom(*mRoomRenderList[i], true);
564
+            mRoomRenderList[i]->display(true);
565 565
         }
566 566
     }
567 567
 
@@ -648,9 +648,7 @@ void Render::newRoomRenderList(int index)
648 648
 
649 649
             for (unsigned int i = 0; i < getWorld().sizeRoom(); i++)
650 650
             {
651
-                vec3_t bbox[2];
652
-                getWorld().getRoom(i).getBoundingBox(bbox);
653
-                if (!isVisible(bbox[0], bbox[1]))
651
+                if (!isVisible(getWorld().getRoom(i).getBoundingBox()))
654 652
                     continue;
655 653
 
656 654
                 mRoomRenderList.push_back(&getWorld().getRoom(i));
@@ -667,9 +665,7 @@ void Render::buildRoomRenderList(Room &room)
667 665
 
668 666
     // Must be visible
669 667
     //! \fixme Add depth sorting here - remove multipass
670
-    vec3_t bbox[2];
671
-    room.getBoundingBox(bbox);
672
-    if (!isVisible(bbox[0], bbox[1]))
668
+    if (!isVisible(room.getBoundingBox()))
673 669
         return;
674 670
 
675 671
     // Must not already be cached
@@ -791,12 +787,10 @@ void Render::drawObjects()
791 787
     }
792 788
 
793 789
     // Mongoose 2002.03.22, Draw sprites after player to handle alpha
794
-    if (mFlags & Render::fSprites) {
795
-        for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
796
-            SpriteSequence &sprite = getWorld().getSprite(i);
797
-            for (unsigned int j = 0; j < sprite.size(); j++)
798
-                sprite.get(j).display();
799
-        }
790
+    for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
791
+        SpriteSequence &sprite = getWorld().getSprite(i);
792
+        for (unsigned int j = 0; j < sprite.size(); j++)
793
+            sprite.get(j).display();
800 794
     }
801 795
 }
802 796
 
@@ -984,168 +978,6 @@ void Render::drawModel(SkeletalModel *model)
984 978
 }
985 979
 
986 980
 
987
-void draw_bbox(vec3_t min, vec3_t max, bool draw_points,
988
-        const vec4_t c1, const vec4_t c2)
989
-{
990
-    // Bind before entering now
991
-    //glBindTexture(GL_TEXTURE_2D, 1);
992
-    glPointSize(4.0);
993
-    //glLineWidth(1.25);
994
-
995
-    //! \fixme Need to make custom color key for this
996
-    glColor3fv(c1);
997
-
998
-    glBegin(GL_POINTS);
999
-    glVertex3f(max[0], max[1], max[2]);
1000
-    glVertex3f(min[0], min[1], min[2]);
1001
-
1002
-    if (draw_points)
1003
-    {
1004
-        glVertex3f(max[0], min[1], max[2]);
1005
-        glVertex3f(min[0], max[1], max[2]);
1006
-        glVertex3f(max[0], max[1], min[2]);
1007
-        glVertex3f(min[0], min[1], max[2]);
1008
-        glVertex3f(min[0], max[1], min[2]);
1009
-        glVertex3f(max[0], min[1], min[2]);
1010
-    }
1011
-
1012
-    glEnd();
1013
-
1014
-    glColor3fv(c2);
1015
-
1016
-    glBegin(GL_LINES);
1017
-    // max, top quad
1018
-    glVertex3f(max[0], max[1], max[2]);
1019
-    glVertex3f(max[0], min[1], max[2]);
1020
-
1021
-    glVertex3f(max[0], max[1], max[2]);
1022
-    glVertex3f(min[0], max[1], max[2]);
1023
-
1024
-    glVertex3f(max[0], max[1], max[2]);
1025
-    glVertex3f(max[0], max[1], min[2]);
1026
-
1027
-    // max-min, vertical quads
1028
-    glVertex3f(min[0], max[1], max[2]);
1029
-    glVertex3f(min[0], max[1], min[2]);
1030
-
1031
-    glVertex3f(max[0], min[1], max[2]);
1032
-    glVertex3f(max[0], min[1], min[2]);
1033
-
1034
-    glVertex3f(max[0], min[1], max[2]);
1035
-    glVertex3f(min[0], min[1], max[2]);
1036
-
1037
-    // min-max, vertical quads
1038
-    glVertex3f(max[0], max[1], min[2]);
1039
-    glVertex3f(max[0], min[1], min[2]);
1040
-
1041
-    glVertex3f(max[0], max[1], min[2]);
1042
-    glVertex3f(min[0], max[1], min[2]);
1043
-
1044
-    glVertex3f(min[0], max[1], max[2]);
1045
-    glVertex3f(min[0], min[1], max[2]);
1046
-
1047
-
1048
-    // min, bottom quad
1049
-    glVertex3f(min[0], min[1], min[2]);
1050
-    glVertex3f(min[0], max[1], min[2]);
1051
-
1052
-    glVertex3f(min[0], min[1], min[2]);
1053
-    glVertex3f(max[0], min[1], min[2]);
1054
-
1055
-    glVertex3f(min[0], min[1], min[2]);
1056
-    glVertex3f(min[0], min[1], max[2]);
1057
-    glEnd();
1058
-
1059
-    glPointSize(1.0);
1060
-    //glLineWidth(1.0);
1061
-}
1062
-
1063
-
1064
-void Render::drawRoom(Room &room, bool draw_alpha)
1065
-{
1066
-    if (!(mFlags & Render::fRoomAlpha) && draw_alpha)
1067
-        return;
1068
-
1069
-    glPushMatrix();
1070
-    //LightingSetup();
1071
-
1072
-    mTexture.bindTextureId(0); // WHITE texture
1073
-
1074
-    if (!draw_alpha &&
1075
-            (mFlags & Render::fPortals || mMode == Render::modeWireframe)) {
1076
-        glLineWidth(2.0);
1077
-        glColor3fv(RED);
1078
-
1079
-        for (unsigned int i = 0; i < room.sizePortals(); i++) {
1080
-            Portal &portal = room.getPortal(i);
1081
-            vec3_t vertices[4];
1082
-            portal.getVertices(vertices);
1083
-
1084
-            glBegin(GL_LINE_LOOP);
1085
-            glVertex3fv(vertices[0]);
1086
-            glVertex3fv(vertices[1]);
1087
-            glVertex3fv(vertices[2]);
1088
-            glVertex3fv(vertices[3]);
1089
-            glEnd();
1090
-        }
1091
-
1092
-        glLineWidth(1.0);
1093
-    }
1094
-
1095
-    if (mMode == Render::modeWireframe && !draw_alpha) {
1096
-        vec3_t bbox[2];
1097
-        room.getBoundingBox(bbox);
1098
-        draw_bbox(bbox[0], bbox[1], true, RED, GREEN);
1099
-    }
1100
-
1101
-    vec3_t pos;
1102
-    room.getPos(pos);
1103
-    glTranslated(pos[0], pos[1], pos[2]);
1104
-
1105
-    // Reset since GL_MODULATE used, reset to WHITE
1106
-    glColor3fv(WHITE);
1107
-
1108
-    switch (mMode)
1109
-    {
1110
-        case modeWireframe:
1111
-            room.getMesh().mMode = Mesh::MeshModeWireframe;
1112
-            break;
1113
-        case modeSolid:
1114
-            room.getMesh().mMode = Mesh::MeshModeSolid;
1115
-            break;
1116
-        default:
1117
-            room.getMesh().mMode = Mesh::MeshModeTexture;
1118
-            break;
1119
-    }
1120
-
1121
-    if (draw_alpha)
1122
-        room.getMesh().drawAlpha();
1123
-    else
1124
-        room.getMesh().drawSolid();
1125
-
1126
-    glPopMatrix();
1127
-
1128
-    //mTexture.bindTextureId(0);
1129
-
1130
-    // Draw other room meshes and sprites
1131
-    if (draw_alpha || mMode == modeWireframe || mMode == modeSolid) {
1132
-        if (mFlags & Render::fRoomModels) {
1133
-            room.sortModels();
1134
-            for (unsigned int i = 0; i < room.sizeModels(); i++) {
1135
-                room.getModel(i).display();
1136
-            }
1137
-        }
1138
-
1139
-        // Draw other room alpha polygon objects
1140
-        if (mFlags & Render::fSprites) {
1141
-            for (unsigned int i = 0; i < room.sizeSprites(); i++) {
1142
-                room.getSprite(i).display();
1143
-            }
1144
-        }
1145
-    }
1146
-}
1147
-
1148
-
1149 981
 void Render::tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri)
1150 982
 {
1151 983
     glBegin(GL_TRIANGLES);
@@ -1354,23 +1186,13 @@ void Render::updateViewVolume()
1354 1186
     mViewVolume.updateFrame(proj, mdl);
1355 1187
 }
1356 1188
 
1357
-
1358
-bool Render::isVisible(float bbox_min[3], float bbox_max[3])
1359
-{
1189
+bool Render::isVisible(Box &box) {
1190
+    vec3_t bbox[2];
1191
+    box.getBoundingBox(bbox);
1360 1192
     // For debugging purposes
1361 1193
     if (mMode == Render::modeWireframe)
1362
-    {
1363
-        //glPointSize(5.0);
1364
-        //glColor3fv(PINK);
1365
-        //glBegin(GL_POINTS);
1366
-        //glVertex3fv(bbox_min);
1367
-        //glVertex3fv(bbox_max);
1368
-        //glEnd();
1369
-
1370
-        draw_bbox(bbox_min, bbox_max, true, PINK, RED);
1371
-    }
1372
-
1373
-    return mViewVolume.isBboxInFrustum(bbox_min, bbox_max);
1194
+        box.display(true, PINK, RED);
1195
+    return mViewVolume.isBboxInFrustum(bbox[0], bbox[1]);
1374 1196
 }
1375 1197
 
1376 1198
 

+ 90
- 21
src/Room.cpp 查看文件

@@ -5,6 +5,14 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#ifdef __APPLE__
9
+#include <OpenGL/gl.h>
10
+#include <OpenGL/glu.h>
11
+#else
12
+#include <GL/gl.h>
13
+#include <GL/glu.h>
14
+#endif
15
+
8 16
 #include <algorithm>
9 17
 #include <assert.h>
10 18
 
@@ -12,6 +20,7 @@
12 20
 #include "Room.h"
13 21
 
14 22
 Room::Room(TombRaider &tr, unsigned int index) {
23
+    vec3_t box[2];
15 24
     Matrix transform;
16 25
 
17 26
     if (!tr.isRoomValid(index)) {
@@ -21,13 +30,15 @@ Room::Room(TombRaider &tr, unsigned int index) {
21 30
         return;
22 31
     }
23 32
 
24
-    tr.getRoomInfo(index, &flags, pos, bbox[0], bbox[1]);
33
+    tr.getRoomInfo(index, &flags, pos, box[0], box[1]);
25 34
 
26 35
     // Adjust positioning for OR world coordinate translation
27
-    bbox[0][0] += pos[0];
28
-    bbox[1][0] += pos[0];
29
-    bbox[0][2] += pos[2];
30
-    bbox[1][2] += pos[2];
36
+    box[0][0] += pos[0];
37
+    box[1][0] += pos[0];
38
+    box[0][2] += pos[2];
39
+    box[1][2] += pos[2];
40
+
41
+    bbox.setBoundingBox(box[0], box[1]);
31 42
 
32 43
     // Mongoose 2002.04.03, Setup 3D transform
33 44
     transform.setIdentity();
@@ -71,7 +82,7 @@ Room::Room(TombRaider &tr, unsigned int index) {
71 82
     for (unsigned int i = 0; i < count; i++)
72 83
         sprites.push_back(new Sprite(tr, index, i));
73 84
 
74
-#define EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
85
+//#define EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
75 86
 #ifdef EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
76 87
     unsigned int vertexCount, normalCount, colorCount, triCount;
77 88
     vec_t *vertexArray;
@@ -438,6 +449,75 @@ Room::~Room() {
438 449
     EMPTY_VECTOR(lights);
439 450
 }
440 451
 
452
+void Room::display(bool alpha) {
453
+    glPushMatrix();
454
+    //LightingSetup();
455
+
456
+    getRender().mTexture.bindTextureId(0); // WHITE texture
457
+
458
+    if ((!alpha) && getRender().getMode() == Render::modeWireframe) {
459
+        glLineWidth(2.0);
460
+        glColor3fv(RED);
461
+
462
+        for (unsigned int i = 0; i < sizePortals(); i++) {
463
+            Portal &portal = getPortal(i);
464
+            vec3_t vertices[4];
465
+            portal.getVertices(vertices);
466
+
467
+            glBegin(GL_LINE_LOOP);
468
+            glVertex3fv(vertices[0]);
469
+            glVertex3fv(vertices[1]);
470
+            glVertex3fv(vertices[2]);
471
+            glVertex3fv(vertices[3]);
472
+            glEnd();
473
+        }
474
+
475
+        glLineWidth(1.0);
476
+    }
477
+
478
+    if (getRender().getMode() == Render::modeWireframe && (!alpha)) {
479
+        bbox.display(true, RED, GREEN);
480
+    }
481
+
482
+    glTranslated(pos[0], pos[1], pos[2]);
483
+
484
+    // Reset since GL_MODULATE used, reset to WHITE
485
+    glColor3fv(WHITE);
486
+
487
+    switch (getRender().getMode())
488
+    {
489
+        case Render::modeWireframe:
490
+            getMesh().mMode = Mesh::MeshModeWireframe;
491
+            break;
492
+        case Render::modeSolid:
493
+            getMesh().mMode = Mesh::MeshModeSolid;
494
+            break;
495
+        default:
496
+            getMesh().mMode = Mesh::MeshModeTexture;
497
+            break;
498
+    }
499
+
500
+    if (alpha)
501
+        getMesh().drawAlpha();
502
+    else
503
+        getMesh().drawSolid();
504
+
505
+    glPopMatrix();
506
+
507
+    //getRender().mTexture.bindTextureId(0);
508
+
509
+    // Draw other room meshes and sprites
510
+    if (alpha || (getRender().getMode() == Render::modeWireframe)
511
+            || (getRender().getMode() == Render::modeSolid)) {
512
+        sortModels();
513
+        for (unsigned int i = 0; i < sizeModels(); i++)
514
+            getModel(i).display();
515
+
516
+        for (unsigned int i = 0; i < sizeSprites(); i++)
517
+            getSprite(i).display();
518
+    }
519
+}
520
+
441 521
 unsigned int Room::getFlags() {
442 522
     return flags;
443 523
 }
@@ -455,21 +535,6 @@ void Room::getPos(vec3_t p) {
455 535
         p[i] = pos[i];
456 536
 }
457 537
 
458
-void Room::getBoundingBox(vec3_t box[2]) {
459
-    for (unsigned int i = 0; i < 2; i++)
460
-        for (unsigned int j = 0; j < 3; j++)
461
-            box[i][j] = bbox[i][j];
462
-}
463
-
464
-bool Room::inBox(vec_t x, vec_t y, vec_t z) {
465
-    return ((y > bbox[0][1]) && (y < bbox[1][1]) && inBoxPlane(x, z));
466
-}
467
-
468
-bool Room::inBoxPlane(vec_t x, vec_t z) {
469
-    return ((x > bbox[0][0]) && (x < bbox[1][0])
470
-            && (z > bbox[0][2]) && (z < bbox[1][2]));
471
-}
472
-
473 538
 unsigned int Room::sizeAdjacentRooms() {
474 539
     return adjacentRooms.size();
475 540
 }
@@ -537,6 +602,10 @@ Sprite &Room::getSprite(unsigned int index) {
537 602
     return *sprites.at(index);
538 603
 }
539 604
 
605
+Box &Room::getBoundingBox() {
606
+    return bbox;
607
+}
608
+
540 609
 Mesh &Room::getMesh() {
541 610
     return mesh;
542 611
 }

+ 106
- 0
src/RoomData.cpp 查看文件

@@ -130,6 +130,112 @@ int Portal::getAdjoiningRoom() {
130 130
 
131 131
 // ----------------------------------------------------------------------------
132 132
 
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
+
133 239
 Box::Box(TombRaider &tr, unsigned int room, unsigned int index) {
134 240
     tr.getRoomBox(room, index, a, b, c, d);
135 241
 }

+ 3
- 3
src/World.cpp 查看文件

@@ -276,7 +276,7 @@ int World::getRoomByLocation(int index, float x, float y, float z)
276 276
     assert(index < (int)mRooms.size());
277 277
     Room &room = *mRooms.at(index);
278 278
 
279
-    if (room.inBox(x, y, z))
279
+    if (room.getBoundingBox().inBox(x, y, z))
280 280
         return index;
281 281
     else
282 282
         return getRoomByLocation(x, y, z);
@@ -287,8 +287,8 @@ int World::getRoomByLocation(float x, float y, float z) {
287 287
     int hop = -1;
288 288
 
289 289
     for (unsigned int i = 0; i < mRooms.size(); i++) {
290
-        if (mRooms.at(i)->inBoxPlane(x, z)) {
291
-            if (mRooms.at(i)->inBox(x, y, z))
290
+        if (mRooms.at(i)->getBoundingBox().inBoxPlane(x, z)) {
291
+            if (mRooms.at(i)->getBoundingBox().inBox(x, y, z))
292 292
                 return i;
293 293
             else
294 294
                 hop = i; // This room is above or below current position

正在加载...
取消
保存