KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Matrices

SH4-optimized matrix and linear algebra routines More...

Files

file  matrix.h
 Basic matrix operations.
 
file  matrix3d.h
 3D matrix operations.
 
file  vec3f.h
 Basic matrix operations.
 
file  vector.h
 Primitive matrix, vector, and point types.
 

Data Structures

struct  vec3f_t
 3D floating-point vector More...
 
struct  vector_t
 4-part vector type. More...
 

Macros

#define mat_trans_single(x, y, z)
 Macro to transform a single vertex by the internal matrix.
 
#define mat_trans_single4(x, y, z, w)
 Macro to transform a single vertex by the internal matrix.
 
#define mat_trans_single3(x, y, z)
 Macro to transform a single vertex by the internal matrix.
 
#define mat_trans_nodiv(x, y, z, w)
 Macro to transform a single vertex by the internal matrix with no perspective division.
 
#define mat_trans_single3_nodiv(x, y, z)
 Macro to transform a single 3d vertex coordinate by the internal matrix with no perspective division.
 
#define mat_trans_single3_nomod(x, y, z, x2, y2, z2)
 Macro to transform a single 3d vertex coordinate by the internal matrix with perspective division.
 
#define mat_trans_single3_nodiv_nomod(x, y, z, x2, y2, z2)
 Macro to transform a single 3d vertex coordinate by the internal matrix.
 
#define mat_trans_single3_nodivw(x, y, z, w)
 Macro to transform a single 3d vertex coordinate by the internal matrix.
 
#define mat_trans_single3_nodiv_div(x, y, z, xd, yd, zd)
 Macro to transform a single 3d vertex coordinate by the internal matrix both with and without perspective division.
 
#define mat_trans_normal3(x, y, z)
 Macro to transform a single vertex normal by the internal matrix.
 
#define mat_trans_normal3_nomod(x, y, z, x2, y2, z2)
 Macro to transform a single vertex normal by the internal matrix.
 
#define vec3f_dot(x1, y1, z1, x2, y2, z2, w)
 Macro to return the scalar dot product of two 3d vectors.
 
#define vec3f_length(x, y, z, w)
 Macro to return scalar Euclidean length of a 3d vector.
 
#define vec3f_distance(x1, y1, z1, x2, y2, z2, w)
 Macro to return the Euclidean distance between two 3d vectors.
 
#define vec3f_normalize(x, y, z)
 Macro to return the normalized version of a vector.
 
#define vec3f_sub_normalize(x1, y1, z1, x2, y2, z2, x3, y3, z3)
 Macro to return the normalized version of a vector minus another vector.
 
#define vec3f_rotr_xy(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, y plane.
 
#define vec3f_rotr_xz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, z plane.
 
#define vec3f_rotr_yz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the y, z plane.
 
#define vec3f_rotd_xy(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, y plane.
 
#define vec3f_rotd_xz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, z plane.
 
#define vec3f_rotd_yz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the y, z plane.
 

Typedefs

typedef float matrix_t[4][4]
 Basic 4x4 matrix type.
 
typedef vector_t point_t
 4-part point type (alias to the vector_t type).
 

Functions

void mat_store (matrix_t *out)
 Copy the internal matrix to a memory one.
 
void mat_load (const matrix_t *src)
 Copy a memory matrix into the internal one.
 
void mat_identity (void)
 Clear the internal matrix to identity.
 
void mat_apply (const matrix_t *src)
 Apply a matrix.
 
void mat_transform (const vector_t *invecs, vector_t *outvecs, int veccnt, int stride)
 Transform vectors by the internal matrix.
 
void mat_transform_sq (void *input, void *output, int veccnt)
 Transform vectors by the internal matrix into the store queues.
 
void mat_rotate_x (float r)
 Rotate around the X-axis.
 
void mat_rotate_y (float r)
 Rotate around the Y-axis.
 
void mat_rotate_z (float r)
 Rotate around the Z-axis.
 
void mat_rotate (float xr, float yr, float zr)
 Rotate around all axes.
 
void mat_translate (float x, float y, float z)
 Perform a 3D translation.
 
void mat_scale (float x, float y, float z)
 Perform a 3D scale operation.
 
void mat_perspective (float xcenter, float ycenter, float cot_fovy_2, float znear, float zfar)
 Set up a perspective view frustum.
 
void mat_lookat (const point_t *eye, const point_t *center, const vector_t *up)
 Set up a "camera".
 

Detailed Description

SH4-optimized matrix and linear algebra routines

Macro Definition Documentation

◆ mat_trans_nodiv

