Browse Source

Fixed SkeletalModel animation creation

Thomas Buck 11 years ago
parent
commit
e59892542e
4 changed files with 20 additions and 18 deletions
  1. 3
    0
      ChangeLog.md
  2. 2
    8
      TODO.md
  3. 1
    1
      include/SkeletalModel.h
  4. 14
    9
      src/SkeletalModel.cpp

+ 3
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20140617 ]
6
+    * Finally fixed SkeletalModel bug introduced a month ago
7
+
5
     [ 20140615 ]
8
     [ 20140615 ]
6
     * Added FontManager, selecting Font library to use depending on
9
     * Added FontManager, selecting Font library to use depending on
7
       the file extension of the font file specified in the config.
10
       the file extension of the font file specified in the config.

+ 2
- 8
TODO.md View File

2
 
2
 
3
 ## General
3
 ## General
4
 
4
 
5
-There are these DebugModel, DebugMap flags...?
6
-
7
 * Endian dependence ugly, shouldn't dereference to different types?
5
 * Endian dependence ugly, shouldn't dereference to different types?
8
     * TombRaider.h/cpp structs aren't aligned... unportable to some big endian & other archs?!
6
     * TombRaider.h/cpp structs aren't aligned... unportable to some big endian & other archs?!
9
 * Use more asserts
7
 * Use more asserts
10
 * Don't use C-Style code, try to replace with C++ lib
8
 * Don't use C-Style code, try to replace with C++ lib
11
-    * Use shared_ptr, should make memory handling/segfaults much less of a problem
12
-        * Don't even new ... the data structures but use std::make_shared or allocate_shared?
13
-        * Pass object references to all other objects that need it, completely remove gOpenRaider
14
     * Use std::strings
9
     * Use std::strings
15
-    * Rewrite Console and use operator << to write to the console
10
+    * Rewrite Console and use operator << to write to the console?
16
 * SDL_TTF 2.0.12+ can do line breaks, use it: http://stackoverflow.com/questions/17847818/how-to-do-line-breaks-and-line-wrapping-with-sdl-ttf/18418688#18418688
11
 * SDL_TTF 2.0.12+ can do line breaks, use it: http://stackoverflow.com/questions/17847818/how-to-do-line-breaks-and-line-wrapping-with-sdl-ttf/18418688#18418688
17
 
12
 
18
 ## Changes
13
 ## Changes
19
 
14
 
20
 * Using std::vector with [] is not bound checked. Segfaults were caused because the upper bound of the argument was never checked and garbage was returned... Do consistent checks, or use .at() as it throws an exception
15
 * Using std::vector with [] is not bound checked. Segfaults were caused because the upper bound of the argument was never checked and garbage was returned... Do consistent checks, or use .at() as it throws an exception
21
-* The wrong SkeletalModels are used by entities, except for Lara...?
22
 
16
 
23
 ## Cmake
17
 ## Cmake
24
 
18
 
28
 
22
 
29
 ## Future Features
23
 ## Future Features
30
 
24
 
31
-* Use only assets from old TR games, not even depending on a font file?
32
 * Cut TGA image reader, currently only used for menu background?!
25
 * Cut TGA image reader, currently only used for menu background?!
26
+    * Abstract image reading/writing, like Font Engine selection
33
 * When cutscene rendering is working, use TR4/5 style menu?
27
 * When cutscene rendering is working, use TR4/5 style menu?
34
 
28
 

+ 1
- 1
include/SkeletalModel.h View File

47
 
47
 
48
 class AnimationFrame {
48
 class AnimationFrame {
49
 public:
49
 public:
50
-    AnimationFrame(TombRaider &tr, unsigned int index, int a);
50
+    AnimationFrame(TombRaider &tr, unsigned int index, int a, unsigned int *frame_offset, int frame_step);
51
     ~AnimationFrame();
51
     ~AnimationFrame();
52
 
52
 
53
     unsigned int size();
53
     unsigned int size();

+ 14
- 9
src/SkeletalModel.cpp View File

102
     p[2] = pos[2];
102
     p[2] = pos[2];
103
 }
103
 }
