Mario Kart 64
Loading...
Searching...
No Matches
animation.h
Go to the documentation of this file.
1#ifndef CODE_80004740_H
2#define CODE_80004740_H
3
4#include <common_structs.h>
5
6/*
7What I know about animation stuff so far
8
9Its not clear to me exactly what animations even are in MK64, my speculation is that their some form of matrix
10manipulation sequence. Presumably the "models" of the objects that are getting animated are a bunch of matrices and the
11animations somehow change them. animation appears to be responsible for the handling of animations. Animation seem to be
12reserved for objects, namely: seagulls in KTB, flags in YV, chain chomps in RR, and penguins in SL.
13
14Each object has 2 pointers of interest, at offsets 0x70 and 0x74 (unk_070 and unk_074).
15These are passed to render_animated_model, along with what appears to be an index and a timer.
16render_animated_model(unk70, unk74, index, timer)
17
18unk_070 points to what I will call a "Type 1" array.
19I call it an array, but I don't think that's entirely accurate.
20There are 4 potential "types" of "type 1" arrays: 0, 1, 2, and 3
21Only type 0 has anything below the "size" entry.
22The rest only have the type and size.
23The contents look like this struct
24struct {
25 s32 type;
26 s32 size;
27 s32 always_zero_never_used;
28 s32 maybe_a_dl_pointer_maybe_null;
29 s32 thing1;
30 s32 thing2;
31 s32 thing3;
32}
33Again, note that types 1, 2, and 3 only have the "type" and "size" elements.
34
35They are handled in render_armature.
36Each "type" indicates a different action to take while iterating over the array.
37Type 1: Only used to modify Type 0's behaviour
38Type 2: Pop a matrix
39Type 3: End of array, stop processing
40Type 0: Always handles some part of the animation. If preceded by a Type 1 entry it will pop a matrix prior to the
41animation handling.
42
43The "size" entry is used in a weird way. If you have a set of entries like:
44
45 0x00000001, <- Our unk_070 pointer starts here
46 0x00000002,
47
48 0x00000000,
49 0x00000007,
50 0x00000000,
51 0x00000000,
52 0x00000000,
53 0x00000000,
54 0x00000000,
55
56 0x00000001,
57 0x00000002,
58
59Then the size of 2 in the first entry is used to move the pointer 2 words forward
60
61 0x00000001,
62 0x00000002,
63
64 0x00000000, <- Goes here
65 0x00000007,
66 0x00000000,
67 0x00000000,
68 0x00000000,
69 0xfffffffb, (this is really -5)
70 0x00000005,
71
72 0x00000001,
73 0x00000002,
74
75Then, the 7 does the same thing
76
77 0x00000001,
78 0x00000002,
79
80 0x00000000,
81 0x00000007,
82 0x00000000,
83 0x00000000,
84 0x00000000,
85 0x00000000,
86 0x00000000,
87
88 0x00000001, <- Now we're here
89 0x00000002,
90
91This is why I don't think referring to this as an "array" is really correct.
92Iterating over this data not like iterating over a proper array at all.
93
94I don't really understand the "thing" entries yet.
95They seem to be used in render_limb_or_add_mtx to set some values in Vec3f which is then used to set some values in a
96Mat4. This, I assume, is related to the matrix maniplation stuff that's used to actually accomplish the animation.
97
98The unk_074 pointer points to a list of other pointers.
99As best as I can tell only the penguins actually have multiple entries in this list, all the other animated objects have
100just 1 entry. The pointers in this list have entires that look like this struct:
101
102struct {
103 s32 always_set_to_something_but_never_used;
104 s32 always_zero_never_used;
105 s/u16 animation_length;
106 s/u16 has_value_but_never_used;
107 s32 angle_array;
108 s32 AnimationCycleSpecVector;
109}
110
111I will refer to these structs as Struct 2's.
112
113Type 2 arrays appear to be just s/u16 arrays.
114Their use will be discussed later
115
116Type 3 arrays appear to be arrays of pairs of s/u16 numbers that look like this struct:
117
118struct {
119 s/u16 animation_length;
120 s/u16 indexCycle;
121};
122
123Type 3 entires are interesting.
124They're used in render_armature and render_limb_or_add_mtx, and they're always used in triples
125The `timer` argument to render_animated_model is compared to the `animation_length` entry.
126If it less than the limiter then its value it used elsewhere, otherwise 0 is used (more details below).
127The `indexCycle` value is always used.
128
129Then, the 2 chosen values are used to select a value from the Type 2 array.
130So, for example, if you have a Struct 2 like:
131
132
133 0x00010000,
134 0x00000000,
135 0x0037, <- animation lenght
136 0x000a,
137 d_course_koopa_troopa_beach_unk_data2,
138 d_course_koopa_troopa_beach_unk_data3,
139
140d_course_koopa_troopa_beach_unk_data2 should be a Type 2 array while d_course_koopa_troopa_beach_unk_data3 is a Type 3
141array.
142
143d_course_koopa_troopa_beach_unk_data3 has entries that look like:
144 //limiter //offset
145 0x0001, 0x0000,
146 0x0037, 0x0001,
147 0x0001, 0x0000,
148
149In practice the limiter value is always 1 or the animation length, meaning that you either choose 0 or the current
150animation timer. There's never a situation where you will choose the animation timer until it hits X and then swap to 0.
151Its always one or the other, never swapping.
152
153The first triplet is used in render_armature to access the Type 2 array and the values accessed is placed into
154sOriginalPosAnimation. sOriginalPosAnimation is a Vec3s is then used to set the values of some Vec3f in
155render_limb_or_add_mtx. All further triplets are used in render_limb_or_add_mtx to collect Type 2 values to another
156Vec3s local to the function. Both the local Vec3s and Vec3f are used to create a Mat4, which is then converted to a Mtx,
157which is then pushed into the matrix pool.
158
159The chosen values are then used to access the Type 2 array and the value accessed is placed into sOriginalPosAnimation.
160sOriginalPosAnimation is a Vec3s that is used to set values in the some Vec3f that goes on to be used to modify the same
161Mat4 that the `thing` values are placed into.
162
163*/
164
165#define SIMPLE_ANIMATION_INSTRUCTION(x) x, 0x00000002
166
167#define ANIMATION_DISABLE_AUTOMATIC_POP SIMPLE_ANIMATION_INSTRUCTION(DISABLE_AUTOMATIC_POP_MATRIX)
168#define ANIMATION_POP_MATRIX SIMPLE_ANIMATION_INSTRUCTION(POP_MATRIX)
169#define ANIMATION_STOP SIMPLE_ANIMATION_INSTRUCTION(STOP_ANIMATION)
171#define ANIMATION_RENDER_MODEL_AT(model, x, y, z) RENDER_MODEL_OR_ADD_POS, 0x00000007, 0x00000000, (u32) model, x, y, z
173#define ANIMATION_RENDER_MODEL(model) ANIMATION_RENDER_MODEL_AT(model, 0x00000000, 0x00000000, 0x00000000)
175#define ANIMATION_ADD_POS(x, y, z) ANIMATION_RENDER_MODEL_AT((u32) NULL, x, y, z)
176
178
183typedef struct {
184 /* 0x00 */ s32 type;
185 /* 0x04 */ s32 size;
187 /* 0x0C */ Gfx* model;
188 /* 0x10 */ s32 pos[3];
189} Armature;
190
191typedef struct {
193 /* 0x02 */ u16 indexCycle;
195
199
208
209/* Function Prototypes */
210
212void mtxf_translate_rotate2(Mat4 dest, Vec3f pos, Vec3s angle);
217
218#endif
void render_armature(Armature *, Animation *, s16)
Definition animation.c:106
s16 render_animated_model(Armature *, Animation **, s16, s16)
Definition animation.c:154
animation_type
Definition animation.h:177
@ DISABLE_AUTOMATIC_POP_MATRIX
Definition animation.h:177
@ POP_MATRIX
Definition animation.h:177
@ STOP_ANIMATION
Definition animation.h:177
@ RENDER_MODEL_OR_ADD_POS
Definition animation.h:177
void render_limb_or_add_mtx(Armature *, s16 *, AnimationLimbVector, s32)
Definition animation.c:67
void convert_to_fixed_point_matrix_animation(Mtx *dest, Mat4 src)
Definition animation.c:16
AnimationCycleSpec AnimationLimbVector[3]
Definition animation.h:198
void mtxf_translate_rotate2(Mat4 dest, Vec3f pos, Vec3s angle)
Definition animation.c:36
s16 get_animation_length(Animation **, s16)
Definition animation.c:174
f32 Vec3f[3]
Definition common_structs.h:6
s16 Vec3s[3]
Definition common_structs.h:11
f32 Mat4[4][4]
Definition common_structs.h:16
Definition animation.h:191
u16 animation_length
Definition animation.h:192
u16 indexCycle
Definition animation.h:193
Definition animation.h:200
s16 * angle_array
Definition animation.h:205
s16 animation_length
Definition animation.h:203
AnimationLimbVector * animation_cycle_spec_vector
Definition animation.h:206
u16 has_value_but_never_used
Definition animation.h:204
s32 always_set_to_something_but_never_used
Definition animation.h:201
s32 always_zero_never_used
Definition animation.h:202
The armature is associated with an AnimationLimbVector which is equal to the number of RENDER_MODEL_O...
Definition animation.h:183
s32 type
Definition animation.h:184
s32 size
Definition animation.h:185
Gfx * model
Definition animation.h:187
s32 always_zero_never_used
Definition animation.h:186
signed int s32
Definition ultratypes.h:15
signed short int s16
Definition ultratypes.h:13
unsigned short int u16
Definition ultratypes.h:14