#define mat_trans_nodiv ( x,
y,
z,
w )
Value:
{ \
register float __x __asm__("fr0") = (x); \
register float __y __asm__("fr1") = (y); \
register float __z __asm__("fr2") = (z); \
register float __w __asm__("fr3") = (w); \
__asm__ __volatile__( \
"ftrv xmtrx,fv0\n" \
: "=f" (__x), "=f" (__y), "=f" (__z), "=f" (__w) \
: "0" (__x), "1" (__y), "2" (__z), "3" (__w) ); \
x = __x; y = __y; z = __z; w = __w; \
}

Macro to transform a single vertex by the internal matrix with no perspective division.

This macro is an inline assembly operation to transform a single vertex. It works most efficiently if the x value is in fr0, y is in fr1, z is in fr2, and w is in fr3 before using the macro. This macro is similar to mat_trans_single(), but this one does not do any perspective division.

Parameters
xThe X coordinate to transform.
yThe Y coordinate to transform.
zThe Z coordinate to transform.
wThe W coordinate to transform.

◆ mat_trans_normal3

#define mat_trans_normal3 ( x,
y,
z )
Value:
{ \
register float __x __asm__("fr8") = (x); \
register float __y __asm__("fr9") = (y); \
register float __z __asm__("fr10") = (z); \
__asm__ __volatile__( \
"fldi0 fr11\n" \
"ftrv xmtrx, fv8\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr11" ); \
x = __x; y = __y; z = __z; \
}

Macro to transform a single vertex normal by the internal matrix.

This macro is an inline assembly operation to transform a 3 float vertex normal. It works most efficiently if the x value is in fr8, y is in fr9, and z is in fr10 before using the macro. This macro is similar to mat_trans_nodiv(), but this one sets the W component to 0 in order to transform a vertex normal, rather than 1 for a vertex position.

Parameters
xThe X normal to transform.
yThe Y normal to transform.
zThe Z normal to transform.

◆ mat_trans_normal3_nomod

#define mat_trans_normal3_nomod ( x,
y,
z,
x2,
y2,
z2 )
Value:
{ \
register float __x __asm__("fr8") = (x); \
register float __y __asm__("fr9") = (y); \
register float __z __asm__("fr10") = (z); \
__asm__ __volatile__( \
"fldi0 fr11\n" \
"ftrv xmtrx, fv8\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr11" ); \
x2 = __x; y2 = __y; z2 = __z; \
}

Macro to transform a single vertex normal by the internal matrix.

This macro is an inline assembly operation to transform a 3 float vertex normal. It works most efficiently if the x value is in fr8, y is in fr9, and z is in fr10 before using the macro. This macro is similar to mat_trans_normal3(), but this one does not modify the input operands, instead storing the transformed vector to the output operands.

Parameters
xThe X normal to input transform.
yThe Y normal to input transform.
zThe Z normal to input transform.
x2The X normal to output transform.
y2The Y normal to output transform.
z2The Z normal to output transform.

◆ mat_trans_single

#define mat_trans_single ( x,
y,
z )
Value:
{ \
register float __x __asm__("fr0") = (x); \
register float __y __asm__("fr1") = (y); \
register float __z __asm__("fr2") = (z); \
__asm__ __volatile__( \
"fldi1 fr3\n" \
"ftrv xmtrx,fv0\n" \
"fldi1 fr2\n" \
"fdiv fr3,fr2\n" \
"fmul fr2,fr0\n" \
"fmul fr2,fr1\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr3" ); \
x = __x; y = __y; z = __z; \
}

Macro to transform a single vertex by the internal matrix.

This macro is an inline assembly operation to transform a single vertex. It works most efficiently if the x value is in fr0, y is in fr1, and z is in fr2 before using the macro.

Parameters
xThe X coordinate to transform.
yThe Y coordinate to transform.
zThe Z coordinate to transform.

◆ mat_trans_single3

#define mat_trans_single3 ( x,
y,
z )
Value:
{ \
register float __x __asm__("fr0") = (x); \
register float __y __asm__("fr1") = (y); \
register float __z __asm__("fr2") = (z); \
__asm__ __volatile__( \
"fldi1 fr3\n" \
"ftrv xmtrx,fv0\n" \
"fdiv fr3,fr0\n" \
"fdiv fr3,fr1\n" \
"fdiv fr3,fr2\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr3" ); \
x = __x; y = __y; z = __z; \
}

Macro to transform a single vertex by the internal matrix.

This macro is an inline assembly operation to transform a single vertex. It works most efficiently if the x value is in fr0, y is in fr1, and z is in fr2 before using the macro. This macro is similar to mat_trans_single(), but this one leaves z/w instead of 1/w for the z component.

