ソースを参照

Compiles up to Render

Thomas Buck 10年前
コミット
fdd71891c0
10個のファイルの変更235行の追加246行の削除
  1. 11
    2
      include/Entity.h
  2. 1
    5
      include/Render.h
  3. 3
    1
      include/SkeletalModel.h
  4. 0
    7
      include/World.h
  5. 31
    41
      src/Command.cpp
  6. 162
    2
      src/Entity.cpp
  7. 13
    12
      src/Game.cpp
  8. 1
    1
      src/OpenRaider.cpp
  9. 13
    2
      src/SkeletalModel.cpp
  10. 0
    173
      src/World.cpp

+ 11
- 2
include/Entity.h ファイルの表示

@@ -9,6 +9,7 @@
9 9
 #define _ENTITY_H_
10 10
 
11 11
 #include "math/math.h"
12
+#include "SkeletalModel.h"
12 13
 #include "TombRaider.h"
13 14
 
14 15
 class Entity {
@@ -25,12 +26,20 @@ public:
25 26
 
26 27
     bool operator<(Entity &o);
27 28
     void display();
29
+    void move(char movement);
30
+    void print();
28 31
 
32
+    SkeletalModel &getModel();
29 33
     void setSkeletalModel(unsigned int model);
34
+    void setMoveType(MoveType m);
35
+    int getObjectId();
36
+    void setAngles(vec_t yaw, vec_t pitch);
37
+    vec_t getPos(unsigned int i);
38
+    vec_t getAngle(unsigned int i);
30 39
 
31 40
     // Animation State
32
-    unsigned int getAnimationFrame();
33
-    void setAnimationFrame(unsigned int index);
41
+    unsigned int getAnimation();
42
+    void setAnimation(unsigned int index);
34 43
     unsigned int getBoneFrame();
35 44
     void setBoneFrame(unsigned int index);
36 45
     unsigned int getIdleAnimation();

+ 1
- 5
include/Render.h ファイルの表示

@@ -15,7 +15,6 @@
15 15
 #include "math/Matrix.h"
16 16
 #include "ViewVolume.h"
17 17
 #include "World.h"
18
-#include "SkeletalModel.h"
19 18
 #include "Mesh.h"
20 19
 #include "Texture.h"
21 20
 #include "Camera.h"
@@ -121,8 +120,6 @@ public:
121 120
 
122 121
     void setSkyMesh(int index, bool rot);
123 122
 
124
-    void addSkeletalModel(SkeletalModel *mdl);
125
-
126 123
     unsigned int getFlags();
127 124
 
128 125
     /*!
@@ -157,8 +154,7 @@ public:
157 154
     //! \fixme should be private
158 155
 
159 156
     ViewVolume mViewVolume; //!< View Volume for frustum culling
160
-    std::vector<SkeletalModel *> mModels;
161
-    Texture mTexture;                     //!< Texture subsystem
157
+    Texture mTexture; //!< Texture subsystem
162 158
 
163 159
 private:
164 160
 

+ 3
- 1
include/SkeletalModel.h ファイルの表示

@@ -56,9 +56,11 @@ private:
56 56
 
57 57
 class SkeletalModel {
58 58
 public:
59
-    SkeletalModel(TombRaider &tr, unsigned int index);
59
+    SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i, int objectId);
60 60
     ~SkeletalModel();
61 61
     int getId();
62
+    void setPigTail(bool b);
63
+    void setPonyPos(vec_t x, vec_t y, vec_t z, vec_t angle);
62 64
 
63 65
     unsigned int size();
64 66
     AnimationFrame &get(unsigned int i);

+ 0
- 7
include/World.h ファイルの表示

@@ -60,13 +60,6 @@ public:
60 60
     model_mesh_t *getMesh(int index);
61 61
 
62 62
     /*!
63
-     * \brief Move entity in given direction unless collision occurs
64
-     * \param e entity to move
65
-     * \param movement direction of movement ('f', 'b', 'l' or 'r')
66
-     */
67
-    void moveEntity(entity_t *e, char movement);
68
-
69
-    /*!
70 63
      * \brief Find room a location is in.
71 64
      *
72 65
      * If it fails to be in a room it gives closest overlapping room.

+ 31
- 41
src/Command.cpp ファイルの表示

@@ -13,6 +13,7 @@
13 13
 
14 14
 #include "config.h"
15 15
 #include "Console.h"
16
+#include "Entity.h"
16 17
 #include "Game.h"
17 18
 #include "main.h"
18 19
 #include "math/math.h"
@@ -131,13 +132,13 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
131 132
             if (getGame().isLoaded()) {
132 133
                 char *move = args->at(0);
133 134
                 if (strcmp(move, "walk") == 0) {
134
-                    getGame().mLara->moveType = worldMoveType_walk;
135
+                    getGame().getLara().setMoveType(Entity::MoveTypeWalk);
135 136
                     getConsole().print("Lara is walking...");
136 137
                 } else if (strcmp(move, "fly") == 0) {
137
-                    getGame().mLara->moveType = worldMoveType_fly;
138
+                    getGame().getLara().setMoveType(Entity::MoveTypeFly);
138 139
                     getConsole().print("Lara is flying...");
139 140
                 } else if (strcmp(move, "noclip") == 0) {
140
-                    getGame().mLara->moveType = worldMoveType_noClipping;
141
+                    getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
141 142
                     getConsole().print("Lara is noclipping...");
142 143
                 } else {
143 144
                     getConsole().print("Invalid use of move command (%s)!", move);
@@ -172,13 +173,13 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
172 173
             if (c == 'n') {
173 174
                 // Step all skeletal models to their next animation
174 175
                 if (getRender().getFlags() & Render::fAnimateAllModels) {
175
-                    for (unsigned int i = 0; i < getRender().mModels.size(); i++) {
176
-                        SkeletalModel *m = getRender().mModels[i];
177
-                        if (m->getAnimation() < ((int)m->model->animation.size() - 1))
178
-                            m->setAnimation(m->getAnimation() + 1);
176
+                    for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
177
+                        Entity &e = getWorld().getEntity(i);
178
+                        SkeletalModel &m = e.getModel();
179
+                        if (e.getAnimation() < (m.size() - 1))
180
+                            e.setAnimation(e.getAnimation() + 1);
179 181
                         else
180
-                            if (m->getAnimation() != 0)
181
-                                m->setAnimation(0);
182
+                            e.setAnimation(0);
182 183
                     }
183 184
                 } else {
184 185
                     getConsole().print("Animations need to be enabled!");
@@ -186,13 +187,14 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
186 187
             } else if (c == 'p') {
187 188
                 // Step all skeletal models to their previous animation
188 189
                 if (getRender().getFlags() & Render::fAnimateAllModels) {
189
-                    for (unsigned int i = 0; i < getRender().mModels.size(); i++) {
190
-                        SkeletalModel *m = getRender().mModels[i];
191
-                        if (m->getAnimation() > 0)
192
-                            m->setAnimation(m->getAnimation() - 1);
190
+                    for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
191
+                        Entity &e = getWorld().getEntity(i);
192
+                        SkeletalModel &m = e.getModel();
193
+                        if (e.getAnimation() > 0)
194
+                            e.setAnimation(e.getAnimation() - 1);
193 195
                         else
194
-                            if (m->model->animation.size() > 0)
195
-                                m->setAnimation(m->model->animation.size() - 1);
196
+                            if (m.size() > 0)
197
+                                e.setAnimation(m.size() - 1);
196 198
                     }
197 199
                 } else {
198 200
                     getConsole().print("Animations need to be enabled!");
@@ -251,22 +253,19 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
251 253
             getConsole().print("Use viewmodel command interactively!");
252 254
             return -999;
253 255
         }
254
-        if (getGame().mLara) {
255
-            skeletal_model_t *mdl = getWorld().getModel(atoi(args->at(0)));
256
-            if (getGame().mLara->tmpHook)
257
-                getGame().mLara->tmpHook->setModel(mdl);
256
+        unsigned int n = atoi(args->at(0));
257
+        if (n < getWorld().sizeSkeletalModel())
258
+            getGame().getLara().setSkeletalModel(n);
259
+        else {
260
+            getConsole().print("Invalid SkeletalModel index!");
261
+            return -66;
258 262
         }
259
-        //m_render.ViewModel(LARA, atoi(cmd));
260 263
     } else if (strcmp(command, "pos") == 0) {
261
-        if (getGame().mLara) {
262
-            getConsole().print("Position:");
263
-            getConsole().print("  Room %i (0x%X)", getGame().mLara->room, getWorld().getRoomInfo(getGame().mLara->room));
264
-            getConsole().print("  %.1fx %.1fy %.1fz", getGame().mLara->pos[0], getGame().mLara->pos[1], getGame().mLara->pos[2]);
265
-            getConsole().print("  %.1f Yaw %.1f Pitch", OR_RAD_TO_DEG(getGame().mLara->angles[1]), OR_RAD_TO_DEG(getGame().mLara->angles[2]));
266
-        } else {
267
-            getConsole().print("Load a level to get Laras position!");
264
+        if ((!mRunning) || (!getGame().isLoaded())) {
265
+            getConsole().print("Use pos command interactively!");
268 266
             return -21;
269 267
         }
268
+        getGame().getLara().print();
270 269
     } else if (strcmp(command, "vmodel") == 0) {
271 270
         if (args->size() > 0) {
272 271
             bool b;
@@ -406,15 +405,8 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
406 405
                 getConsole().print("Pass BOOL to pigtail command!");
407 406
                 return -46;
408 407
             }
409
-            SkeletalModel *tmp = getGame().mLara->tmpHook;
410
-            tmp->model->pigtails = b;
411
-            if (b) {
412
-                tmp->model->ponyOff -= 20;
413
-                tmp->model->ponytail[1] -= 32;
414
-            } else {
415
-                tmp->model->ponyOff += 20;
416
-                tmp->model->ponytail[1] += 32;
417
-            }
408
+            SkeletalModel &tmp = getGame().getLara().getModel();
409
+            tmp.setPigTail(b);
418 410
             getConsole().print("Pigtail is now %s", b ? "on" : "off");
419 411
         } else {
420 412
             getConsole().print("Invalid use of pigtail-command!");
@@ -426,11 +418,9 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
426 418
             return -999;
427 419
         }
428 420
         if (args->size() > 3) {
429
-            SkeletalModel *tmp = getGame().mLara->tmpHook;
430
-            tmp->model->ponytail[0] = (float)atof(args->at(0));
431
-            tmp->model->ponytail[1] = (float)atof(args->at(1));
432
-            tmp->model->ponytail[2] = (float)atof(args->at(2));
433
-            tmp->model->ponytailAngle = (float)atof(args->at(3));
421
+            SkeletalModel &tmp = getGame().getLara().getModel();
422
+            tmp.setPonyPos((float)atof(args->at(0)), (float)atof(args->at(1)),
423
+                    (float)atof(args->at(2)), (float)atof(args->at(3)));
434 424
         } else {
435 425
             getConsole().print("Invalid use of ponypos-command!");
436 426
             return -48;

+ 162
- 2
src/Entity.cpp ファイルの表示

@@ -19,6 +19,8 @@
19 19
 #include "Entity.h"
20 20
 #include "main.h"
21 21
 
22
+#include "games/TombRaider1.h"
23
+
22 24
 Entity::Entity(TombRaider &tr, unsigned int index, unsigned int i, unsigned int model) {
23 25
     tr2_moveable_t *moveable = tr.Moveable();
24 26
     tr2_item_t *item = tr.Item();
@@ -73,6 +75,164 @@ void Entity::display() {
73 75
     */
74 76
 }