104
 
104
 
105
-AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, int a) {
105
+AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, int a, unsigned int *frame_offset, int frame_step) {
106
     tr2_moveable_t *moveable = tr.Moveable();
106
     tr2_moveable_t *moveable = tr.Moveable();
107
     tr2_animation_t *animation = tr.Animation();
107
     tr2_animation_t *animation = tr.Animation();
108
 
108
 
109
-    unsigned int frame_offset = animation[a].frame_offset / 2;
110
-    int frame_step = animation[a].frame_size;
111
     unsigned int frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
109
     unsigned int frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
112
     rate = animation[a].frame_rate;
110
     rate = animation[a].frame_rate;
113
 
111
 
114
-    for (unsigned int f = 0; f < frame_count; f++, frame_offset += frame_step) {
112
+    for (unsigned int f = 0; f < frame_count; f++, *frame_offset += frame_step) {
115
         // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
113
         // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
116
         // quick substitution (so she doesn't appear as a bunch of thighs)
114
         // quick substitution (so she doesn't appear as a bunch of thighs)
117
         if ((index == 0) && (tr.Engine() == TR_VERSION_3)) {
115
         if ((index == 0) && (tr.Engine() == TR_VERSION_3)) {
138
             }
136
             }
139
         }
137
         }
140
 
138
 
141
-        if (frame_offset > tr.NumFrames()) {
139
+        if (*frame_offset > tr.NumFrames()) {
142
             getConsole().print("WARNING: Bad animation frame %i > %i (%u.%d)",
140
             getConsole().print("WARNING: Bad animation frame %i > %i (%u.%d)",
143
-                    frame_offset, tr.NumFrames(), index, a);
141
+                    *frame_offset, tr.NumFrames(), index, a);
144
             return;
142
             return;
145
         }
143
         }
146
 
144
 
147
-        frame.push_back(new BoneFrame(tr, index, frame_offset));
145
+        frame.push_back(new BoneFrame(tr, index, *frame_offset));
148
     }
146
     }
149
 }
147
 }
150
 
148
 
234
     unsigned int frame_offset = anim[a].frame_offset / 2;
232
     unsigned int frame_offset = anim[a].frame_offset / 2;
235
     int frame_step = anim[a].frame_size;
233
     int frame_step = anim[a].frame_size;
236
 
234
 
235
+    int frame_cycle = 0;
236
+
237
     if (a >= (int)tr.NumAnimations())
237
     if (a >= (int)tr.NumAnimations())
238
         a = tr.NumFrames() - frame_offset; //! \fixme Couldn't a be already used out of range?!
238
         a = tr.NumFrames() - frame_offset; //! \fixme Couldn't a be already used out of range?!
239
     else
239
     else
240
-        a = (anim[a].frame_offset / 2) - frame_offset;
240
+        a = (anim[a].frame_offset / 2) - frame_offset; //! \fixme Same as a = 0; ??
241
 
241
 
242
     if (frame_step != 0) // prevent divide-by-zero errors
242
     if (frame_step != 0) // prevent divide-by-zero errors
243
         a /= frame_step;
243
         a /= frame_step;
244
 
244
 
245
+    if (a != 0)
246
+        frame_offset += frame_step * (frame_cycle % a);
247
+
245
     if (a < 0) {
248
     if (a < 0) {
246
         getConsole().print("Invalid animation data for model %d. Skip!", index);
249
         getConsole().print("Invalid animation data for model %d. Skip!", index);
247
         return;
250
         return;
248
     } else {
251
     } else {
249
         for (; a < tr.getNumAnimsForMoveable(index); a++) {
252
         for (; a < tr.getNumAnimsForMoveable(index); a++) {
250
-            animation.push_back(new AnimationFrame(tr, index, a));
253
+            animation.push_back(new AnimationFrame(tr, index, a, &frame_offset, frame_step));
254
+            frame_offset = anim[a].frame_offset / 2;
255
+            frame_step = anim[a].frame_size;
251
         }
256
         }
252
     }
257
     }
253
 }
258
 }

Loading…
Cancel
Save