Parameters
xThe X coordinate to transform.
yThe Y coordinate to transform.
zThe Z coordinate to transform.

◆ mat_trans_single3_nodiv

#define mat_trans_single3_nodiv ( x,
y,
z )
Value:
{ \
register float __x __asm__("fr12") = (x); \
register float __y __asm__("fr13") = (y); \
register float __z __asm__("fr14") = (z); \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr15" ); \
x = __x; y = __y; z = __z; \
}

Macro to transform a single 3d vertex coordinate by the internal matrix with no perspective division.

This macro is an inline assembly operation to transform a 3 float vertex coordinate. It works most efficiently if the x value is in fr12, y is in fr13, and z is in fr14 before using the macro. This macro is similar to mat_trans_nodiv(), but this one sets the W component to 1 for use with a 3d vector.

Parameters
xThe X coordinate to transform.
yThe Y coordinate to transform.
zThe Z coordinate to transform.

◆ mat_trans_single3_nodiv_div

#define mat_trans_single3_nodiv_div ( x,
y,
z,
xd,
yd,
zd )
Value:
{ \
register float __x __asm__("fr0") = (x); \
register float __y __asm__("fr1") = (y); \
register float __z __asm__("fr2") = (z); \
register float __xd __asm__("fr4"); \
register float __yd __asm__("fr5"); \
register float __zd __asm__("fr6"); \
__asm__ __volatile__( \
"fldi1 fr3\n" \
"ftrv xmtrx, fv0\n" \
"fmov fr0, fr4\n" \
"fmov fr1, fr5\n" \
"fmov fr3, fr7\n" \
"fldi1 fr6\n" \
"fdiv fr7, fr6\n" \
"fmul fr6, fr4\n" \
"fmul fr6, fr5\n" \
: "=f" (__x), "=f" (__y), "=f" (__z), \
"=f" (__xd), "=f" (__yd), "=f" (__zd) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr3" ); \
x = __x; y = __y; z = __z; xd = __xd; yd = __yd; zd = __zd; \
}

Macro to transform a single 3d vertex coordinate by the internal matrix both with and without perspective division.

This macro is an inline assembly operation to transform a 3 float vertex coordinate. It works most efficiently if the x value is in fr0, y is in fr1, and z is in fr2 before using the macro. This macro is similar to mat_trans_single(), but this one is used for transforming input vertex with and without perspective division.

Parameters
xThe X coordinate to transform without perspective divide.
yThe Y coordinate to transform without perspective divide.
zThe Z coordinate to transform without perspective divide.
xdThe X coordinate to output transform with perspective divide.
ydThe Y coordinate to output transform with perspective divide.
zdThe Z coordinate to output transform with perspective divide.

◆ mat_trans_single3_nodiv_nomod

#define mat_trans_single3_nodiv_nomod ( x,
y,
z,
x2,
y2,
z2 )
Value:
{ \
register float __x __asm__("fr12") = (x); \
register float __y __asm__("fr13") = (y); \
register float __z __asm__("fr14") = (z); \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr15" ); \
x2 = __x; y2 = __y; z2 = __z; \
}

Macro to transform a single 3d vertex coordinate by the internal matrix.

This macro is an inline assembly operation to transform a 3 float vertex coordinate. It works most efficiently if the x value is in fr12, y is in fr13, and z is in fr14 before using the macro. This macro is similar to mat_trans_single3_nodiv(), but this one does not modify the input operands, instead storing the transformed vector to the output operands.

Parameters
xThe X coordinate to input transform.
yThe Y coordinate to input transform.
zThe Z coordinate to input transform.
x2The X coordinate to output transform.
y2The Y coordinate to output transform.
z2The Z coordinate to output transform.

◆ mat_trans_single3_nodivw

#define mat_trans_single3_nodivw ( x,
y,
z,
w )
Value:
{ \
register float __x __asm__("fr12") = (x); \
register float __y __asm__("fr13") = (y); \
register float __z __asm__("fr14") = (z); \
register float __w __asm__("fr15") = 1.0f; \
__asm__ __volatile__( \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z), "=f" (__w) \
: "0" (__x), "1" (__y), "2" (__z), "3" (__w) ); \
x = __x; y = __y; z = __z; w = __w; \
}

Macro to transform a single 3d vertex coordinate by the internal matrix.

This macro is an inline assembly operation to transform a 3 float vertex coordinate. It works most efficiently if the x value is in fr12, y is in fr13, and z is in fr14 before using the macro. This macro is similar to mat_trans_single3_nodiv(), but this one stores the W component of transform for later perspective divide.

