Browse Source

Moved Box, Sector,... into extra file

Thomas Buck 10 years ago
parent
commit
2007e0693b
6 changed files with 266 additions and 279 deletions
  1. 1
    83
      include/Room.h
  2. 103
    0
      include/RoomData.h
  3. 1
    0
      src/CMakeLists.txt
  4. 0
    42
      src/Render.cpp
  5. 8
    154
      src/Room.cpp
  6. 153
    0
      src/RoomData.cpp

+ 1
- 83
include/Room.h View File

@@ -15,89 +15,7 @@
15 15
 #include "Mesh.h"
16 16
 #include "Sprite.h"
17 17
 #include "TombRaider.h"
18
-
19
-class Light {
20
-public:
21
-    /*!
22
-     * \brief Type a light can be of
23
-     */
24
-    typedef enum {
25
-        typePoint       = 1, //!< Point light
26
-        typeSpot        = 2, //!< Spot light
27
-        typeDirectional = 3  //!< Directional light
28
-    } LightType;
29
-
30
-    Light(TombRaider &tr, unsigned int room, unsigned int index);
31
-
32
-    void getPos(vec4_t p);
33
-    void getDir(vec3_t d);
34
-    vec_t getAtt();
35
-    void getColor(vec4_t c);
36
-    vec_t getCutoff();
37
-    LightType getType();
38
-
39
-private:
40
-    vec4_t pos; //! Light position in 3 space
41
-    vec3_t dir; //! Light direction
42
-    vec_t att;
43
-    vec4_t color; //! Color of light
44
-    vec_t cutoff; //! Fade out distance
45
-    LightType type; //! Type of light
46
-};
47
-
48
-class StaticModel {
49
-public:
50
-    StaticModel(TombRaider &tr, unsigned int room, unsigned int i);
51
-    void display();
52
-
53
-    // Compares distance to ViewVolume for depth sorting
54
-    bool operator<(const StaticModel &other);
55
-
56
-private:
57
-    int index;
58
-    vec_t yaw;
59
-    vec3_t pos;
60
-
61
-    // ?
62
-    //vec3_t bbox[2];
63
-};
64
-
65
-class Portal {
66
-public:
67
-    Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform);
68
-
69
-    void getVertices(vec3_t vert[4]);
70
-    int getAdjoiningRoom();
71
-
72
-private:
73
-    vec3_t vertices[4];
74
-    vec3_t normal;
75
-    int adjoiningRoom;
76
-};
77
-
78
-class Box {
79
-public:
80
-    Box(TombRaider &tr, unsigned int room, unsigned int index);
81
-
82
-private:
83
-    vec3_t a;
84
-    vec3_t b;
85
-    vec3_t c;
86
-    vec3_t d;
87
-};
88
-
89
-class Sector {
90
-public:
91
-    Sector(TombRaider &tr, unsigned int room, unsigned int index);
92
-    vec_t getFloor();
93
-    vec_t getCeiling();
94
-    bool isWall();
95
-
96
-private:
97
-    vec_t floor;
98
-    vec_t ceiling;
99
-    bool wall;
100
-};
18
+#include "RoomData.h"
101 19
 
