Browse Source

Simplified SkeletalModel/AnimationFrame/... constructors

Thomas Buck 10 years ago
parent
commit
55d27f888c
2 changed files with 14 additions and 23 deletions
  1. 2
    2
      include/SkeletalModel.h
  2. 12
    21
      src/SkeletalModel.cpp

+ 2
- 2
include/SkeletalModel.h View File

16
 
16
 
17
 class BoneTag {
17
 class BoneTag {
18
 public:
18
 public:
19
-    BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l, unsigned short **frame, unsigned int *frame_offset);
19
+    BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l, unsigned int frame_offset);
20
     void display();
20
     void display();
21
 
21
 
22
     void getOffset(vec3_t o);
22
     void getOffset(vec3_t o);
32
 
32
 
33
 class BoneFrame {
33
 class BoneFrame {
34
 public:
34
 public:
35
-    BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned short **frame, unsigned int *frame_offset);
35
+    BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned int frame_offset);
36
     ~BoneFrame();
36
     ~BoneFrame();
37
 
37
 
38
     void getPosition(vec3_t p);
38
     void getPosition(vec3_t p);

+ 12
- 21
src/SkeletalModel.cpp View File

12
 #include "SkeletalModel.h"
12
 #include "SkeletalModel.h"
13
 #include "World.h"
13
 #include "World.h"
14
 
14
 
15
-BoneTag::BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l, unsigned short **frame, unsigned int *frame_offset) {
15
+BoneTag::BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l, unsigned int frame_offset) {
16
     tr2_moveable_t *moveable = tr.Moveable();
16
     tr2_moveable_t *moveable = tr.Moveable();
17
     tr2_meshtree_t *meshtree = tr.MeshTree();
17
     tr2_meshtree_t *meshtree = tr.MeshTree();
18
+    unsigned short *frame = tr.Frame();
18
 
19
 
19
     off[0] = 0.0;
20
     off[0] = 0.0;
20
     off[1] = 0.0;
21
     off[1] = 0.0;
44
     }
45
     }
45
 
46
 
46
     // Setup tag rotations
47
     // Setup tag rotations
47
-    tr.computeRotationAngles(frame, frame_offset, l, rot, rot+1, rot+2);
48
+    tr.computeRotationAngles(&frame, &frame_offset, l, rot, rot + 1, rot + 2);
48
 }
49
 }
49
 
50
 
50
 void BoneTag::display() {
51
 void BoneTag::display() {
67
     return flag;
68
     return flag;
68
 }
69
 }
69
 
70
 
70
-BoneFrame::BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned short **frame, unsigned int *frame_offset) {
71
+BoneFrame::BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned int frame_offset) {
71
     tr2_moveable_t *moveable = tr.Moveable();
72
     tr2_moveable_t *moveable = tr.Moveable();
72
     tr2_item_t *item = tr.Item();
73
     tr2_item_t *item = tr.Item();
74
+    unsigned short *frame = tr.Frame();
73
 
75
 
74
-    /*!
75
-     * \fixme Do we really need to keep frame and frame_offset
76
-     * at the top level, passing pointers?!
77
-     */
78
-
79
-    pos[0] = (short)((*frame)[(*frame_offset) + 6]);
80
-    pos[1] = (short)((*frame)[(*frame_offset) + 7]);
81
-    pos[2] = (short)((*frame)[(*frame_offset) + 8]);
76
+    pos[0] = (short)(frame[frame_offset + 6]);
77
+    pos[1] = (short)(frame[frame_offset + 7]);
78
+    pos[2] = (short)(frame[frame_offset + 8]);
82
 
79
 
83
     yaw = ((item[i].angle >> 14) & 0x03);
80
     yaw = ((item[i].angle >> 14) & 0x03);
84
     yaw *= 90;
81
     yaw *= 90;
87
 
84
 
88
     // Run through the tag and calculate the rotation and offset
85
     // Run through the tag and calculate the rotation and offset
89
     for (int j = 0; j < (int)moveable[index].num_meshes; ++j)
86
     for (int j = 0; j < (int)moveable[index].num_meshes; ++j)
90
-        tag.push_back(new BoneTag(tr, index, j, &l, frame, frame_offset));
87
+        tag.push_back(new BoneTag(tr, index, j, &l, frame_offset));
91
 }
88
 }
92
 
89
 
93
 BoneFrame::~BoneFrame() {
90
 BoneFrame::~BoneFrame() {
113
 AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, unsigned int i, int a) {
110
 AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, unsigned int i, int a) {
114
     tr2_moveable_t *moveable = tr.Moveable();
111
     tr2_moveable_t *moveable = tr.Moveable();
115
     tr2_animation_t *animation = tr.Animation();
112
     tr2_animation_t *animation = tr.Animation();
116
-    unsigned short *fr = tr.Frame();
117
 
113
 
118
     unsigned int frame_offset = animation[a].frame_offset / 2;
114
     unsigned int frame_offset = animation[a].frame_offset / 2;
119
     int frame_step = animation[a].frame_size;
115
     int frame_step = animation[a].frame_size;
148
         }
144
         }
149
 
145
 
150
         if (frame_offset > tr.NumFrames()) {
146
         if (frame_offset > tr.NumFrames()) {
151
-            getConsole().print("WARNING: Bad animation frame %i > %i",
152
-                    frame_offset, tr.NumFrames());
147
+            getConsole().print("WARNING: Bad animation frame %i > %i (%u.%u.%d)",
148
+                    frame_offset, tr.NumFrames(), index, i, a);
153
             return;
149
             return;
154
         }
150
         }
155
 
151
 
156
-        frame.push_back(new BoneFrame(tr, index, i, &fr, &frame_offset));
152
+        frame.push_back(new BoneFrame(tr, index, i, frame_offset));
157
     }
153
     }
158
 }
154
 }
159
 
155
 
273
     AnimationFrame &anim = get(aframe);
269
     AnimationFrame &anim = get(aframe);
274
     BoneFrame &boneframe = anim.get(bframe);
270
     BoneFrame &boneframe = anim.get(bframe);
275
 
271
 
276
-    if (boneframe.size() == 0) {
277
-        printf("Empty bone frame?!?!\n");
278
-        return;
279
-    }
280
-
281
     vec3_t pos;
272
     vec3_t pos;
282
     boneframe.getPosition(pos);
273
     boneframe.getPosition(pos);
283
     glTranslatef(pos[0], pos[1], pos[2]);
274
     glTranslatef(pos[0], pos[1], pos[2]);

Loading…
Cancel
Save