Browse Source

Compiles but segfaults on level load

Thomas Buck 10 years ago
parent
commit
afe8cb1122
3 changed files with 101 additions and 32 deletions
  1. 4
    4
      include/SkeletalModel.h
  2. 33
    0
      src/Entity.cpp
  3. 64
    28
      src/SkeletalModel.cpp

+ 4
- 4
include/SkeletalModel.h View File

@@ -16,7 +16,7 @@
16 16
 
17 17
 class BoneTag {
18 18
 public:
19
-    BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l);
19
+    BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l, unsigned short **frame, unsigned int *frame_offset);
20 20
     void display();
21 21
 
22 22
     void getOffset(vec3_t o);
@@ -32,12 +32,13 @@ private:
32 32
 
33 33
 class BoneFrame {
34 34
 public:
35
-    BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned int frame_offset);
35
+    BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned short **frame, unsigned int *frame_offset);
36 36
     ~BoneFrame();
37 37
 
38
+    void getPosition(vec3_t p);
39
+
38 40
     unsigned int size();
39 41
     BoneTag &get(unsigned int i);
40
-    void add(BoneTag &b);
41 42
 
42 43
 private:
43 44
     vec3_t pos;
@@ -52,7 +53,6 @@ public:
52 53
 
53 54
     unsigned int size();
54 55
     BoneFrame &get(unsigned int i);
55
-    void add(BoneFrame &b);
56 56
 
57 57
 private:
58 58
     char rate;

+ 33
- 0
src/Entity.cpp View File

@@ -240,6 +240,10 @@ void Entity::print() {
240 240
     getConsole().print("  %.1f Yaw %.1f Pitch", OR_RAD_TO_DEG(angles[1]), OR_RAD_TO_DEG(angles[2]));
241 241
 }
242 242
 
243
+SkeletalModel &Entity::getModel() {
244
+    return getWorld().getSkeletalModel(skeletalModel);
245
+}
246
+
243 247
 void Entity::setSkeletalModel(unsigned int model) {
244 248
     skeletalModel = model;
245 249
     animationFrame = 0;
@@ -247,6 +251,35 @@ void Entity::setSkeletalModel(unsigned int model) {
247 251
     idleAnimation = 0;
248 252
 }
249 253
 
254
+Entity::MoveType Entity::getMoveType() {
255
+    return moveType;
256
+}
257
+
258
+void Entity::setMoveType(MoveType m) {
259
+    moveType = m;
260
+}
261
+
262
+int Entity::getObjectId() {
263
+    return objectId;
264
+}
265
+
266
+void Entity::setAngles(vec_t yaw, vec_t pitch) {
267
+    angles[1] = yaw;
268
+    angles[2] = pitch;
269
+}
270
+
271
+vec_t Entity::getPos(unsigned int i) {
272
+    return pos[i];
273
+}
274
+
275
+vec_t Entity::getAngle(unsigned int i) {
276
+    return angles[i];
277
+}
278
+
279
+int Entity::getRoom() {
280
+    return room;
281
+}
282
+
250 283
 unsigned int Entity::getAnimation() {
251 284
     return animationFrame;
252 285
 }

+ 64
- 28
src/SkeletalModel.cpp View File

@@ -6,12 +6,23 @@
6 6
  * \author xythobuz
7 7
  */
8 8
 
9
+#ifdef __APPLE__
10
+#include <OpenGL/gl.h>
11
+#include <OpenGL/glu.h>
12
+#elif defined WIN32
13
+#include <gl/glew.h>
14
+#include <gl/wglew.h>
15
+#else
16
+#include <GL/gl.h>
17
+#include <GL/glu.h>
18
+#endif
19
+
9 20
 #include <assert.h>
10 21
 
11 22
 #include "main.h"
12 23
 #include "SkeletalModel.h"
13 24
 
14
-BoneTag::BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l) {
25
+BoneTag::BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l, unsigned short **frame, unsigned int *frame_offset) {
15 26
     tr2_moveable_t *moveable = tr.Moveable();
16 27
     tr2_meshtree_t *meshtree = tr.MeshTree();
17 28
 
@@ -43,20 +54,36 @@ BoneTag::BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l) {
43 54
     }
44 55
 
45 56
     // Setup tag rotations