102 20
 typedef enum {
103 21
     RoomFlagUnderWater = (1 << 0)

+ 103
- 0
include/RoomData.h View File

@@ -0,0 +1,103 @@
1
+/*!
2
+ * \file include/RoomData.h
3
+ * \brief World Room Mesh
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _ROOM_DATA_H_
9
+#define _ROOM_DATA_H_
10
+
11
+#include <vector>
12
+#include <memory>
13
+#include "math/math.h"
14
+#include "math/Matrix.h"
15
+#include "Mesh.h"
16
+#include "Sprite.h"
17
+#include "TombRaider.h"
18
+
19
+class Light {
20
+public:
21
+    /*!
22
+     * \brief Type a light can be of
23
+     */
24
+    typedef enum {
25
+        typePoint       = 1, //!< Point light
26
+        typeSpot        = 2, //!< Spot light
27
+        typeDirectional = 3  //!< Directional light
28
+    } LightType;
29
+
30
+    Light(TombRaider &tr, unsigned int room, unsigned int index);
31
+
32
+    void getPos(vec4_t p);
33
+    void getDir(vec3_t d);
34
+    vec_t getAtt();
35
+    void getColor(vec4_t c);
36
+    vec_t getCutoff();
37
+    LightType getType();
38
+
39
+private:
40
+    vec4_t pos; //! Light position in 3 space
41
+    vec3_t dir; //! Light direction
42
+    vec_t att;
43
+    vec4_t color; //! Color of light
44
+    vec_t cutoff; //! Fade out distance
45
+    LightType type; //! Type of light
46
+};
47
+
48
+class StaticModel {
49
+public:
50
+    StaticModel(TombRaider &tr, unsigned int room, unsigned int i);
51
+    void display();
52
+
53
+    // Compares distance to ViewVolume for depth sorting
54
+    bool operator<(const StaticModel &other);
55
+
56
+private:
57
+    int index;
58
+    vec_t yaw;
59
+    vec3_t pos;
60
+
61
+    // ?
62
+    //vec3_t bbox[2];
63
+};
64
+
65
+class Portal {
66
+public:
67
+    Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform);
68
+
69
+    void getVertices(vec3_t vert[4]);
70
+    int getAdjoiningRoom();
71
+
72
+private:
73
+    vec3_t vertices[4];
74
+    vec3_t normal;
75
+    int adjoiningRoom;
76
+};
77
+
78
+class Box {
79
+public:
80
+    Box(TombRaider &tr, unsigned int room, unsigned int index);
81
+
82
+private:
83
+    vec3_t a;
84
+    vec3_t b;
85
+    vec3_t c;
86
+    vec3_t d;
87
+};
88
+
89
+class Sector {
90
+public:
91
+    Sector(TombRaider &tr, unsigned int room, unsigned int index);
92
+    vec_t getFloor();
93
+    vec_t getCeiling();
94
+    bool isWall();
95
+
96
+private:
97
+    vec_t floor;
98
+    vec_t ceiling;
99
+    bool wall;
100
+};
101
+
102
+#endif
103
+

+ 1
- 0
src/CMakeLists.txt View File

@@ -49,6 +49,7 @@ set (SRCS ${SRCS} "Mesh.cpp")
49 49
 set (SRCS ${SRCS} "OpenRaider.cpp")
50 50
 set (SRCS ${SRCS} "Render.cpp")
51 51
 set (SRCS ${SRCS} "Room.cpp")
52
+set (SRCS ${SRCS} "RoomData.cpp")
52 53
 set (SRCS ${SRCS} "SkeletalModel.cpp")
53 54
 set (SRCS ${SRCS} "Sound.cpp")
54 55
 set (SRCS ${SRCS} "Sprite.cpp")

+ 0
- 42
src/Render.cpp View File

@@ -1218,7 +1218,6 @@ void Render::drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type)
1218 1218
     texture_tri_t *ttri;
1219 1219
     int lastTexture = -1;
1220 1220
 
1221
-
1222 1221
     // If they pass NULL structs let it hang up - this is tmp
1223 1222
 
1224 1223
     //! \fixme Duh, vis tests need to be put back
@@ -1227,47 +1226,6 @@ void Render::drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type)
1227 1226
     //   return;
1228 1227
     //}
1229 1228
 
1230
-#ifdef USE_GL_ARRAYS
1231
-    // Setup Arrays ( move these to another method depends on mMode )
1232
-    glEnableClientState(GL_VERTEX_ARRAY);
1233
-    glVertexPointer(3, GL_FLOAT, 0, r_mesh->vertices);
1234
-
1235
-    if (r_mesh->normals)
1236
-    {
1237
-        glEnableClientState(GL_NORMAL_ARRAY);
1238
-        glNormalPointer(3, GL_FLOAT, 0, r_mesh->normals);
1239
-    }
1240
-
1241
-    if (r_mesh->colors)
1242
-    {
1243
-        glEnableClientState(GL_COLOR_ARRAY);
1244
-        glColorPointer(4, GL_FLOAT, 0, r_mesh->colors);
1245
-    }
1246
-
1247
-    //glTexCoordPointer(2, GL_FLOAT, 0, ttri->st);
1248
-    //glDrawArrays(GL_TRIANGLES, i * 3, 3 * j);
1249
-
1250
-    glBegin(GL_TRIANGLES);
1251
-
1252
-    for (unsigned int i = 0; i < r_mesh->texturedTriangles.size(); i++)
1253
-    {
1254
-        ttri = r_mesh->texturedTriangles[i];
1255
-
1256
-        if (!ttri)
1257
-            continue;
1258
-
1259
-        for (k = 0; k < 4; ++k)
1260
-        {
1261
-            index = mQuads[i].quads[j*4+k];
1262
-            glTexCoord2fv(mQuads[i].texcoors[j*4+k]);
1263
-            glArrayElement(mVertices[index]);
1264
-        }
1265
-    }
1266
-
1267
-    glEnd();
1268
-#endif
1269
-
1270
-
1271 1229
     //! \fixme 'AMBIENT' -- Mongoose 2002.01.08