75 77
 
78
+void Entity::move(char movement) {
79
+    const float moved = 180.0f;
80
+    const float testd = 220.0f;
81
+    const float camHeight = 8.0f;
82
+    float x, y, z, pitch, h, floor, ceiling;
83
+    int roomNew, sector;
84
+    bool wall;
85
+    unsigned int roomFlags;
86
+
87
+    switch (moveType) {
88
+        case MoveTypeWalkNoSwim:
89
+        case MoveTypeWalk:
90
+            pitch = 0.0f; // in the future pitch could control jump up blocks here
91
+            break;
92
+
93
+        case MoveTypeNoClipping:
94
+        case MoveTypeFly:
95
+        case MoveTypeSwim:
96
+            pitch = angles[2];
97
+            break;
98
+    }
99
+
100
+    switch (movement) {
101
+        case 'f':
102
+            x = pos[0] + (testd * sinf(angles[1]));
103
+            y = pos[1] + (testd * sinf(pitch));
104
+            z = pos[2] + (testd * cosf(angles[1]));
105
+            break;
106
+        case 'b':
107
+            x = pos[0] - (testd * sinf(angles[1]));
108
+            y = pos[1] - (testd * sinf(pitch));
109
+            z = pos[2] - (testd * cosf(angles[1]));
110
+            break;
111
+        case 'l':
112
+            x = pos[0] - (testd * sinf(angles[1] + 90.0f));
113
+            y = pos[1];
114
+            z = pos[2] - (testd * cosf(angles[1] + 90.0f));
115
+            break;
116
+        case 'r':
117
+            x = pos[0] + (testd * sinf(angles[1] + 90.0f));
118
+            y = pos[1];
119
+            z = pos[2] + (testd * cosf(angles[1] + 90.0f));
120
+            break;
121
+        default:
122
+            return;
123
+    }
124
+
125
+    //room = getRoomByLocation(x, y, z);
126
+    roomNew = getWorld().getRoomByLocation(room, x, y, z);
127
+
128
+    if (roomNew == -1) { // Will we hit a portal?
129
+        roomNew = getWorld().getAdjoiningRoom(room,
130
+                pos[0],  pos[1], pos[2],
131
+                x, y, z);
132
+
133
+        if (roomNew > -1)
134
+            printf("Crossing from room %i to %i\n", room, roomNew);
135
+        else
136
+            //! \fixme mRooms, sectors, ... are now std::vector, but often upper bound checks are missing
137
+            return;
138
+    }
139
+
140
+    roomFlags = getWorld().getRoomInfo(roomNew);
141
+    sector = getWorld().getSector(roomNew, x, z, &floor, &ceiling);
142
+    wall = getWorld().isWall(roomNew, sector);
143
+
144
+    // If you're underwater you may want to swim  =)
145
+    // ...if you're worldMoveType_walkNoSwim, you better hope it's shallow
146
+    if ((roomFlags & RoomFlagUnderWater) && (moveType == MoveTypeWalk))
147
+        moveType = MoveTypeSwim;
148
+
149
+    // Don't swim on land
150
+    if (!(roomFlags & RoomFlagUnderWater) && (moveType == MoveTypeSwim))
151
+        moveType = MoveTypeWalk;
152
+
153
+    // Mongoose 2002.09.02, Add check for room -> room transition
154
+    // (Only allow by movement between rooms by using portals)
155
+    if (((moveType == MoveTypeNoClipping) ||
156
+                (moveType == MoveTypeFly) ||
157
+                (moveType == MoveTypeSwim)) ||
158
+            ((roomNew > -1) && (!wall))) {
159
+        room = roomNew;
160
+
161
+        switch (movement) {
162
+            case 'f':
163
+                x = pos[0] + (moved * sinf(angles[1]));
164
+                y = pos[1] + (moved * sinf(pitch));
165
+                z = pos[2] + (moved * cosf(angles[1]));
166
+                break;
167
+            case 'b':
168
+                x = pos[0] - (moved * sinf(angles[1]));
169
+                y = pos[1] - (moved * sinf(pitch));
170
+                z = pos[2] - (moved * cosf(angles[1]));
171
+                break;
172
+            case 'l':
173
+                x = pos[0] - (moved * sinf(angles[1] + 90.0f));
174
+                z = pos[2] - (moved * cosf(angles[1] + 90.0f));
175
+                break;
176
+            case 'r':
177
+                x = pos[0] + (moved * sinf(angles[1] + 90.0f));
178
+                z = pos[2] + (moved * cosf(angles[1] + 90.0f));
179
+                break;
180
+        }
181
+
182
+        /*! \fixme Test for vector (move vector) / plane (portal) collision here
183
+         * to see if we need to switch rooms... man...
184
+         */
185
+
186
+        h = y;
187
+        getWorld().getHeightAtPosition(room, x, &h, z);
188
+
189
+        switch (moveType) {
190
+            case MoveTypeFly:
191
+            case MoveTypeSwim:
192
+                // Don't fall out of world, avoid a movement that does
193
+                if (h > y - camHeight) {
194
+                    pos[0] = x;
195
+                    pos[1] = y;
196
+                    pos[2] = z;
197
+                }
198
+                break;
199
+
200
+            case MoveTypeWalk:
201
+            case MoveTypeWalkNoSwim:
202
+                y = pos[1];  // Override vector movement walking ( er, not pretty )
203
+
204
+                // Now fake gravity
205
+                // Mongoose 2002.08.14, Remember TR is upside down ( you fall 'up' )
206
+
207
+                //ddist = h - pos[1];
208
+
209
+                // This is to force false gravity, by making camera stay on ground
210
+                pos[1] = h; //roomFloor->bbox_min[1];
211
+
212
+                // Check for camera below terrian and correct
213
+                if (pos[1] < h - camHeight)
214
+                    pos[1] = h - camHeight;
215
+
216
+                pos[0] = x;
217
+                pos[2] = z;
218
+                break;
219
+
220
+            case MoveTypeNoClipping:
221
+                pos[0] = x;
222
+                pos[1] = y;
223
+                pos[2] = z;
224
+                break;
225
+        }
226
+    }
227
+}
228
+
229
+void Entity::print() {
230
+    getConsole().print("Entity %d:", objectId);
231
+    getConsole().print("  Room %i (0x%X)", room, getWorld().getRoomInfo(room));
232
+    getConsole().print("  %.1fx %.1fy %.1fz", pos[0], pos[1], pos[2]);
233
+    getConsole().print("  %.1f Yaw %.1f Pitch", OR_RAD_TO_DEG(angles[1]), OR_RAD_TO_DEG(angles[2]));
234
+}
235
+
76 236
 void Entity::setSkeletalModel(unsigned int model) {
77 237
     skeletalModel = model;
78 238
     animationFrame = 0;
@@ -80,11 +240,11 @@ void Entity::setSkeletalModel(unsigned int model) {
80 240
     idleAnimation = 0;
81 241
 }
82 242
 
83
-unsigned int Entity::getAnimationFrame() {
243
+unsigned int Entity::getAnimation() {
84 244
     return animationFrame;
85 245
 }
86 246
 
87
-void Entity::setAnimationFrame(unsigned int index) {
247
+void Entity::setAnimation(unsigned int index) {
88 248
     animationFrame = index;
89 249
     boneFrame = 0;
90 250
 }

+ 13
- 12
src/Game.cpp ファイルの表示

@@ -17,6 +17,7 @@
17 17
 #include <algorithm>
18 18
 #include <map>
19 19
 #include <cstdlib>
20
+#include <assert.h>
20 21
 
21 22
 #include "main.h"
22 23
 #include "Console.h"
@@ -64,9 +65,9 @@ int Game::initialize() {
64 65
 void Game::destroy() {
65 66
     if (mName)
66 67
         delete [] mName;
67
-
68
+    mName = NULL;
68 69
     mLoaded = false;
69
-    mLara = NULL;
70
+    mLara = -1;
70 71
     getRender().setMode(Render::modeDisabled);
71 72
 
72 73
     getWorld().destroy();
@@ -123,7 +124,7 @@ int Game::loadLevel(const char *level) {
123 124
     mTombRaider.reset();
124 125
 
125 126
     // Check if the level contains Lara
126
-    if (mLara == NULL) {
127
+    if (mLara == -1) {
127 128
         getConsole().print("Can't find Lara entity in level pak!");
128 129
         return -1;
129 130
     }
@@ -137,13 +138,13 @@ int Game::loadLevel(const char *level) {
137 138
 void Game::handleAction(ActionEvents action, bool isFinished) {
138 139
     if (mLoaded) {
139 140
         if (action == forwardAction) {
140
-            getWorld().moveEntity(mLara, 'f');
141
+            getLara().move('f');
141 142
         } else if (action == backwardAction) {
142
-            getWorld().moveEntity(mLara, 'b');
143
+            getLara().move('b');
143 144
         } else if (action == leftAction) {
144
-            getWorld().moveEntity(mLara, 'l');
145
+            getLara().move('l');
145 146
         } else if (action == rightAction) {
146
-            getWorld().moveEntity(mLara, 'r');
147
+            getLara().move('r');
147 148
         }
148 149
     }
149 150
 }
@@ -167,13 +168,13 @@ void Game::handleMouseMotion(int xrel, int yrel) {
167 168
                 getCamera().command(CAMERA_ROTATE_DOWN);
168 169
 
169 170
         // Fix Laras rotation
170
-        mLara->angles[1] = getCamera().getRadianYaw();
171
-        mLara->angles[2] = getCamera().getRadianPitch();
171
+        getLara().setAngles(getCamera().getRadianYaw(), getCamera().getRadianPitch());
172 172
     }
173 173
 }
174 174
 
175 175
 Entity &Game::getLara() {
176
-    assert(mLara < getWorld().sizeEntity());
176
+    assert(mLara >= 0);
177
+    assert(mLara < (int)getWorld().sizeEntity());
177 178
     return getWorld().getEntity(mLara);
178 179
 }
179 180
 
@@ -385,14 +386,14 @@ void Game::processMoveable(int index, int i, int object_id) {
385 386
     bool cached = false;
386 387
     unsigned int mod = 0;
387 388
     for (; mod < getWorld().sizeSkeletalModel(); mod++) {
388
-        if (getWorld().getSkeletalModel(mod).getId() == moveable[index].object_id) {
389
+        if (getWorld().getSkeletalModel(mod).getId() == object_id) {
389 390
             cached = true;
390 391
             break;
391 392
         }
392 393
     }
393 394
 
394 395
     if (!cached) {
395
-        getWorld().addSkeletalModel(*new SkeletalModel(mTombRaider, index, i));
396
+        getWorld().addSkeletalModel(*new SkeletalModel(mTombRaider, index, i, object_id));
396 397
     }
397 398
 
398 399
     getWorld().addEntity(*new Entity(mTombRaider, index, i, mod));

+ 1
- 1
src/OpenRaider.cpp ファイルの表示

@@ -493,7 +493,7 @@ void OpenRaider::frame() {
493 493
     if (getGame().isLoaded()) {
494 494
         for (int i = 0; i < 3; i++) {
495 495
             getWindow().drawText(10, getWindow().mHeight - ((4 - i) * 20), 0.5f, OR_BLUE, "%.2f (%.2f)",
496
-                getGame().mLara->pos[i] / 256.0f, getGame().mLara->angles[i]);
496
+                getGame().getLara().getPos(i) / 256.0f, getGame().getLara().getAngle(i));
497 497
         }
498 498
     }
499 499
 #endif

+ 13
- 2
src/SkeletalModel.cpp ファイルの表示

@@ -146,11 +146,11 @@ void AnimationFrame::add(BoneFrame &b) {
146 146
     frame.push_back(&b);
147 147
 }
148 148
 
149
-SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i) {
149
+SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i, int objectId) {
150 150
     tr2_moveable_t *moveable = mTombRaider.Moveable();
151 151
     tr2_animation_t *anim = mTombRaider.Animation();
152 152
 
153
-    id = moveable[index].object_id;
153
+    id = objectId;
154 154
 
155 155
     // Gather more info if this is lara
156 156
     if (id == 0) {
@@ -244,6 +244,17 @@ int SkeletalModel::getId() {
244 244
     return id;
245 245
 }
246 246
 
247
+void SkeletalModel::setPigTail(bool b) {
248
+    pigtails = b;
249
+    if (b) {
250
+        ponyOff -= 20;
251
+        ponytail[1] -= 32;
252
+    } else {
253
+        ponyOff += 20;
254
+        ponytail[1] += 32;
255
+    }
256
+}
257
+
247 258
 unsigned int SkeletalModel::size() {
248 259
     return animation.size();
249 260
 }

+ 0
- 173
src/World.cpp ファイルの表示

@@ -27,179 +27,6 @@ void World::addMesh(model_mesh_t *mesh)
27 27
         mMeshes.push_back(mesh);
28 28
 }
29 29
 
30
-void World::moveEntity(entity_t *e, char movement)
31
-{
32
-    const float moved = 180.0f;
33
-    const float testd = 220.0f;
34
-    const float camHeight = 8.0f;
35
-    float x, y, z, pitch, h, floor, ceiling;
36
-    int room, sector;
37
-    bool wall;
38
-    unsigned int roomFlags;
39
-
40
-
41
-    if (!e)
42
-    {
43
-        return;
44
-    }
45
-
46
-    switch (e->moveType)
47
-    {
48
-        case worldMoveType_walkNoSwim:
49
-        case worldMoveType_walk:
50
-            pitch = 0.0f;  // in the future pitch could control jump up blocks here
51
-            break;
52
-
53
-        case worldMoveType_noClipping:
54
-        case worldMoveType_fly:
55
-        case worldMoveType_swim:
56
-            pitch = e->angles[2];
57
-            break;
58
-    }
59
-
60
-    switch (movement)
61
-    {
62
-        case 'f':
63
-            x = e->pos[0] + (testd * sinf(e->angles[1]));
64
-            y = e->pos[1] + (testd * sinf(pitch));
65
-            z = e->pos[2] + (testd * cosf(e->angles[1]));
66
-            break;
67
-        case 'b':
68
-            x = e->pos[0] - (testd * sinf(e->angles[1]));
69
-            y = e->pos[1] - (testd * sinf(pitch));
70
-            z = e->pos[2] - (testd * cosf(e->angles[1]));
71
-            break;
72
-        case 'l':
73
-            x = e->pos[0] - (testd * sinf(e->angles[1] + 90.0f));
74
-            y = e->pos[1];
75
-            z = e->pos[2] - (testd * cosf(e->angles[1] + 90.0f));
76
-            break;
77
-        case 'r':
78
-            x = e->pos[0] + (testd * sinf(e->angles[1] + 90.0f));
79
-            y = e->pos[1];
80
-            z = e->pos[2] + (testd * cosf(e->angles[1] + 90.0f));
81
-            break;
82
-        default:
83
-            return;
84
-    }
85
-
86
-    //room = getRoomByLocation(x, y, z);
87
-    room = getRoomByLocation(e->room, x, y, z);
88
-
89
-    if (room == -1) // Will we hit a portal?
90
-    {
91
-        room = getAdjoiningRoom(e->room,
92
-                e->pos[0],  e->pos[1], e->pos[2],
93
-                x, y, z);
94
-
95
-        if (room > -1)
96
-        {
97
-            printf("Crossing from room %i to %i\n", e->room, room);
98
-        } else {
99
-            //! \fixme mRooms, sectors, ... are now std::vector, but often upper bound checks are missing
100
-            return;
101
-        }
102
-    }
103
-
104
-    roomFlags = getRoomInfo(room);
105
-    sector = getSector(room, x, z, &floor, &ceiling);
106
-    wall = isWall(room, sector);
107
-
108
-    // If you're underwater you may want to swim  =)
109
-    // ...if you're worldMoveType_walkNoSwim, you better hope it's shallow
110
-    if (roomFlags & RoomFlagUnderWater && e->moveType == worldMoveType_walk)
111
-        e->moveType = worldMoveType_swim;
112
-
113
-    // Don't swim on land
114
-    if (!(roomFlags & RoomFlagUnderWater) && e->moveType == worldMoveType_swim)
115
-        e->moveType = worldMoveType_walk;
116
-
117
-    // Mongoose 2002.09.02, Add check for room -> room transition
118
-    //   ( Only allow by movement between rooms by using portals )
119
-    if (((e->moveType == worldMoveType_noClipping) ||
120
-                (e->moveType == worldMoveType_fly) ||
121
-                (e->moveType == worldMoveType_swim)) ||
122
-            ((room > -1) && (!wall)))
123
-    {
124
-        e->room = room;
125
-
126
-        switch (movement)
127
-        {
128
-            case 'f':
129
-                x = e->pos[0] + (moved * sinf(e->angles[1]));
130
-                y = e->pos[1] + (moved * sinf(pitch));
131
-                z = e->pos[2] + (moved * cosf(e->angles[1]));
132
-                break;
133
-            case 'b':
134
-                x = e->pos[0] - (moved * sinf(e->angles[1]));
135
-                y = e->pos[1] - (moved * sinf(pitch));
136
-                z = e->pos[2] - (moved * cosf(e->angles[1]));
137
-                break;
138
-            case 'l':
139
-                x = e->pos[0] - (moved * sinf(e->angles[1] + 90.0f));
140
-                z = e->pos[2] - (moved * cosf(e->angles[1] + 90.0f));
141
-                break;
142
-            case 'r':
143
-                x = e->pos[0] + (moved * sinf(e->angles[1] + 90.0f));
144
-                z = e->pos[2] + (moved * cosf(e->angles[1] + 90.0f));
145
-                break;
146
-        }
147
-
148
-        /*! \fixme Test for vector (move vector) / plane (portal) collision here
149
-         * to see if we need to switch rooms... man...
150
-         */
151
-
152
-        h = y;
153
-        getHeightAtPosition(room, x, &h, z);
154
-
155
-        switch (e->moveType)
156
-        {
157
-            case worldMoveType_fly:
158
-            case worldMoveType_swim:
159
-                // Don't fall out of world, avoid a movement that does
160
-                if (h > y - camHeight)
161
-                {
162
-                    e->pos[0] = x;
163
-                    e->pos[1] = y;
164
-                    e->pos[2] = z;
165
-                }
166
-                break;
167
-            case worldMoveType_walk:
168
-            case worldMoveType_walkNoSwim:
169
-                y = e->pos[1];  // Override vector movement walking ( er, not pretty )
170
-
171
-                // Now fake gravity
172
-                // Mongoose 2002.08.14, Remember TR is upside down ( you fall 'up' )
173
-
174
-                //ddist = h - e->pos[1];
175
-
176
-                // This is to force false gravity, by making camera stay on ground
177
-                e->pos[1] = h; //roomFloor->bbox_min[1];
178
-
179
-                // Check for camera below terrian and correct
180
-                if (e->pos[1] < h - camHeight)
181
-                {
182
-                    e->pos[1] = h - camHeight;
183
-                }
184
-
185
-                e->pos[0] = x;
186
-                e->pos[2] = z;
187
-                break;
188
-            case worldMoveType_noClipping:
189
-                e->pos[0] = x;
190
-                e->pos[1] = y;
191
-                e->pos[2] = z;
192
-        }
193
-    }
194
-    else
195
-    {
196
-        return;
197
-    }
198
-
199
-    e->room = room;
200
-}
201
-
202
-
203 30
 void World::addRoom(Room &room) {
204 31
     mRooms.push_back(&room);
205 32
 }

読み込み中…
キャンセル
保存