Parameters
xThe X coordinate to transform.
yThe Y coordinate to transform.
zThe Z coordinate to transform.
wThe W coordinate output of transform.

◆ mat_trans_single3_nomod

#define mat_trans_single3_nomod ( x,
y,
z,
x2,
y2,
z2 )
Value:
{ \
register float __x __asm__("fr12") = (x); \
register float __y __asm__("fr13") = (y); \
register float __z __asm__("fr14") = (z); \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
"fldi1 fr14\n" \
"fdiv fr15, fr14\n" \
"fmul fr14, fr12\n" \
"fmul fr14, fr13\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr15" ); \
x2 = __x; y2 = __y; z2 = __z; \
}

Macro to transform a single 3d vertex coordinate by the internal matrix with perspective division.

This macro is an inline assembly operation to transform a 3 float vertex coordinate. It works most efficiently if the x value is in fr12, y is in fr13, and z is in fr14 before using the macro. This macro is similar to mat_trans_single(), but this one does not modify the input operands, instead storing the transformed vector to the output operands.

Parameters
xThe X coordinate to input transform.
yThe Y coordinate to input transform.
zThe Z coordinate to input transform.
x2The X coordinate to output transform.
y2The Y coordinate to output transform.
z2The Z coordinate to output transform.

◆ mat_trans_single4

#define mat_trans_single4 ( x,
y,
z,
w )
Value:
{ \
register float __x __asm__("fr0") = (x); \
register float __y __asm__("fr1") = (y); \
register float __z __asm__("fr2") = (z); \
register float __w __asm__("fr3") = (w); \
__asm__ __volatile__( \
"ftrv xmtrx,fv0\n" \
"fdiv fr3,fr0\n" \
"fdiv fr3,fr1\n" \
"fdiv fr3,fr2\n" \
"fldi1 fr4\n" \
"fdiv fr3,fr4\n" \
"fmov fr4,fr3\n" \
: "=f" (__x), "=f" (__y), "=f" (__z), "=f" (__w) \
: "0" (__x), "1" (__y), "2" (__z), "3" (__w) \
: "fr4" ); \
x = __x; y = __y; z = __z; w = __w; \
}

Macro to transform a single vertex by the internal matrix.

This macro is an inline assembly operation to transform a single vertex. It works most efficiently if the x value is in fr0, y is in fr1, z is in fr2, and w is in fr3 before using the macro. This macro is similar to mat_trans_single(), but this one allows an input to and preserves the Z/W value.

Parameters
xThe X coordinate to transform.
yThe Y coordinate to transform.
zThe Z coordinate to transform.
wThe W coordinate to transform.

◆ vec3f_distance

#define vec3f_distance ( x1,
y1,
z1,
x2,
y2,
z2,
w )
Value:
{ \
register float __x __asm__("fr0") = (x2-x1); \
register float __y __asm__("fr1") = (y2-y1); \
register float __z __asm__("fr2") = (z2-z1); \
register float __w __asm__("fr3"); \
__asm__ __volatile__( \
"fldi0 fr3\n" \
"fipr fv0,fv0\n" \
"fsqrt fr3\n" \
: "+f" (__w) \
: "f" (__x), "f" (__y), "f" (__z), "f" (__w) \
); \
w = __w; \
}

Macro to return the Euclidean distance between two 3d vectors.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions, and returns a single-precision floating-point value.

Parameters
x1The X coordinate of first vector.
y1The Y coordinate of first vector.
z1The Z coordinate of first vector.
x2The X coordinate of second vector.
y2The Y coordinate of second vector.
z2The Z coordinate of second vector.
wThe result of the calculation.

◆ vec3f_dot

#define vec3f_dot ( x1,
y1,
z1,
x2,
y2,
z2,
w )
Value:
{ \
register float __x __asm__("fr0") = (x1); \
register float __y __asm__("fr1") = (y1); \
register float __z __asm__("fr2") = (z1); \
register float __w __asm__("fr3"); \
register float __a __asm__("fr4") = (x2); \
register float __b __asm__("fr5") = (y2); \
register float __c __asm__("fr6") = (z2); \
register float __d __asm__("fr7"); \
__asm__ __volatile__( \
"fldi0 fr3\n" \
"fldi0 fr7\n" \
"fipr fv4,fv0" \
: "+f" (__w) \
: "f" (__x), "f" (__y), "f" (__z), "f" (__w), \
"f" (__a), "f" (__b), "f" (__c), "f" (__d) \
); \
w = __w; \
}

Macro to return the scalar dot product of two 3d vectors.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions, and returns a single-precision floating-point value.

