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

Basic matrix operations. More...

#include <sys/cdefs.h>

Go to the source code of this file.

Data Structures

struct  vec3f
 

Macros

#define R_DEG   182.04444443623349541909523793743
 
#define R_RAD   10430.37835
 
#define vec3f_dot(x1, y1, z1, x2, y2, z2, w)
 Macro to return the scalar dot product of two 3d vectors. More...
 
#define vec3f_length(x, y, z, w)
 Macro to return scalar Euclidean length of a 3d vector. More...
 
#define vec3f_distance(x1, y1, z1, x2, y2, z2, w)
 Macro to return the Euclidean distance between two 3d vectors. More...
 
#define vec3f_normalize(x, y, z)
 Macro to return the normalized version of a vector. More...
 
#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. More...
 
#define vec3f_rotr_xy(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, y plane. More...
 
#define vec3f_rotr_xz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, z plane. More...
 
#define vec3f_rotr_yz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the y, z plane. More...
 
#define vec3f_rotd_xy(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, y plane. More...
 
#define vec3f_rotd_xz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the x, z plane. More...
 
#define vec3f_rotd_yz(px, py, pz, cx, cy, cz, r)
 Macro to rotate a vector about its origin on the y, z plane. More...
 

Typedefs

typedef struct vec3f vec3f_t
 

Detailed Description

Basic matrix operations.

This file contains various basic vector math functionality for using the SH4's vector instructions. Higher level functionality in KGL is built off of these.

Author
Josh "PH3NOM" Pearson
See also
dc/matrix.h

Macro Definition Documentation

#define R_DEG   182.04444443623349541909523793743
#define R_RAD   10430.37835
#define vec3f_distance (   x1,
  y1,
  z1,
  x2,
  y2,
  z2,
 
)
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.
#define vec3f_dot (   x1,
  y1,
  z1,
  x2,
  y2,
  z2,
 
)
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.
#define vec3f_length (   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"); \
__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.
#define vec3f_normalize (   x,
  y,
 
)
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.
#define vec3f_rotd_xy (   px,
  py,
  pz,
  cx,
  cy,
  cz,
 
)
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; \
}
#define R_DEG
Definition: vec3f.h:29

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.
#define vec3f_rotd_xz (   px,
  py,
  pz,
  cx,
  cy,
  cz,
 
)
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; \
}
#define R_DEG
Definition: vec3f.h:29

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.
#define vec3f_rotd_yz (   px,
  py,
  pz,
  cx,
  cy,
  cz,
 
)
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; \
}
#define R_DEG
Definition: vec3f.h:29

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.
#define vec3f_rotr_xy (   px,
  py,
  pz,
  cx,
  cy,
  cz,
 
)
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; \
}
#define R_RAD
Definition: vec3f.h:30

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.
#define vec3f_rotr_xz (   px,
  py,
  pz,
  cx,
  cy,
  cz,
 
)
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; \
}
#define R_RAD
Definition: vec3f.h:30

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.
#define vec3f_rotr_yz (   px,
  py,
  pz,
  cx,
  cy,
  cz,
 
)
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; \
}
#define R_RAD
Definition: vec3f.h:30

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

typedef struct vec3f vec3f_t