1272 1230
     glColor3fv(WHITE);
1273 1231
 

+ 8
- 154
src/Room.cpp View File

@@ -5,159 +5,12 @@
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
-
16 8
 #include <algorithm>
17 9
 #include <assert.h>
18 10
 
19 11
 #include "main.h"
20 12
 #include "Room.h"
21 13
 
22
-#ifndef EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
23
-#define TextureLimit 24
24
-#endif
25
-
26
-Light::Light(TombRaider &tr, unsigned int room, unsigned int index) {
27
-    unsigned int lightFlags, lightType;
28
-
29
-    tr.getRoomLight(room, index, pos, color,
30
-            dir, &att, &cutoff, &lightType, &lightFlags);
31
-
32
-    switch (lightType) {
33
-        case tombraiderLight_typeDirectional:
34
-            type = Light::typeDirectional;
35
-            break;
36
-        case tombraiderLight_typeSpot:
37
-            type = Light::typeSpot;
38
-            break;
39
-        case tombraiderLight_typePoint:
40
-        default:
41
-            type = Light::typePoint;
42
-    }
43
-
44
-    //! \todo Light flags?
45
-}
46
-
47
-void Light::getPos(vec4_t p) {
48
-    p[0] = pos[0];
49
-    p[1] = pos[1];
50
-    p[2] = pos[2];
51
-    p[3] = pos[3];
52
-}
53
-
54
-void Light::getDir(vec3_t d) {
55
-    d[0] = dir[0];
56
-    d[1] = dir[1];
57
-    d[2] = dir[2];
58
-}
59
-
60
-vec_t Light::getAtt() {
61
-    return att;
62
-}
63
-
64
-void Light::getColor(vec4_t c) {
65
-    c[0] = color[0];
66
-    c[1] = color[1];
67
-    c[2] = color[2];
68
-    c[3] = color[3];
69
-}
70
-
71
-vec_t Light::getCutoff() {
72
-    return cutoff;
73
-}
74
-
75
-Light::LightType Light::getType() {
76
-    return type;
77
-}
78
-
79
-StaticModel::StaticModel(TombRaider &tr, unsigned int room, unsigned int i) {
80
-    tr.getRoomModel(room, i, &index, pos, &yaw);
81
-}
82
-
83
-void StaticModel::display() {
84
-    model_mesh_t *mesh = getWorld().getMesh(index);
85
-
86
-    if (!mesh)
87
-        return;
88
-
89
-    if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh->radius))
90
-        return;
91
-
92
-    glPushMatrix();
93
-    glTranslated(pos[0], pos[1], pos[2]);
94
-    glRotated(yaw, 0, 1, 0);
95
-
96
-    getRender().drawModelMesh(mesh, Render::roomMesh);
97
-    glPopMatrix();
98
-}
99
-
100
-bool StaticModel::operator<(const StaticModel &other) {
101
-    vec_t distA, distB;
102
-    distA = getRender().mViewVolume.getDistToSphereFromNear(pos[0],
103
-            pos[1], pos[2], 128.0f);
104
-    distB = getRender().mViewVolume.getDistToSphereFromNear(other.pos[0],
105
-            other.pos[1], other.pos[2], 128.0f);
106
-    return (distA < distB);
107
-}
108
-
109
-Portal::Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform) {
110
-    float portalVertices[12];
111
-    tr.getRoomPortal(room, index, &adjoiningRoom, normal, portalVertices);
112
-    for (unsigned int j = 0; j < 4; ++j) {
113
-        vertices[j][0] = portalVertices[j*3];
114
-        vertices[j][1] = portalVertices[j*3+1];
115
-        vertices[j][2] = portalVertices[j*3+2];
116
-
117
-        // Relative coors in vis portals
118
-        transform.multiply3v(vertices[j], vertices[j]);
119
-    }
120
-}
121
-
122
-void Portal::getVertices(vec3_t vert[4]) {
123
-    for (unsigned int i = 0; i < 4; i++) {
124
-        for (unsigned int j = 0; j < 3; j++) {
125
-            vert[i][j] = vertices[i][j];
126
-        }
127
-    }
128
-}
129
-
130
-int Portal::getAdjoiningRoom() {
131
-    return adjoiningRoom;
132
-}
133
-
134
-Box::Box(TombRaider &tr, unsigned int room, unsigned int index) {
135
-    tr.getRoomBox(room, index, a, b, c, d);
136
-}
137
-
138
-Sector::Sector(TombRaider &tr, unsigned int room, unsigned int index) {
139
-    unsigned int sectorFlags;
140
-    int floorDataIndex, boxIndex, roomBelow, roomAbove;
141
-
142
-    tr.getRoomSector(room, index, &sectorFlags,
143
-            &ceiling, &floor, &floorDataIndex, &boxIndex,
144
-            &roomBelow, &roomAbove);
145
-
146
-    wall = (sectorFlags & tombraiderSector_wall);
147
-}
148
-
149
-vec_t Sector::getFloor() {
150
-    return floor;
151
-}
152
-
153
-vec_t Sector::getCeiling() {
154
-    return ceiling;
155
-}
156
-
157
-bool Sector::isWall() {
158
-    return wall;
159
-}
160
-
161 14
 Room::Room(TombRaider &tr, unsigned int index) {
162 15
     Matrix transform;
163 16
 
@@ -218,13 +71,13 @@ Room::Room(TombRaider &tr, unsigned int index) {
218 71
     for (unsigned int i = 0; i < count; i++)
219 72
         sprites.push_back(new Sprite(tr, index, i));
220 73
 
221
-//#define EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
74
+#define EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
222 75
 #ifdef EXPERIMENTAL_UNIFIED_ROOM_GEOMETERY
223 76
     unsigned int vertexCount, normalCount, colorCount, triCount;
224 77
     vec_t *vertexArray;
225 78
     vec_t *normalArray;
226 79
     vec_t *colorArray;
227
-    unsigned int *indices, *flags;
80
+    unsigned int *indices, *fflags;
228 81
     float *texCoords;
229 82
     int *textures;
230 83
 
@@ -233,16 +86,17 @@ Room::Room(TombRaider &tr, unsigned int index) {
233 86
             &normalCount, &normalArray,
234 87
             &colorCount, &colorArray);
235 88
 
236
-    mesh.bufferVertexArray(vertexCount, (vec_t *)vertexArray);
237
-    mesh.bufferNormalArray(normalCount, (vec_t *)normalArray);
238
-    mesh.bufferColorArray(vertexCount, (vec_t *)colorArray);
89
+    mesh.bufferVertexArray(vertexCount, vertexArray);
90
+    mesh.bufferNormalArray(normalCount, normalArray);
91
+    mesh.bufferColorArray(vertexCount, colorArray);
239 92
 
240 93
     tr.getRoomTriangles(index, getGame().getTextureStart(),
241 94
             &triCount, &indices, &texCoords, &textures,
242
-            &flags);
95
+            &fflags);
243 96
 
244
-    mesh.bufferTriangles(triCount, indices, texCoords, textures, flags);
97
+    mesh.bufferTriangles(triCount, indices, texCoords, textures, fflags);
245 98
 #else
99
+    const unsigned int TextureLimit = 24;
246 100
     float rgba[4];
247 101
     float xyz[3];
248 102
 

+ 153
- 0
src/RoomData.cpp View File

@@ -0,0 +1,153 @@
1
+/*!
2
+ * \file src/RoomData.cpp
3
+ * \brief World Room Mesh
4
+ *
5
+ * \author xythobuz
6
+ */
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
+
16
+#include "main.h"
17
+#include "RoomData.h"
18
+
19
+Light::Light(TombRaider &tr, unsigned int room, unsigned int index) {
20
+    unsigned int lightFlags, lightType;
21
+
22
+    tr.getRoomLight(room, index, pos, color,
23
+            dir, &att, &cutoff, &lightType, &lightFlags);
24
+
25
+    switch (lightType) {
26
+        case tombraiderLight_typeDirectional:
27
+            type = Light::typeDirectional;
28
+            break;
29
+        case tombraiderLight_typeSpot:
30
+            type = Light::typeSpot;
31
+            break;
32
+        case tombraiderLight_typePoint:
33
+        default:
34
+            type = Light::typePoint;
35
+    }
36
+
37
+    //! \todo Light flags?
38
+}
39
+
40
+void Light::getPos(vec4_t p) {
41
+    p[0] = pos[0];
42
+    p[1] = pos[1];
43
+    p[2] = pos[2];
44
+    p[3] = pos[3];
45
+}
46
+
47
+void Light::getDir(vec3_t d) {
48
+    d[0] = dir[0];
49
+    d[1] = dir[1];
50
+    d[2] = dir[2];
51
+}
52
+
53
+vec_t Light::getAtt() {
54
+    return att;
55
+}
56
+
57
+void Light::getColor(vec4_t c) {
58
+    c[0] = color[0];
59
+    c[1] = color[1];
60
+    c[2] = color[2];
61
+    c[3] = color[3];
62
+}
63
+
64
+vec_t Light::getCutoff() {
65
+    return cutoff;
66
+}
67
+
68
+Light::LightType Light::getType() {
69
+    return type;
70
+}
71
+
72
+StaticModel::StaticModel(TombRaider &tr, unsigned int room, unsigned int i) {
73
+    tr.getRoomModel(room, i, &index, pos, &yaw);
74
+}
75
+
76
+void StaticModel::display() {
77
+    model_mesh_t *mesh = getWorld().getMesh(index);
78
+
79
+    if (!mesh)
80
+        return;
81
+
82
+    if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh->radius))
83
+        return;
84
+
85
+    glPushMatrix();
86
+    glTranslated(pos[0], pos[1], pos[2]);
87
+    glRotated(yaw, 0, 1, 0);
88
+
89
+    getRender().drawModelMesh(mesh, Render::roomMesh);
90
+    glPopMatrix();
91
+}
92
+
93
+bool StaticModel::operator<(const StaticModel &other) {
94
+    vec_t distA, distB;
95
+    distA = getRender().mViewVolume.getDistToSphereFromNear(pos[0],
96
+            pos[1], pos[2], 128.0f);
97
+    distB = getRender().mViewVolume.getDistToSphereFromNear(other.pos[0],
98
+            other.pos[1], other.pos[2], 128.0f);
99
+    return (distA < distB);
100
+}
101
+
102
+Portal::Portal(TombRaider &tr, unsigned int room, unsigned int index, Matrix &transform) {
103
+    float portalVertices[12];
104
+    tr.getRoomPortal(room, index, &adjoiningRoom, normal, portalVertices);
105
+    for (unsigned int j = 0; j < 4; ++j) {
106
+        vertices[j][0] = portalVertices[j*3];
107
+        vertices[j][1] = portalVertices[j*3+1];
108
+        vertices[j][2] = portalVertices[j*3+2];
109
+
110
+        // Relative coors in vis portals
111
+        transform.multiply3v(vertices[j], vertices[j]);
112
+    }
113
+}
114
+
115
+void Portal::getVertices(vec3_t vert[4]) {
116
+    for (unsigned int i = 0; i < 4; i++) {
117
+        for (unsigned int j = 0; j < 3; j++) {
118
+            vert[i][j] = vertices[i][j];
119
+        }
120
+    }
121
+}
122
+
123
+int Portal::getAdjoiningRoom() {
124
+    return adjoiningRoom;
125
+}
126
+
127
+Box::Box(TombRaider &tr, unsigned int room, unsigned int index) {
128
+    tr.getRoomBox(room, index, a, b, c, d);
129
+}
130
+
131
+Sector::Sector(TombRaider &tr, unsigned int room, unsigned int index) {
132
+    unsigned int sectorFlags;
133
+    int floorDataIndex, boxIndex, roomBelow, roomAbove;
134
+
135
+    tr.getRoomSector(room, index, &sectorFlags,
136
+            &ceiling, &floor, &floorDataIndex, &boxIndex,
137
+            &roomBelow, &roomAbove);
138
+
139
+    wall = (sectorFlags & tombraiderSector_wall);
140
+}
141
+
142
+vec_t Sector::getFloor() {
143
+    return floor;
144
+}
145
+
146
+vec_t Sector::getCeiling() {
147
+    return ceiling;
148
+}
149
+
150
+bool Sector::isWall() {
151
+    return wall;
152
+}
153
+

Loading…
Cancel
Save