KallistiOS git master
Independent SDK for the Sega Dreamcast
|
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. | |
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". | |
static float | vec_fipr (vec3f_t vec) |
static float | vec_dot (vec3f_t vec1, vec3f_t vec2) |
Function to return the scalar dot product of two 3d vectors. | |
static float | vec_length (vec3f_t vec) |
Macro to return scalar Euclidean length of a 3d vector. | |
static float | vec_distance (vec3f_t vec1, vec3f_t vec2) |
Function to return the Euclidean distance between two 3d vectors. | |
static vec3f_t | vec_normalize (vec3f_t vec) |
Function to return the normalized version of a vector. | |
static vec3f_t | vec_sub_normalize (vec3f_t vec1, vec3f_t vec2) |
Function to return the normalized version of a vector minus another vector. | |
static vec3f_t | vec_rotr_xy (vec3f_t vec, vec3f_t origin, float angle) |
Macro to rotate a vector about its origin on the x, y plane. | |
static vec3f_t | vec_rotr_xz (vec3f_t vec, vec3f_t origin, float angle) |
Macro to rotate a vector about its origin on the x, z plane. | |
static vec3f_t | vec_rotr_yz (vec3f_t vec, vec3f_t origin, float angle) |
Macro to rotate a vector about its origin on the y, z plane. | |
static vec3f_t | vec_rotd_xy (vec3f_t vec, vec3f_t origin, float angle) |
Macro to rotate a vector about its origin on the x, y plane. | |
static vec3f_t | vec_rotd_xz (vec3f_t vec, vec3f_t origin, float angle) |
Macro to rotate a vector about its origin on the x, z plane. | |
static vec3f_t | vec_rotd_yz (vec3f_t vec, vec3f_t origin, float angle) |
Macro to rotate a vector about its origin on the y, z plane. | |
SH4-optimized matrix and linear algebra routines
#define mat_trans_nodiv | ( | x, | |
y, | |||
z, | |||
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.
x | The X coordinate to transform. |
y | The Y coordinate to transform. |
z | The Z coordinate to transform. |
w | The W coordinate to transform. |
#define mat_trans_normal3 | ( | x, | |
y, | |||
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.
x | The X normal to transform. |
y | The Y normal to transform. |
z | The Z normal to transform. |
#define mat_trans_normal3_nomod | ( | x, | |
y, | |||
z, | |||
x2, | |||
y2, | |||
z2 ) |
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.
x | The X normal to input transform. |
y | The Y normal to input transform. |
z | The Z normal to input transform. |
x2 | The X normal to output transform. |
y2 | The Y normal to output transform. |
z2 | The Z normal to output transform. |
#define mat_trans_single | ( | x, | |
y, | |||
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.
x | The X coordinate to transform. |
y | The Y coordinate to transform. |
z | The Z coordinate to transform. |
#define mat_trans_single3 | ( | x, | |
y, | |||
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.
x | The X coordinate to transform. |
y | The Y coordinate to transform. |
z | The Z coordinate to transform. |
#define mat_trans_single3_nodiv | ( | x, | |
y, | |||
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.
x | The X coordinate to transform. |
y | The Y coordinate to transform. |
z | The Z coordinate to transform. |
#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.
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.
x | The X coordinate to transform without perspective divide. |
y | The Y coordinate to transform without perspective divide. |
z | The Z coordinate to transform without perspective divide. |
xd | The X coordinate to output transform with perspective divide. |
yd | The Y coordinate to output transform with perspective divide. |
zd | The Z coordinate to output transform with perspective divide. |
#define mat_trans_single3_nodiv_nomod | ( | x, | |
y, | |||
z, | |||
x2, | |||
y2, | |||
z2 ) |
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.
x | The X coordinate to input transform. |
y | The Y coordinate to input transform. |
z | The Z coordinate to input transform. |
x2 | The X coordinate to output transform. |
y2 | The Y coordinate to output transform. |
z2 | The Z coordinate to output transform. |
#define mat_trans_single3_nodivw | ( | x, | |
y, | |||
z, | |||
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.
x | The X coordinate to transform. |
y | The Y coordinate to transform. |
z | The Z coordinate to transform. |
w | The W coordinate output of transform. |
#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.
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.
x | The X coordinate to input transform. |
y | The Y coordinate to input transform. |
z | The Z coordinate to input transform. |
x2 | The X coordinate to output transform. |
y2 | The Y coordinate to output transform. |
z2 | The Z coordinate to output transform. |
#define mat_trans_single4 | ( | x, | |
y, | |||
z, | |||
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.
x | The X coordinate to transform. |
y | The Y coordinate to transform. |
z | The Z coordinate to transform. |
w | The W coordinate to transform. |
typedef float matrix_t[4][4] |
Basic 4x4 matrix type.
void mat_apply | ( | const matrix_t * | src | ) |
Apply a matrix.
This function multiplies a matrix in memory onto the internal matrix.
src
MUST be at least 8-byte aligned!src
is recommended.src | A pointer to the matrix to multiply. |
void mat_identity | ( | void | ) |
Clear the internal matrix to identity.
This function clears the internal matrix to a standard identity matrix.
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.
out
MUST be at least 8-byte aligned!out
is recommended.src | A pointer to where to load the matrix from (must be at least 8-byte aligned, should be 32-byte aligned). |
Set up a "camera".
This function acts as the similarly named GL function to set up a "camera" by doing rotations/translations.
eye | The eye coordinate. |
center | The center coordinate. |
up | The up vector. |
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.
xcenter | Center of the X direction. |
ycenter | Center of the Y direction. |
cot_fovy_2 | 1.0 / tan(view_angle / 2). |
znear | Near Z-plane. |
zfar | Far Z-plane. |
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.
xr | The angle to rotate around the X-axis, in radians. |
yr | The angle to rotate around the Y-axis, in radians. |
zr | The angle to rotate around the Z-axis, in radians. |
void mat_rotate_x | ( | float | r | ) |
Rotate around the X-axis.
This function sets up a rotation matrix around the X-axis.
r | The angle to rotate, in radians. |
void mat_rotate_y | ( | float | r | ) |
Rotate around the Y-axis.
This function sets up a rotation matrix around the Y-axis.
r | The angle to rotate, in radians. |
void mat_rotate_z | ( | float | r | ) |
Rotate around the Z-axis.
This function sets up a rotation matrix around the Z-axis.
r | The angle to rotate, in radians. |
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.
x | The ratio to scale in X. |
y | The ratio to scale in Y. |
z | The ratio to scale in Z. |
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.
out
MUST be at least 8-byte aligned!out
is recommended.out | A pointer to where to store the matrix (must be at least 8-byte aligned, should be 32-byte aligned). |
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.
invecs | The list of input vectors. |
outvecs | The list of output vectors. |
veccnt | How many vectors are in the list. |
stride | Number of bytes between vectors. |
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.
input | The list of input vertices. |
output | The output pointer (SQ address) |
veccnt | The number of vertices to transform. |
void mat_translate | ( | float | x, |
float | y, | ||
float | z ) |
Perform a 3D translation.
This function sets up a translation matrix with the specified parameters.
x | The amount to translate in X. |
y | The amount to translate in Y. |
z | The amount to translate in Z. |
Function 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.
vec1 | The first vector. |
vec2 | The second vector. |
References vec_length(), vec3f_t::x, vec3f_t::y, and vec3f_t::z.
Function 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.
vec1 | The first vector. |
vec2 | The second vector. |
References fipr(), vec3f_t::x, vec3f_t::y, and vec3f_t::z.
|
inlinestatic |
References fipr_magnitude_sqr(), vec3f_t::x, vec3f_t::y, and vec3f_t::z.
Referenced by vec_length().
|
inlinestatic |
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.
vec | The vector. |
References vec_fipr().
Referenced by vec_distance(), and vec_normalize().
Function 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.
vec | The source vector. |
References vec_length(), vec3f_t::x, vec3f_t::y, and vec3f_t::z.
Referenced by vec_sub_normalize().
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.
vec | The source vector. |
origin | The origin vector. |
angle | The angle (in degrees) of rotation. |
References vec_rotr_xy().
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.
vec | The source vector. |
origin | The origin vector. |
angle | The angle (in degrees) of rotation. |
References vec_rotr_xz().
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.
vec | The source vector. |
origin | The origin vector. |
angle | The angle (in degrees) of rotation. |
References vec_rotr_yz().
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.
vec | The source vector. |
origin | The origin vector. |
angle | The angle (in radians) of rotation. |
References vec3f_t::x, vec3f_t::y, and vec3f_t::z.
Referenced by vec_rotd_xy().
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.
vec | The source vector. |
origin | The origin vector. |
angle | The angle (in radians) of rotation. |
References vec3f_t::x, vec3f_t::y, and vec3f_t::z.
Referenced by vec_rotd_xz().
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.
vec | The source vector. |
origin | The origin vector. |
angle | The angle (in radians) of rotation. |
References vec3f_t::x, vec3f_t::y, and vec3f_t::z.
Referenced by vec_rotd_yz().
Function 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.
vec1 | The first vector. |
vec2 | The second vector. |
References vec_normalize(), vec3f_t::x, vec3f_t::y, and vec3f_t::z.