46
-    tr.computeRotationAngles(&frame, &frame_offset, l, rot, rot+1, rot+2);
57
+    tr.computeRotationAngles(frame, frame_offset, l, rot, rot+1, rot+2);
47 58
 }
48 59
 
49
-BoneTag::display() {
60
+void BoneTag::display() {
50 61
     getRender().drawModelMesh(getWorld().getMesh(mesh));
51 62
 }
52 63
 
53
-BoneFrame::BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned int frame_offset) {
64
+void BoneTag::getOffset(vec3_t o) {
65
+    o[0] = off[0];
66
+    o[1] = off[1];
67
+    o[2] = off[2];
68
+}
69
+
70
+void BoneTag::getRotation(vec3_t r) {
71
+    r[0] = rot[0];
72
+    r[1] = rot[1];
73
+    r[2] = rot[2];
74
+}
75
+
76
+char BoneTag::getFlag() {
77
+    return flag;
78
+}
79
+
80
+BoneFrame::BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned short **frame, unsigned int *frame_offset) {
54 81
     tr2_moveable_t *moveable = tr.Moveable();
55
-    unsigned short *frame = tr.Frame();
82
+    tr2_item_t *item = tr.Item();
56 83
 
57
-    pos[0] = (short)frame[frame_offset + 6];
58
-    pos[1] = (short)frame[frame_offset + 7];
59
-    pos[2] = (short)frame[frame_offset + 8];
84
+    pos[0] = (short)*frame[*frame_offset + 6];
85
+    pos[1] = (short)*frame[*frame_offset + 7];
86
+    pos[2] = (short)*frame[*frame_offset + 8];
60 87
 
61 88
     yaw = ((item[i].angle >> 14) & 0x03);
62 89
     yaw *= 90;
@@ -65,7 +92,7 @@ BoneFrame::BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigne
65 92
 
66 93
     // Run through the tag and calculate the rotation and offset
67 94
     for (int j = 0; j < (int)moveable[index].num_meshes; ++j)
68
-        tag.push_back(*new BoneTag(tr, index, j, &l));
95
+        tag.push_back(new BoneTag(tr, index, j, &l, frame, frame_offset));
69 96
 }
70 97
 
71 98
 BoneFrame::~BoneFrame() {
@@ -82,13 +109,16 @@ BoneTag &BoneFrame::get(unsigned int i) {
82 109
     return *tag.at(i);
83 110
 }
84 111
 
85
-void BoneFrame::add(BoneTag &b) {
86
-    tag.push_back(&b);
112
+void BoneFrame::getPosition(vec3_t p) {
113
+    p[0] = pos[0];
114
+    p[1] = pos[1];
115
+    p[2] = pos[2];
87 116
 }
88 117
 
89 118
 AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, unsigned int i, int a) {
90 119
     tr2_moveable_t *moveable = tr.Moveable();
91 120
     tr2_animation_t *animation = tr.Animation();
121
+    unsigned short *fr = tr.Frame();
92 122
 
93 123
     unsigned int frame_offset = animation[a].frame_offset / 2;
94 124
     int frame_step = animation[a].frame_size;
@@ -128,7 +158,7 @@ AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, unsigned int
128 158
             return;
129 159
         }
130 160
 
131
-        frame.push_back(*new BoneFrame(tr, index, i, frame_offset));
161
+        frame.push_back(new BoneFrame(tr, index, i, &fr, &frame_offset));
132 162
     }
133 163
 }
134 164
 
@@ -146,13 +176,10 @@ BoneFrame &AnimationFrame::get(unsigned int i) {
146 176
     return *frame.at(i);
147 177
 }
148 178
 
149
-void AnimationFrame::add(BoneFrame &b) {
150
-    frame.push_back(&b);
151
-}
152
-
153 179
 SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i, int objectId) {
154 180
     tr2_moveable_t *moveable = tr.Moveable();
155 181
     tr2_animation_t *anim = tr.Animation();
182
+    tr2_mesh_t *mesh = tr.Mesh();
156 183
 
157 184
     id = objectId;
158 185
 
@@ -199,7 +226,7 @@ SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i,
199 226
         case TR_VERSION_5:
200 227
         case TR_VERSION_UNKNOWN:
201 228
             if (moveable[index].object_id == 2) {
202
-                ponytailId = k;
229
+                ponytailId = getWorld().sizeSkeletalModel(); //! \fixme Why is this even needed?
203 230
                 ponytailMeshId = moveable[index].starting_mesh;
204 231
                 ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
205 232
                         moveable[index].num_meshes : 0);
@@ -234,7 +261,7 @@ SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i,
234 261
         return;
235 262
     } else {
236 263
         for (; a < tr.getNumAnimsForMoveable(index); a++) {
237
-            animation.push_back(new AnimationFrame(tr, index, i, a))
264
+            animation.push_back(new AnimationFrame(tr, index, i, a));
238 265
         }
239 266
     }