Parameters
x1The X coordinate of first vector.
y1The Y coordinate of first vector.
z1The Z coordinate of first vector.
x2The X coordinate of second vector.
y2The Y coordinate of second vector.
z2The Z coordinate of second vector.
wThe result of the calculation.

◆ vec3f_length

#define vec3f_length ( x,
y,
z,
w )
Value:
{ \
register float __x __asm__("fr0") = (x); \
register float __y __asm__("fr1") = (y); \
register float __z __asm__("fr2") = (z); \
register float __w __asm__("fr3"); \
__asm__ __volatile__( \
"fldi0 fr3\n" \
"fipr fv0,fv0\n" \
"fsqrt fr3\n" \
: "+f" (__w) \
: "f" (__x), "f" (__y), "f" (__z), "f" (__w) \
); \
w = __w; \
}

Macro to return scalar Euclidean length of a 3d vector.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions, and returns a single-precision floating-point value.

Parameters
xThe X coordinate of vector.
yThe Y coordinate of vector.
zThe Z coordinate of vector.
wThe result of the calculation.

◆ vec3f_normalize

#define vec3f_normalize ( x,
y,
z )
Value:
{ \
register float __x __asm__("fr0") = x; \
register float __y __asm__("fr1") = y; \
register float __z __asm__("fr2") = z; \
__asm__ __volatile__( \
"fldi0 fr3\n" \
"fipr fv0,fv0\n" \
"fsrra fr3\n" \
"fmul fr3, fr0\n" \
"fmul fr3, fr1\n" \
"fmul fr3, fr2\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr3" ); \
x = __x; y = __y; z = __z; \
}

Macro to return the normalized version of a vector.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions to calculate a vector that is in the same direction as the input vector but with a Euclidean length of one. The input vector is modified by the operation as the resulting values.

Parameters
xThe X coordinate of vector.
yThe Y coordinate of vector.
zThe Z coordinate of vector.

◆ vec3f_rotd_xy

#define vec3f_rotd_xy ( px,
py,
pz,
cx,
cy,
cz,
r )
Value:
{ \
register float __px __asm__("fr0") = px; \
register float __pz __asm__("fr1") = pz; \
register float __cx __asm__("fr4") = cx; \
register float __cz __asm__("fr5") = cz; \
register float __r __asm__("fr6") = r; \
register float __s __asm__("fr7") = R_DEG; \
__asm__ __volatile__( \
"fmul fr7, fr6\n" \
"ftrc fr6, fpul\n" \
"fsca fpul, dr6\n" \
"fsub fr4, fr0\n" \
"fsub fr5, fr1\n" \
"fmov fr0, fr2\n" \
"fmov fr1, fr3\n" \
"fmul fr7, fr0\n" \
"fmul fr6, fr1\n" \
"fmul fr6, fr2\n" \
"fmul fr7, fr3\n" \
"fadd fr0, fr4\n" \
"fsub fr1, fr4\n" \
"fadd fr2, fr5\n" \
"fadd fr3, fr5\n" \
: "+f" (__cx), "+f" (__cz) \
: "f" (__px), "f" (__pz), "f" (__r), "f" (__s) ); \
px = __cx; pz = __cz; \
}

Macro to rotate a vector about its origin on the x, y plane.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions. The return vector is stored into the first vertex parameter: x1, y1, and z1.

Parameters
pxThe X coordinate of vector to rotate.
pyThe Y coordinate of vector to rotate.
pzThe Z coordinate of vector to rotate.
cxThe X coordinate of origin vector.
cyThe Y coordinate of origin vector.
czThe Z coordinate of origin vector.
rThe angle (in degrees) of rotation.

◆ vec3f_rotd_xz

#define vec3f_rotd_xz ( px,
py,
pz,
cx,
cy,
cz,
r )
Value:
{ \
register float __px __asm__("fr0") = px; \
register float __pz __asm__("fr1") = pz; \
register float __cx __asm__("fr4") = cx; \
register float __cz __asm__("fr5") = cz; \
register float __r __asm__("fr6") = r; \
register float __s __asm__("fr7") = R_DEG; \
__asm__ __volatile__( \
"fmul fr7, fr6\n" \
"ftrc fr6, fpul\n" \
"fsca fpul, dr6\n" \
"fsub fr4, fr0\n" \
"fsub fr5, fr1\n" \
"fmov fr0, fr2\n" \
"fmov fr1, fr3\n" \
"fmul fr7, fr0\n" \
"fmul fr6, fr1\n" \
"fmul fr6, fr2\n" \
"fmul fr7, fr3\n" \
"fadd fr0, fr4\n" \
"fsub fr1, fr4\n" \
"fadd fr2, fr5\n" \
"fadd fr3, fr5\n" \
: "+f" (__cx), "+f" (__cz) \
: "f" (__px), "f" (__pz), "f" (__r), "f" (__s) ); \
px = __cx; pz = __cz; \
}

