Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
math_util.h
Go to the documentation of this file.
1 #ifndef _MATH_UTIL_H_
2 #define _MATH_UTIL_H_
3 
4 extern f32 gSineTable[];
5 extern f32 gCosineTable[];
6 
7 #define sins(x) gSineTable[(u16) (x) >> 4]
8 #define coss(x) gCosineTable[(u16) (x) >> 4]
9 
10 #define min(a, b) ((a) <= (b) ? (a) : (b))
11 #define max(a, b) ((a) > (b) ? (a) : (b))
12 
13 #define sqr(x) ((x) * (x))
14 
15 void *vec3f_copy(Vec3f dest, Vec3f src);
16 void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z);
17 void *vec3f_add(Vec3f dest, Vec3f a);
18 void *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b);
19 void *vec3s_copy(Vec3s dest, Vec3s src);
20 void *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z);
21 void *vec3s_add(Vec3s dest, Vec3s a);
22 void *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b);
23 void *vec3s_sub(Vec3s dest, Vec3s a);
24 void *vec3s_to_vec3f(Vec3f dest, Vec3s a);
25 void *vec3f_to_vec3s(Vec3s dest, Vec3f a);
27 void *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b);
28 void *vec3f_normalize(Vec3f dest);
29 void mtxf_copy(f32 dest[4][4], f32 src[4][4]);
30 void mtxf_identity(f32 mtx[4][4]);
31 void mtxf_translate(f32 a[4][4], Vec3f b);
32 void mtxf_lookat(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d);
33 void mtxf_rotate_zxy_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c);
34 void mtxf_rotate_xyz_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c);
35 void mtxf_billboard(f32 mtx1[4][4], f32 mtx2[4][4], Vec3f c, s16 d);
36 void mtxf_align_terrain_normal(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d);
37 void mtxf_align_terrain_triangle(f32 mtx[4][4], Vec3f b, s16 c, f32 d);
38 void mtxf_mul(f32 dest[4][4], f32 a[4][4], f32 b[4][4]);
39 void mtxf_scale_vec3f(f32 a[4][4], f32 b[4][4], Vec3f c);
40 void mtxf_mul_vec3s(f32 a[4][4], Vec3s b);
41 void mtxf_to_mtx(Mtx *a, f32 b[4][4]);
42 void mtxf_rotate_xy(Mtx *a, s16 b);
43 void get_pos_from_transform_mtx(Vec3f a, f32 b[4][4], f32 c[4][4]);
44 void vec3f_get_dist_and_angle(Vec3f a, Vec3f b, f32 *c, s16 *d, s16 *e);
45 void vec3f_set_dist_and_angle(Vec3f a, Vec3f b, f32 c, s16 d, s16 e);
46 s32 approach_s32(s32 a, s32 b, s32 c, s32 d);
47 f32 approach_f32(f32 a, f32 b, f32 c, f32 d);
48 s16 atan2s(f32 a, f32 b);
49 f32 atan2f(f32 a, f32 b);
51 void anim_spline_init(Vec4s *a);
53 
54 #endif
f32 Vec3f[3]
Definition: types.h:23
void mtxf_rotate_xy(Mtx *a, s16 b)
Set &#39;mtx&#39; to a transformation matrix that rotates around the z axis.
Definition: math_util.c:568
void get_pos_from_transform_mtx(Vec3f a, f32 b[4][4], f32 c[4][4])
void vec3f_set_dist_and_angle(Vec3f a, Vec3f b, f32 c, s16 d, s16 e)
Construct the &#39;to&#39; point which is distance &#39;dist&#39; away from the &#39;from&#39; position, and has the angles p...
Definition: math_util.c:615
void * vec3s_add(Vec3s dest, Vec3s a)
Add vector a to &#39;dest&#39;.
Definition: math_util.c:69
void * vec3f_normalize(Vec3f dest)
Scale vector &#39;dest&#39; so it has length 1.
Definition: math_util.c:131
void * vec3f_set(Vec3f dest, f32 x, f32 y, f32 z)
Set vector &#39;dest&#39; to (x, y, z)
Definition: math_util.c:29
void mtxf_scale_vec3f(f32 a[4][4], f32 b[4][4], Vec3f c)
f32 approach_f32(f32 a, f32 b, f32 c, f32 d)
Return the value &#39;current&#39; after it tries to approach target, going up at most &#39;inc&#39; and going down a...
Definition: math_util.c:643
signed short int s16
Definition: ultratypes.h:13
f32 Vec4f[4]
Definition: types.h:26
s16 Vec4s[4]
Definition: types.h:27
void mtxf_align_terrain_triangle(f32 mtx[4][4], Vec3f b, s16 c, f32 d)
void mtxf_copy(f32 dest[4][4], f32 src[4][4])
s16 Vec3s[3]
Definition: types.h:24
s32 approach_s32(s32 a, s32 b, s32 c, s32 d)
Return the value &#39;current&#39; after it tries to approach target, going up at most &#39;inc&#39; and going down a...
Definition: math_util.c:624
void vec3f_get_dist_and_angle(Vec3f a, Vec3f b, f32 *c, s16 *d, s16 *e)
Take the vector starting at &#39;from&#39; pointed at &#39;to&#39; an retrieve the length of that vector...
Definition: math_util.c:602
void * find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c)
Set &#39;dest&#39; the normal vector of a triangle with vertices a, b and c.
Definition: math_util.c:115
s16 atan2s(f32 a, f32 b)
Compute the angle from (0, 0) to (x, y) as a s16.
Definition: math_util.c:672
void * vec3s_sub(Vec3s dest, Vec3s a)
Subtract vector a from &#39;dest&#39;.
Definition: math_util.c:85
float f32
Definition: ultratypes.h:29
void mtxf_billboard(f32 mtx1[4][4], f32 mtx2[4][4], Vec3f c, s16 d)
void * vec3s_copy(Vec3s dest, Vec3s src)
Copy vector src to dest.
Definition: math_util.c:53
void mtxf_rotate_zxy_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c)
void mtxf_translate(f32 a[4][4], Vec3f b)
void mtxf_mul(f32 dest[4][4], f32 a[4][4], f32 b[4][4])
at end of structure union member declaration In standard C each member declaration must be terminated by a
Definition: err.english.cc:690
void mtxf_align_terrain_normal(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d)
f32 gCosineTable[]
void * vec3s_to_vec3f(Vec3f dest, Vec3s a)
Convert short vector a to float vector &#39;dest&#39;.
Definition: math_util.c:93
f32 gSineTable[]
void * vec3f_add(Vec3f dest, Vec3f a)
Add vector &#39;a&#39; to &#39;dest&#39;.
Definition: math_util.c:37
Definition: gbi_old.h:46
void spline_get_weights(Vec4f a, f32 b, UNUSED s32 c)
Set &#39;result&#39; to a 4-vector with weights corresponding to interpolation value t in [0...
Definition: math_util.c:741
void * vec3s_sum(Vec3s dest, Vec3s a, Vec3s b)
Make &#39;dest&#39; the sum of vectors a and b.
Definition: math_util.c:77
void mtxf_to_mtx(Mtx *a, f32 b[4][4])
void * vec3f_sum(Vec3f dest, Vec3f a, Vec3f b)
Make &#39;dest&#39; the sum of vectors a and b.
Definition: math_util.c:45
void * vec3f_cross(Vec3f dest, Vec3f a, Vec3f b)
Make vector &#39;dest&#39; the cross product of vectors a and b.
Definition: math_util.c:123
void mtxf_identity(f32 mtx[4][4])
f32 atan2f(f32 a, f32 b)
Compute the atan2 in radians by calling atan2s and converting the result.
Definition: math_util.c:708
void mtxf_rotate_xyz_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c)
void * vec3s_set(Vec3s dest, s16 x, s16 y, s16 z)
Set vector &#39;dest&#39; to (x, y, z)
Definition: math_util.c:61
#define UNUSED
Definition: macros.h:13
void mtxf_mul_vec3s(f32 a[4][4], Vec3s b)
void * vec3f_to_vec3s(Vec3s dest, Vec3f a)
Convert float vector a to a short vector &#39;dest&#39; by rounding the components to the nearest integer...
Definition: math_util.c:103
signed int s32
Definition: ultratypes.h:15
void mtxf_lookat(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d)
s32 anim_spline_poll(Vec3f a)
Poll the next point from a spline animation.
Definition: math_util.c:799
void anim_spline_init(Vec4s *a)
Initialize a spline animation.
Definition: math_util.c:789
void * vec3f_copy(Vec3f dest, Vec3f src)
Copy vector &#39;src&#39; to &#39;dest&#39;.
Definition: math_util.c:21