The SM64 decompilation relies on a carefully structured set of type definitions found primarily inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/n64decomp/sm64/llms.txt
Use this file to discover all available pages before exploring further.
include/types.h. Understanding these types is essential before reading or writing any behavior or engine code. This page covers primitive integer and float types, the vector and matrix types used for 3D math, the script-data aliases for collision and behavior arrays, the animation structs, and the math helper functions declared in src/engine/math_util.h.
Primitive types
SM64 uses the N64 SDK’sultra64.h integer types throughout the codebase. All types below are guaranteed-width aliases.
| Type | Underlying type | Size | Notes |
|---|---|---|---|
u8 | unsigned char | 1 byte | Unsigned 8-bit |
s8 | signed char | 1 byte | Signed 8-bit |
u16 | unsigned short | 2 bytes | Unsigned 16-bit |
s16 | signed short | 2 bytes | Signed 16-bit; also used for angles |
u32 | unsigned int | 4 bytes | Unsigned 32-bit |
s32 | signed int | 4 bytes | Signed 32-bit |
f32 | float | 4 bytes | 32-bit IEEE 754 float |
Vector types
All vector types are plain C arrays, not structs. Y is the up-axis in SM64’s coordinate system.Two-component float vector. Used for 2D texture coordinates and some UV mapping.
Three-component float vector (
[X, Y, Z], Y is up). The primary type for world-space positions, velocities, and surface normals.Three-component signed 16-bit integer vector. Used for compact angle storage (
faceAngle, angle in GraphNodeObject) and for collision vertex coordinates.Three-component signed 32-bit integer vector. Used where higher-precision integer coordinates are needed.
Four-component float vector. Used internally by the spline weight system (
spline_get_weights).Four-component signed 16-bit integer vector. Used as the keyframe type for animation splines (
anim_spline_init).Matrix type
A 4×4 row-major float matrix. Used for all object and camera transforms.The engine stores a
Mat4 transform directly inside struct Object (at offset 0x21C) and a pointer Mat4 *throwMatrix in GraphNodeObject for held-object rendering.Script and data type aliases
These aliases are all thintypedefs over integer primitives. They communicate intent to the reader rather than adding any runtime behaviour.
An element of a geometry layout (display list command) array. Defined as
uintptr_t to hold either an integer command word or a pointer on both 32-bit and 64-bit hosts.An element of a level script command array. Same representation as
GeoLayout.An element of an object behavior script array.
An element in a moving-texture vertex array.
An element in a macro-object placement array (used in level scripts to place objects cheaply).
An element in a raw collision data array. Values are limited to −32768 … 32767. If you need coordinates outside that range, change the typedef to
s32 (and update TerrainData / Vec3Terrain accordingly).An element in an object trajectory (waypoint path) array.
An element in a painting geometry/animation data array.
A single byte of raw texture data.
A room index. Limited to −128 … 127 (256 rooms total). Change to
s16 if more rooms are required.Alias for
Collision; used in surface/collision structs (struct Surface) to make the purpose of a field obvious.Animation types
ANIM_FLAG_* constants
Animation behaviour is controlled by a bitmask stored inAnimation.flags.
| Constant | Value | Meaning |
|---|---|---|
ANIM_FLAG_NOLOOP | 0x01 | Play once; do not loop |
ANIM_FLAG_BACKWARD | 0x02 | Play in reverse |
ANIM_FLAG_2 | 0x04 | (purpose unknown) |
ANIM_FLAG_HOR_TRANS | 0x08 | Apply horizontal root translation from animation data |
ANIM_FLAG_VERT_TRANS | 0x10 | Apply vertical root translation from animation data |
ANIM_FLAG_5 | 0x20 | (purpose unknown) |
ANIM_FLAG_6 | 0x40 | (purpose unknown) |
ANIM_FLAG_7 | 0x80 | (purpose unknown) |
struct Animation
Defined ininclude/types.h.
Bitmask of
ANIM_FLAG_* constants controlling loop and translation behaviour.Vertical translation values from the
values array are divided by this to produce world-unit offsets.Frame range. When the animation reaches
loopEnd, it jumps back to loopStart (unless ANIM_FLAG_NOLOOP is set, in which case it holds on the last frame).Packed rotation data. The
index table stores run-length entries per bone; values stores the actual angle deltas. Use ANIMINDEX_NUMPARTS(animindex) to compute the bone count from the index table.struct AnimInfo
Tracks the runtime playback state of an animation on an object’sGraphNodeObject.
Angle representation
SM64 uses binary angle measurement (BAM) throughout the engine. All angles are stored as
s16 values where the full circle is 0–65535 (unsigned), mapping exactly to 0°–360°.>> 4 shift converts a 16-bit binary angle into a 12-bit table index (4096 entries covering one full circle). To convert from conventional degrees:
Vec3s is used for angle triples (pitch, yaw, roll) in both GraphNodeObject.angle and MarioState.faceAngle. Object fields oFaceAnglePitch, oFaceAngleYaw, oFaceAngleRoll and oMoveAnglePitch, oMoveAngleYaw, oMoveAngleRoll store the same representation as s32 (sign-extended from s16).
Math utility functions
All functions below are declared insrc/engine/math_util.h and implemented in src/engine/math_util.c.
Vec3f operations
Copies
src into dest. Both must be Vec3f.Sets all three components of
dest.In-place addition:
dest += a.dest = a + b.Computes the cross product:
dest = a × b.Normalises
dest in-place to unit length.Computes the normal of the plane defined by triangle vertices
a, b, c and stores it in dest.Vec3s operations
vec3s_to_vec3f / vec3f_to_vec3s pair converts between the compact angle representation and floating-point for rendering.
Matrix operations
Loads the 4×4 identity matrix into
mtx.Copies a
Mat4.Creates a pure translation matrix from the vector
b.Builds a combined rotate-then-translate matrix. Rotation order is Z→X→Y (pitch/roll/yaw), which matches the standard object orientation convention used by most behaviors.
Same as above but with X→Y→Z rotation order. Used for the camera and a few other nodes.
Computes a look-at matrix (camera facing
to from from) with an optional roll angle.Builds a billboard matrix so a quad always faces the camera. Used for particles.
Aligns an object’s matrix to the surface normal
upDir, useful for objects that rest on slopes.Matrix multiplication:
dest = a × b.Applies a non-uniform scale
s to mtx and stores the result in dest.Converts a
Mat4 (f32) into the N64 fixed-point Mtx format required by the RSP microcode.Polar / angular utilities
Decomposes the vector
to − from into a distance and two binary angles. This is the canonical way to compute facing angles toward a target.Inverse of the above: writes the point that is
dist away from from in the direction (pitch, yaw) into to.Returns a binary-angle arctangent of
y/x, analogous to atan2 from <math.h> but returning an s16 BAM angle.Moves
current toward target by at most inc if increasing or dec if decreasing. Clamps at target. Used to smoothly interpolate integer values each frame.Float version of
approach_s32.Scalar helpers
math_util.h and are safe to use with any numeric type.