Macro to rotate a vector about its origin on the x, z plane.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions. The return vector is stored into the first vertex parameter: x1, y1, and z1.

Parameters
pxThe X coordinate of vector to rotate.
pyThe Y coordinate of vector to rotate.
pzThe Z coordinate of vector to rotate.
cxThe X coordinate of origin vector.
cyThe Y coordinate of origin vector.
czThe Z coordinate of origin vector.
rThe angle (in degrees) of rotation.

◆ vec3f_rotd_yz

#define vec3f_rotd_yz ( px,
py,
pz,
cx,
cy,
cz,
r )
Value:
{ \
register float __py __asm__("fr0") = py; \
register float __pz __asm__("fr1") = pz; \
register float __cy __asm__("fr4") = cy; \
register float __cz __asm__("fr5") = cz; \
register float __r __asm__("fr6") = r; \
register float __s __asm__("fr7") = R_DEG; \
__asm__ __volatile__( \
"fmul fr7, fr6\n" \
"ftrc fr6, fpul\n" \
"fsca fpul, dr6\n" \
"fsub fr4, fr0\n" \
"fsub fr5, fr1\n" \
"fmov fr0, fr2\n" \
"fmov fr1, fr3\n" \
"fmul fr7, fr0\n" \
"fmul fr6, fr1\n" \
"fmul fr6, fr2\n" \
"fmul fr7, fr3\n" \
"fadd fr0, fr4\n" \
"fsub fr1, fr4\n" \
"fadd fr2, fr5\n" \
"fadd fr3, fr5\n" \
: "+f" (__cy), "+f" (__cz) \
: "f" (__py), "f" (__pz), "f" (__r), "f" (__s) ); \
py = __cy; pz = __cz; \
}

Macro to rotate a vector about its origin on the y, z plane.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions. The return vector is stored into the first vertex parameter: x1, y1, and z1.

Parameters
pxThe X coordinate of vector to rotate.
pyThe Y coordinate of vector to rotate.
pzThe Z coordinate of vector to rotate.
cxThe X coordinate of origin vector.
cyThe Y coordinate of origin vector.
czThe Z coordinate of origin vector.
rThe angle (in degrees) of rotation.

◆ vec3f_rotr_xy

#define vec3f_rotr_xy ( px,
py,
pz,
cx,
cy,
cz,
r )
Value:
{ \
register float __px __asm__("fr0") = px; \
register float __py __asm__("fr1") = py; \
register float __cx __asm__("fr4") = cx; \
register float __cy __asm__("fr5") = cy; \
register float __r __asm__("fr6") = r; \
register float __s __asm__("fr7") = R_RAD; \
__asm__ __volatile__( \
"fmul fr7, fr6\n" \
"ftrc fr6, fpul\n" \
"fsca fpul, dr6\n" \
"fsub fr4, fr0\n" \
"fsub fr5, fr1\n" \
"fmov fr0, fr2\n" \
"fmov fr1, fr3\n" \
"fmul fr7, fr0\n" \
"fmul fr6, fr1\n" \
"fmul fr6, fr2\n" \
"fmul fr7, fr3\n" \
"fadd fr0, fr4\n" \
"fsub fr1, fr4\n" \
"fadd fr2, fr5\n" \
"fadd fr3, fr5\n" \
: "+f" (__cx), "+f" (__cy) \
: "f" (__px), "f" (__py), "f" (__r), "f" (__s) ); \
px = __cx; py = __cy; \
}

Macro to rotate a vector about its origin on the x, y plane.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions. The return vector is stored into the first vertex parameter: x1, y1, and z1.

Parameters
pxThe X coordinate of vector to rotate.
pyThe Y coordinate of vector to rotate.
pzThe Z coordinate of vector to rotate.
cxThe X coordinate of origin vector.
cyThe Y coordinate of origin vector.
czThe Z coordinate of origin vector.
rThe angle (in radians) of rotation.

◆ vec3f_rotr_xz

