KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Macros | Functions
matrix.h File Reference

Basic matrix operations. More...

#include <sys/cdefs.h>
#include <kos/vector.h>

Go to the source code of this file.

Macros

#define mat_trans_single(x, y, z)
 Macro to transform a single vertex by the internal matrix. More...
 
#define mat_trans_single4(x, y, z, w)
 Macro to transform a single vertex by the internal matrix. More...
 
#define mat_trans_single3(x, y, z)
 Macro to transform a single vertex by the internal matrix. More...
 
#define mat_trans_nodiv(x, y, z, w)
 Macro to transform a single vertex by the internal matrix with no perspective division. More...
 
#define mat_trans_single3_nodiv(x, y, z)
 Macro to transform a single 3d vertex coordinate by the internal matrix with no perspective division. More...
 
#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. More...
 
#define mat_trans_single3_nodiv_nomod(x, y, z, x2, y2, z2)
 Macro to transform a single 3d vertex coordinate by the internal matrix. More...
 
#define mat_trans_single3_nodivw(x, y, z, w)
 Macro to transform a single 3d vertex coordinate by the internal matrix. More...
 
#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. More...
 
#define mat_trans_normal3(x, y, z)
 Macro to transform a single vertex normal by the internal matrix. More...
 
#define mat_trans_normal3_nomod(x, y, z, x2, y2, z2)
 Macro to transform a single vertex normal by the internal matrix. More...
 

Functions

void mat_store (matrix_t *out)
 Copy the internal matrix to a memory one. More...
 
void mat_load (matrix_t *out)
 Copy a memory matrix into the internal one. More...
 
void mat_identity ()
 Clear the internal matrix to identity. More...
 
void mat_apply (matrix_t *src)
 Apply a matrix. More...
 
void mat_transform (vector_t *invecs, vector_t *outvecs, int veccnt, int vecskip)
 Transform vectors by the internal matrix. More...
 
void mat_transform_sq (void *input, void *output, int veccnt)
 Transform vectors by the internal matrix into the store queues. More...
 

Detailed Description

Basic matrix operations.

This file contains various basic matrix math functionality for using the SH4's matrix transformation unit. Higher level functionality, like the 3D functionality is built off of these operations.

Author
Dan Potter
Josh "PH3NOM" Pearson
See also
dc/matrix3d.h

Macro Definition Documentation

#define mat_trans_nodiv (   x,
  y,
  z,
 
)
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.
#define mat_trans_normal3 (   x,
  y,
 
)
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) ); \
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.
#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) ); \
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.
#define mat_trans_single (   x,
  y,
 
)
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.
#define mat_trans_single3 (   x,
  y,
 
)
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.
#define mat_trans_single3_nodiv (   x,
  y,
 
)
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) ); \
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.
#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) \
: "0" (__x), "1" (__y), "2" (__z) ); \
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.
#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) ); \
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.
#define mat_trans_single3_nodivw (   x,
  y,
  z,
 
)
Value:
{ \
register float __x __asm__("fr12") = (x); \
register float __y __asm__("fr13") = (y); \
register float __z __asm__("fr14") = (z); \
register float __w __asm__("fr15"); \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) ); \
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.
#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.
#define mat_trans_single4 (   x,
  y,
  z,
 
)
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.

Function Documentation

void mat_apply ( matrix_t src)

Apply a matrix.

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

Parameters
srcA poitner to the matrix to multiply.
void mat_identity ( )

Clear the internal matrix to identity.

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

void mat_load ( matrix_t out)

Copy a memory matrix into the internal one.

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

Parameters
outA pointer to where to load the matrix from (must be at least 8-byte aligned, should be 32-byte aligned).
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.

Parameters
outA pointer to where to store the matrix (must be at least 8-byte aligned, should be 32-byte aligned).
void mat_transform ( vector_t invecs,
vector_t outvecs,
int  veccnt,
int  vecskip 
)

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.
vecskipNumber of empty 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.

Parameters
inputThe list of input vertices.
outputThe output pointer.
veccntThe number of vertices to transform.
Note
The QACR0 and QACR1 registers must be set appropriately BEFORE calling this function.
Author
Jim Ursetto