240 267
 }
@@ -248,15 +275,17 @@ void SkeletalModel::display(unsigned int aframe, unsigned int bframe) {
248 275
     assert(aframe < size());
249 276
     assert(bframe < get(aframe).size());
250 277
 
251
-    AnimationFrame &animation = get(aframe);
252
-    BoneFrame &boneframe = animation.get(bframe);
278
+    AnimationFrame &anim = get(aframe);
279
+    BoneFrame &boneframe = anim.get(bframe);
253 280
 
254 281
     if (boneframe.size() == 0) {
255 282
         printf("Empty bone frame?!?!\n");
256 283
         return;
257 284
     }
258 285
 
259
-    glTranslatef(boneframe->pos[0], boneframe->pos[1], boneframe->pos[2]);
286
+    vec3_t pos;
287
+    boneframe.getPosition(pos);
288
+    glTranslatef(pos[0], pos[1], pos[2]);
260 289
 
261 290
     for (unsigned int a = 0; a < boneframe.size(); a++) {
262 291
         BoneTag &tag = boneframe.get(a);
@@ -300,7 +329,7 @@ void SkeletalModel::display(unsigned int aframe, unsigned int bframe) {
300 329
         }
301 330
 
302 331
         if (getRender().getFlags() & Render::fRenderPonytail) {
303
-            if ((mdl->ponytailId > 0) && (a == 14)) {
332
+            if ((ponytailId > 0) && (a == 14)) {
304 333
                 glPushMatrix();
305 334
 
306 335
                 // Mongoose 2002.08.30, TEST to align offset
@@ -313,7 +342,7 @@ void SkeletalModel::display(unsigned int aframe, unsigned int bframe) {
313 342
                     glScalef(1.20f, 1.20f, 1.20f);
314 343
 
315 344
 #ifdef EXPERIMENTAL_NON_ITEM_RENDER
316
-                getWorld().getSkeletalModel(mdl->ponytail).display(0, 0);
345
+                getWorld().getSkeletalModel(ponytail).display(0, 0);
317 346
 #else
318 347
                 for (unsigned int i = 0; i < ponytailNumMeshes; i++) {
319 348
                     glPushMatrix();
@@ -327,16 +356,16 @@ void SkeletalModel::display(unsigned int aframe, unsigned int bframe) {
327 356
 
328 357
                     if (pigtails) {
329 358
                         glPushMatrix();
330
-                        glTranslatef(mdl->ponyOff2, 0.0, 0.0);
331
-                        getRender().drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
359
+                        glTranslatef(ponyOff2, 0.0, 0.0);
360
+                        getRender().drawModelMesh(getWorld().getMesh(ponytailMeshId + i));
332 361
                         glPopMatrix();
333 362
 
334 363
                         glPushMatrix();
335
-                        glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
336
-                        getRender().drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
364
+                        glTranslatef(-ponyOff2, 0.0, 0.0);
365
+                        getRender().drawModelMesh(getWorld().getMesh(ponytailMeshId + i));
337 366
                         glPopMatrix();
338 367
                     } else {
339
-                        getRender().drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
368
+                        getRender().drawModelMesh(getWorld().getMesh(ponytailMeshId + i));
340 369
                     }
341 370
                 }
342 371
 
@@ -366,6 +395,13 @@ void SkeletalModel::setPigTail(bool b) {
366 395
     }
367 396
 }
368 397
 
398
+void SkeletalModel::setPonyPos(vec_t x, vec_t y, vec_t z, vec_t angle) {
399
+    ponytail[0] = x;
400
+    ponytail[1] = y;
401
+    ponytail[2] = z;
402
+    ponytailAngle = angle;
403
+}
404
+
369 405
 unsigned int SkeletalModel::size() {
370 406
     return animation.size();
371 407
 }

Loading…
Cancel
Save