KallistiOS  2.0.0
 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.
#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.

Functions

void mat_store (matrix_t *out)
 Copy the internal matrix to a memory one.
void mat_load (matrix_t *out)
 Copy a memory matrix into the internal one.
void mat_identity ()
 Clear the internal matrix to identity.
void mat_apply (matrix_t *src)
 Apply a matrix.
void mat_transform (vector_t *invecs, vector_t *outvecs, int veccnt, int vecskip)
 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.

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
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_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_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