#define vec3f_rotr_xz ( px,
py,
pz,
cx,
cy,
cz,
r )
Value:
{ \
register float __px __asm__("fr0") = px; \
register float __pz __asm__("fr1") = pz; \
register float __cx __asm__("fr4") = cx; \
register float __cz __asm__("fr5") = cz; \
register float __r __asm__("fr6") = r; \
register float __s __asm__("fr7") = R_RAD; \
__asm__ __volatile__( \
"fmul fr7, fr6\n" \
"ftrc fr6, fpul\n" \
"fsca fpul, dr6\n" \
"fsub fr4, fr0\n" \
"fsub fr5, fr1\n" \
"fmov fr0, fr2\n" \
"fmov fr1, fr3\n" \
"fmul fr7, fr0\n" \
"fmul fr6, fr1\n" \
"fmul fr6, fr2\n" \
"fmul fr7, fr3\n" \
"fadd fr0, fr4\n" \
"fsub fr1, fr4\n" \
"fadd fr2, fr5\n" \
"fadd fr3, fr5\n" \
: "+f" (__cx), "+f" (__cz) \
: "f" (__px), "f" (__pz), "f" (__r), "f" (__s) ); \
px = __cx; pz = __cz; \
}

Macro to rotate a vector about its origin on the x, z plane.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions. The return vector is stored into the first vertex parameter: x1, y1, and z1.

Parameters
pxThe X coordinate of vector to rotate.
pyThe Y coordinate of vector to rotate.
pzThe Z coordinate of vector to rotate.
cxThe X coordinate of origin vector.
cyThe Y coordinate of origin vector.
czThe Z coordinate of origin vector.
rThe angle (in radians) of rotation.

◆ vec3f_rotr_yz

#define vec3f_rotr_yz ( px,
py,
pz,
cx,
cy,
cz,
r )
Value:
{ \
register float __py __asm__("fr0") = py; \
register float __pz __asm__("fr1") = pz; \
register float __cy __asm__("fr4") = cy; \
register float __cz __asm__("fr5") = cz; \
register float __r __asm__("fr6") = r; \
register float __s __asm__("fr7") = R_RAD; \
__asm__ __volatile__( \
"fmul fr7, fr6\n" \
"ftrc fr6, fpul\n" \
"fsca fpul, dr6\n" \
"fsub fr4, fr0\n" \
"fsub fr5, fr1\n" \
"fmov fr0, fr2\n" \
"fmov fr1, fr3\n" \
"fmul fr7, fr0\n" \
"fmul fr6, fr1\n" \
"fmul fr6, fr2\n" \
"fmul fr7, fr3\n" \
"fadd fr0, fr4\n" \
"fsub fr1, fr4\n" \
"fadd fr2, fr5\n" \
"fadd fr3, fr5\n" \
: "+f" (__cy), "+f" (__cz) \
: "f" (__py), "f" (__pz), "f" (__r), "f" (__s) ); \
py = __cy; pz = __cz; \
}

Macro to rotate a vector about its origin on the y, z plane.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions. The return vector is stored into the first vertex parameter: x1, y1, and z1.

Parameters
pxThe X coordinate of vector to rotate.
pyThe Y coordinate of vector to rotate.
pzThe Z coordinate of vector to rotate.
cxThe X coordinate of origin vector.
cyThe Y coordinate of origin vector.
czThe Z coordinate of origin vector.
rThe angle (in radians) of rotation.

◆ vec3f_sub_normalize

#define vec3f_sub_normalize ( x1,
y1,
z1,
x2,
y2,
z2,
x3,
y3,
z3 )
Value:
{ \
register float __x __asm__("fr0") = x1 - x2; \
register float __y __asm__("fr1") = y1 - y2; \
register float __z __asm__("fr2") = z1 - z2; \
__asm__ __volatile__( \
"fldi0 fr3\n" \
"fipr fv0,fv0\n" \
"fsrra fr3\n" \
"fmul fr3, fr0\n" \
"fmul fr3, fr1\n" \
"fmul fr3, fr2\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) \
: "fr3" ); \
x3 = __x; y3 = __y; z3 = __z; \
}

Macro to return the normalized version of a vector minus another vector.

This macro is an inline assembly operation using the SH4's fast (approximate) math instructions. The return vector is stored into the third vertex parameter: x3, y3, and z3.

Parameters
x1The X coordinate of first vector.
y1The Y coordinate of first vector.
z1The Z coordinate of first vector.
x2The X coordinate of second vector.
y2The Y coordinate of second vector.
z2The Z coordinate of second vector.
x3The X coordinate of output vector.
y3The Y coordinate of output vector.
z3The Z coordinate of output vector.

Typedef Documentation

◆ matrix_t

typedef float matrix_t[4][4]

Basic 4x4 matrix type.

Warning
This type must always be allocated on 8-byte boundaries, or else the API operating on it will crash on unaligned accesses. Keep this in mind with heap allocation, where you must ensure alignment manually.

◆ point_t

typedef vector_t point_t

4-part point type (alias to the vector_t type).

Function Documentation

◆ mat_apply()

void mat_apply ( const matrix_t * src)

Apply a matrix.

This function multiplies a matrix in memory onto the internal matrix.

Warning
src MUST be at least 8-byte aligned!
Note
For best performance, 32-byte alignment of src is recommended.
Parameters
srcA pointer to the matrix to multiply.

◆ mat_identity()

void mat_identity ( void )

Clear the internal matrix to identity.

This function clears the internal matrix to a standard identity matrix.

◆ mat_load()

void mat_load ( const matrix_t * src)

Copy a memory matrix into the internal one.

This function loads the internal matrix with the values of one in memory.

Warning
out MUST be at least 8-byte aligned!
Note
For best performance, 32-byte alignment of out is recommended.
Parameters
srcA pointer to where to load the matrix from (must be at least 8-byte aligned, should be 32-byte aligned).

◆ mat_lookat()

void mat_lookat ( const point_t * eye,
const point_t * center,
const vector_t * up )

Set up a "camera".

This function acts as the similarly named GL function to set up a "camera" by doing rotations/translations.

Parameters
eyeThe eye coordinate.
centerThe center coordinate.
upThe up vector.

◆ mat_perspective()

void mat_perspective ( float xcenter,
float ycenter,
float cot_fovy_2,
float znear,
float zfar )

Set up a perspective view frustum.

This function sets up a perspective view frustum for basic 3D usage.

Parameters
xcenterCenter of the X direction.
ycenterCenter of the Y direction.
cot_fovy_21.0 / tan(view_angle / 2).
znearNear Z-plane.
zfarFar Z-plane.

◆ mat_rotate()

void mat_rotate ( float xr,
float yr,
float zr )

Rotate around all axes.

This function sets up a rotation matrix around the X-axis, then around the Y, then around the Z.

Parameters
xrThe angle to rotate around the X-axis, in radians.
yrThe angle to rotate around the Y-axis, in radians.
zrThe angle to rotate around the Z-axis, in radians.

◆ mat_rotate_x()

void mat_rotate_x ( float r)

Rotate around the X-axis.

This function sets up a rotation matrix around the X-axis.

Parameters
rThe angle to rotate, in radians.

◆ mat_rotate_y()

void mat_rotate_y ( float r)

Rotate around the Y-axis.

This function sets up a rotation matrix around the Y-axis.

Parameters
rThe angle to rotate, in radians.

◆ mat_rotate_z()

void mat_rotate_z ( float r)

Rotate around the Z-axis.

This function sets up a rotation matrix around the Z-axis.

Parameters
rThe angle to rotate, in radians.

◆ mat_scale()

void mat_scale ( float x,
float y,
float z )

Perform a 3D scale operation.

This function sets up a scaling matrix with the specified parameters.

Parameters
xThe ratio to scale in X.
yThe ratio to scale in Y.
zThe ratio to scale in Z.

◆ mat_store()

void mat_store ( matrix_t * out)

Copy the internal matrix to a memory one.

This function stores the current internal matrix to one in memory.

Warning
out MUST be at least 8-byte aligned!
Note
For best performance, 32-byte alignment of out is recommended.
Parameters
outA pointer to where to store the matrix (must be at least 8-byte aligned, should be 32-byte aligned).

◆ mat_transform()

void mat_transform ( const vector_t * invecs,
vector_t * outvecs,
int veccnt,
int stride )

Transform vectors by the internal matrix.

This function transforms zero or more sets of vectors by the current internal matrix. Each vector is 3 single-precision floats long.

Parameters
invecsThe list of input vectors.
outvecsThe list of output vectors.
veccntHow many vectors are in the list.
strideNumber of bytes between vectors.

◆ mat_transform_sq()

void mat_transform_sq ( void * input,
void * output,
int veccnt )

Transform vectors by the internal matrix into the store queues.

This function transforms one or more sets of vertices using the current internal matrix directly into the store queues. Each vertex is exactly 32-bytes long, and the non-xyz data that is with it will be copied over with the transformed coordinates. This is perfect, for instance, for transforming pvr_vertex_t vertices.

Note
sq_lock() must have been called beforehand
Parameters
inputThe list of input vertices.
outputThe output pointer (SQ address)
veccntThe number of vertices to transform.
Author
Jim Ursetto

◆ mat_translate()

void mat_translate ( float x,
float y,
float z )

Perform a 3D translation.

This function sets up a translation matrix with the specified parameters.

Parameters
xThe amount to translate in X.
yThe amount to translate in Y.
zThe amount to translate in Z.