![]() |
citro3d
|
Implementations of matrix, vector, and quaternion operations. More...
Data Structures | |
| struct | C3D_FVec |
| Float vector. More... | |
| struct | C3D_Mtx |
| Row-major 4x4 matrix. More... | |
Macros | |
| #define | M_TAU (6.28318530717958647692528676655900576) |
| #define | M_PI (M_TAU/2) |
| #define | C3D_Angle(_angle) ((_angle)*M_TAU) |
| Convert an angle from revolutions to radians. | |
| #define | C3D_AngleFromDegrees(_angle) ((_angle)*M_TAU/360.0f) |
| Convert an angle from degrees to radians. | |
| #define | C3D_AspectRatioTop (400.0f / 240.0f) |
| Aspect ratio for 3DS top screen. | |
| #define | C3D_AspectRatioBot (320.0f / 240.0f) |
| Aspect ratio for 3DS bottom screen. | |
Typedefs | |
| typedef C3D_FVec | C3D_FQuat |
| Float quaternion. See C3D_FVec. | |
Vector Math | |
| static C3D_FVec | FVec4_New (float x, float y, float z, float w) |
| Create a new FVec4. | |
| static C3D_FVec | FVec4_Add (C3D_FVec lhs, C3D_FVec rhs) |
| Add two FVec4s. | |
| static C3D_FVec | FVec4_Subtract (C3D_FVec lhs, C3D_FVec rhs) |
| Subtract two FVec4s. | |
| static C3D_FVec | FVec4_Negate (C3D_FVec v) |
| Negate a FVec4. | |
| static C3D_FVec | FVec4_Scale (C3D_FVec v, float s) |
| Scale a FVec4. | |
| static C3D_FVec | FVec4_PerspDivide (C3D_FVec v) |
| Perspective divide. | |
| static float | FVec4_Dot (C3D_FVec lhs, C3D_FVec rhs) |
| Dot product of two FVec4s. | |
| static float | FVec4_Magnitude (C3D_FVec v) |
| Magnitude of a FVec4. | |
| static C3D_FVec | FVec4_Normalize (C3D_FVec v) |
| Normalize a FVec4. | |
| static C3D_FVec | FVec3_New (float x, float y, float z) |
| Create a new FVec3. | |
| static float | FVec3_Dot (C3D_FVec lhs, C3D_FVec rhs) |
| Dot product of two FVec3s. | |
| static float | FVec3_Magnitude (C3D_FVec v) |
| Magnitude of a FVec3. | |
| static C3D_FVec | FVec3_Normalize (C3D_FVec v) |
| Normalize a FVec3. | |
| static C3D_FVec | FVec3_Add (C3D_FVec lhs, C3D_FVec rhs) |
| Add two FVec3s. | |
| static C3D_FVec | FVec3_Subtract (C3D_FVec lhs, C3D_FVec rhs) |
| Subtract two FVec3s. | |
| static float | FVec3_Distance (C3D_FVec lhs, C3D_FVec rhs) |
| Distance between two 3D points. | |
| static C3D_FVec | FVec3_Scale (C3D_FVec v, float s) |
| Scale a FVec3. | |
| static C3D_FVec | FVec3_Negate (C3D_FVec v) |
| Negate a FVec3. | |
| static C3D_FVec | FVec3_Cross (C3D_FVec lhs, C3D_FVec rhs) |
| Cross product of two FVec3s. | |
Matrix Math | |
| |
| static void | Mtx_Zeros (C3D_Mtx *out) |
| Zero matrix. | |
| static void | Mtx_Copy (C3D_Mtx *out, const C3D_Mtx *in) |
| Copy a matrix. | |
| static void | Mtx_Diagonal (C3D_Mtx *out, float x, float y, float z, float w) |
| Creates a matrix with the diagonal using the given parameters. | |
| static void | Mtx_Identity (C3D_Mtx *out) |
| Identity matrix. | |
| void | Mtx_Transpose (C3D_Mtx *out) |
| Transposes the matrix. Row => Column, and vice versa. | |
| static void | Mtx_Add (C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs) |
| Matrix addition. | |
| static void | Mtx_Subtract (C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs) |
| Matrix subtraction. | |
| void | Mtx_Multiply (C3D_Mtx *out, const C3D_Mtx *a, const C3D_Mtx *b) |
| Multiply two matrices. | |
| float | Mtx_Inverse (C3D_Mtx *out) |
| Inverse a matrix. | |
| C3D_FVec | Mtx_MultiplyFVec3 (const C3D_Mtx *mtx, C3D_FVec v) |
| Multiply 3x3 matrix by a FVec3. | |
| C3D_FVec | Mtx_MultiplyFVec4 (const C3D_Mtx *mtx, C3D_FVec v) |
| Multiply 4x4 matrix by a FVec4. | |
| static C3D_FVec | Mtx_MultiplyFVecH (const C3D_Mtx *mtx, C3D_FVec v) |
| Multiply 4x3 matrix by a FVec3. | |
| void | Mtx_FromQuat (C3D_Mtx *m, C3D_FQuat q) |
| Get 4x4 matrix equivalent to Quaternion. | |
3D Transformation Matrix Math | |
| |
| void | Mtx_Translate (C3D_Mtx *mtx, float x, float y, float z, bool bRightSide) |
| 3D translation | |
| void | Mtx_Scale (C3D_Mtx *mtx, float x, float y, float z) |
| 3D Scale | |
| void | Mtx_Rotate (C3D_Mtx *mtx, C3D_FVec axis, float angle, bool bRightSide) |
| 3D Rotation | |
| void | Mtx_RotateX (C3D_Mtx *mtx, float angle, bool bRightSide) |
| 3D Rotation about the X axis | |
| void | Mtx_RotateY (C3D_Mtx *mtx, float angle, bool bRightSide) |
| 3D Rotation about the Y axis | |
| void | Mtx_RotateZ (C3D_Mtx *mtx, float angle, bool bRightSide) |
| 3D Rotation about the Z axis | |
3D Projection Matrix Math | |
| void | Mtx_Ortho (C3D_Mtx *mtx, float left, float right, float bottom, float top, float near, float far, bool isLeftHanded) |
| Orthogonal projection. | |
| void | Mtx_Persp (C3D_Mtx *mtx, float fovy, float aspect, float near, float far, bool isLeftHanded) |
| Perspective projection. | |
| void | Mtx_PerspStereo (C3D_Mtx *mtx, float fovy, float aspect, float near, float far, float iod, float screen, bool isLeftHanded) |
| Stereo perspective projection. | |
| void | Mtx_OrthoTilt (C3D_Mtx *mtx, float left, float right, float bottom, float top, float near, float far, bool isLeftHanded) |
| Orthogonal projection, tilted to account for the 3DS screen rotation. | |
| void | Mtx_PerspTilt (C3D_Mtx *mtx, float fovy, float aspect, float near, float far, bool isLeftHanded) |
| Perspective projection, tilted to account for the 3DS screen rotation. | |
| void | Mtx_PerspStereoTilt (C3D_Mtx *mtx, float fovy, float aspect, float near, float far, float iod, float screen, bool isLeftHanded) |
| Stereo perspective projection, tilted to account for the 3DS screen rotation. | |
| void | Mtx_LookAt (C3D_Mtx *out, C3D_FVec cameraPosition, C3D_FVec cameraTarget, C3D_FVec cameraUpVector, bool isLeftHanded) |
| Look-At matrix, based on DirectX implementation. | |
Quaternion Math | |
| C3D_FQuat | Quat_Multiply (C3D_FQuat lhs, C3D_FQuat rhs) |
| Multiply two Quaternions. | |
| C3D_FQuat | Quat_Pow (C3D_FQuat q, float p) |
| Raise Quaternion to a power. | |
| C3D_FVec | Quat_CrossFVec3 (C3D_FQuat q, C3D_FVec v) |
| Cross product of Quaternion and FVec3. | |
| C3D_FQuat | Quat_Rotate (C3D_FQuat q, C3D_FVec axis, float r, bool bRightSide) |
| 3D Rotation | |
| C3D_FQuat | Quat_RotateX (C3D_FQuat q, float r, bool bRightSide) |
| 3D Rotation about the X axis | |
| C3D_FQuat | Quat_RotateY (C3D_FQuat q, float r, bool bRightSide) |
| 3D Rotation about the Y axis | |
| C3D_FQuat | Quat_RotateZ (C3D_FQuat q, float r, bool bRightSide) |
| 3D Rotation about the Z axis | |
| C3D_FQuat | Quat_FromMtx (const C3D_Mtx *m) |
| Get Quaternion equivalent to 4x4 matrix. | |
| static C3D_FQuat | Quat_Identity (void) |
| Identity Quaternion. | |
| static C3D_FQuat | Quat_Conjugate (C3D_FQuat q) |
| Quaternion conjugate. | |
| static C3D_FQuat | Quat_Inverse (C3D_FQuat q) |
| Quaternion inverse. | |
| static C3D_FVec | FVec3_CrossQuat (C3D_FVec v, C3D_FQuat q) |
| Cross product of FVec3 and Quaternion. | |
| C3D_FQuat | Quat_FromPitchYawRoll (float pitch, float yaw, float roll, bool bRightSide) |
| Converting Pitch, Yaw, and Roll to Quaternion equivalent. | |
| C3D_FQuat | Quat_LookAt (C3D_FVec source, C3D_FVec target, C3D_FVec forwardVector, C3D_FVec upVector) |
| Quaternion Look-At. | |
| C3D_FQuat | Quat_FromAxisAngle (C3D_FVec axis, float angle) |
| Quaternion, created from a given axis and angle in radians. | |
| #define | Quat_New(i, j, k, r) FVec4_New(i,j,k,r) |
| Create a new Quaternion. | |
| #define | Quat_Negate(q) FVec4_Negate(q) |
| Negate a Quaternion. | |
| #define | Quat_Add(lhs, rhs) FVec4_Add(lhs,rhs) |
| Add two Quaternions. | |
| #define | Quat_Subtract(lhs, rhs) FVec4_Subtract(lhs,rhs) |
| Subtract two Quaternions. | |
| #define | Quat_Scale(q, s) FVec4_Scale(q,s) |
| Scale a Quaternion. | |
| #define | Quat_Normalize(q) FVec4_Normalize(q) |
| Normalize a Quaternion. | |
| #define | Quat_Dot(lhs, rhs) FVec4_Dot(lhs,rhs) |
| Dot product of two Quaternions. | |
Implementations of matrix, vector, and quaternion operations.
| #define C3D_Angle | ( | _angle | ) | ((_angle)*M_TAU) |
Convert an angle from revolutions to radians.
| [in] | _angle | Proportion of a full revolution |
| #define C3D_AngleFromDegrees | ( | _angle | ) | ((_angle)*M_TAU/360.0f) |
Convert an angle from degrees to radians.
| [in] | _angle | Angle in degrees |
| #define M_TAU (6.28318530717958647692528676655900576) |
The one true circumference-to-radius ratio. See http://tauday.com/tau-manifesto
| #define Quat_Add | ( | lhs, | |
| rhs | |||
| ) | FVec4_Add(lhs,rhs) |
Add two Quaternions.
| [in] | lhs | Augend |
| [in] | rhs | Addend |
| #define Quat_Dot | ( | lhs, | |
| rhs | |||
| ) | FVec4_Dot(lhs,rhs) |
Dot product of two Quaternions.
| [in] | lhs | Left-side Quaternion |
| [in] | rhs | Right-side Quaternion |
| #define Quat_Negate | ( | q | ) | FVec4_Negate(q) |
Negate a Quaternion.
Quat_Scale(v, -1) | [in] | q | Quaternion to negate |
| #define Quat_New | ( | i, | |
| j, | |||
| k, | |||
| r | |||
| ) | FVec4_New(i,j,k,r) |
Create a new Quaternion.
| [in] | i | I-component |
| [in] | j | J-component |
| [in] | k | K-component |
| [in] | r | Real component |
| #define Quat_Normalize | ( | q | ) | FVec4_Normalize(q) |
Normalize a Quaternion.
| [in] | q | Quaternion to normalize |
| #define Quat_Scale | ( | q, | |
| s | |||
| ) | FVec4_Scale(q,s) |
Scale a Quaternion.
| [in] | q | Quaternion to scale |
| [in] | s | Scale factor |
| #define Quat_Subtract | ( | lhs, | |
| rhs | |||
| ) | FVec4_Subtract(lhs,rhs) |
Subtract two Quaternions.
| [in] | lhs | Minuend |
| [in] | rhs | Subtrahend |
Add two FVec3s.
| [in] | lhs | Augend |
| [in] | rhs | Addend |
Cross product of two FVec3s.
| [in] | lhs | Left-side FVec3 |
| [in] | rhs | Right-side FVec3 |
Cross product of FVec3 and Quaternion.
| [in] | v | Base FVec3 |
| [in] | q | Quaternion to cross |
Distance between two 3D points.
| [in] | lhs | Relative origin |
| [in] | rhs | Relative point of interest |
Dot product of two FVec3s.
| [in] | lhs | Left-side FVec3 |
| [in] | rhs | Right-side FVec3 |
|
inlinestatic |
Magnitude of a FVec3.
| [in] | v | Vector |
Negate a FVec3.
FVec3_Scale(v, -1) | [in] | v | Vector to negate |
|
inlinestatic |
Create a new FVec3.
| [in] | x | X-component |
| [in] | y | Y-component |
| [in] | z | Z-component |
Normalize a FVec3.
| [in] | v | FVec3 to normalize |
Scale a FVec3.
| [in] | v | Vector to scale |
| [in] | s | Scale factor |
Subtract two FVec3s.
| [in] | lhs | Minuend |
| [in] | rhs | Subtrahend |
Add two FVec4s.
| [in] | lhs | Augend |
| [in] | rhs | Addend |
Dot product of two FVec4s.
| [in] | lhs | Left-side FVec4 |
| [in] | rhs | Right-side FVec4 |
|
inlinestatic |
Magnitude of a FVec4.
| [in] | v | Vector |
Negate a FVec4.
FVec4_Scale(v, -1) | [in] | v | Vector to negate |
|
inlinestatic |
Create a new FVec4.
| [in] | x | X-component |
| [in] | y | Y-component |
| [in] | z | Z-component |
| [in] | w | W-component |
Normalize a FVec4.
| [in] | v | FVec4 to normalize |
Perspective divide.
| [in] | v | Vector to divide |
Scale a FVec4.
| [in] | v | Vector to scale |
| [in] | s | Scale factor |
Subtract two FVec4s.
| [in] | lhs | Minuend |
| [in] | rhs | Subtrahend |
Matrix addition.
| [out] | out | Output matrix. |
| [in] | lhs | Left matrix. |
| [in] | rhs | Right matrix. |
Copy a matrix.
| [out] | out | Output matrix |
| [in] | in | Input matrix |
|
inlinestatic |
Creates a matrix with the diagonal using the given parameters.
| [out] | out | Output matrix. |
| [in] | x | The X component. |
| [in] | y | The Y component. |
| [in] | z | The Z component. |
| [in] | w | The W component. |
Get 4x4 matrix equivalent to Quaternion.
| [out] | m | Output matrix |
| [in] | q | Input Quaternion |
|
inlinestatic |
Identity matrix.
| [out] | out | Matrix to fill |
| float Mtx_Inverse | ( | C3D_Mtx * | out | ) |
Inverse a matrix.
| [in,out] | out | Matrix to inverse |
| 0.0f | Degenerate matrix (no inverse) |
| void Mtx_LookAt | ( | C3D_Mtx * | out, |
| C3D_FVec | cameraPosition, | ||
| C3D_FVec | cameraTarget, | ||
| C3D_FVec | cameraUpVector, | ||
| bool | isLeftHanded | ||
| ) |
Look-At matrix, based on DirectX implementation.
| [out] | out | Output matrix. |
| [in] | cameraPosition | Position of the intended camera in 3D space. |
| [in] | cameraTarget | Position of the intended target the camera is supposed to face in 3D space. |
| [in] | cameraUpVector | The vector that points straight up depending on the camera's "Up" direction. |
| [in] | isLeftHanded | Whether to build a LH projection |
Multiply two matrices.
| [out] | out | Output matrix |
| [in] | a | Multiplicand |
| [in] | b | Multiplier |
Multiply 3x3 matrix by a FVec3.
| [in] | mtx | Matrix |
| [in] | v | Vector |
Multiply 4x4 matrix by a FVec4.
| [in] | mtx | Matrix |
| [in] | v | Vector |
Multiply 4x3 matrix by a FVec3.
| [in] | mtx | Matrix |
| [in] | v | Vector |
| void Mtx_Ortho | ( | C3D_Mtx * | mtx, |
| float | left, | ||
| float | right, | ||
| float | bottom, | ||
| float | top, | ||
| float | near, | ||
| float | far, | ||
| bool | isLeftHanded | ||
| ) |
Orthogonal projection.
| [out] | mtx | Output matrix |
| [in] | left | Left clip plane (X=left) |
| [in] | right | Right clip plane (X=right) |
| [in] | bottom | Bottom clip plane (Y=bottom) |
| [in] | top | Top clip plane (Y=top) |
| [in] | near | Near clip plane (Z=near) |
| [in] | far | Far clip plane (Z=far) |
| [in] | isLeftHanded | Whether to build a LH projection |
| void Mtx_OrthoTilt | ( | C3D_Mtx * | mtx, |
| float | left, | ||
| float | right, | ||
| float | bottom, | ||
| float | top, | ||
| float | near, | ||
| float | far, | ||
| bool | isLeftHanded | ||
| ) |
Orthogonal projection, tilted to account for the 3DS screen rotation.
| [out] | mtx | Output matrix |
| [in] | left | Left clip plane (X=left) |
| [in] | right | Right clip plane (X=right) |
| [in] | bottom | Bottom clip plane (Y=bottom) |
| [in] | top | Top clip plane (Y=top) |
| [in] | near | Near clip plane (Z=near) |
| [in] | far | Far clip plane (Z=far) |
| [in] | isLeftHanded | Whether to build a LH projection |
| void Mtx_Persp | ( | C3D_Mtx * | mtx, |
| float | fovy, | ||
| float | aspect, | ||
| float | near, | ||
| float | far, | ||
| bool | isLeftHanded | ||
| ) |
Perspective projection.
| [out] | mtx | Output matrix |
| [in] | fovy | Vertical field of view in radians |
| [in] | aspect | Aspect ration of projection plane (width/height) |
| [in] | near | Near clip plane (Z=near) |
| [in] | far | Far clip plane (Z=far) |
| [in] | isLeftHanded | Whether to build a LH projection |
| void Mtx_PerspStereo | ( | C3D_Mtx * | mtx, |
| float | fovy, | ||
| float | aspect, | ||
| float | near, | ||
| float | far, | ||
| float | iod, | ||
| float | screen, | ||
| bool | isLeftHanded | ||
| ) |
Stereo perspective projection.
| [out] | mtx | Output matrix |
| [in] | fovy | Vertical field of view in radians |
| [in] | aspect | Aspect ration of projection plane (width/height) |
| [in] | near | Near clip plane (Z=near) |
| [in] | far | Far clip plane (Z=far) |
| [in] | iod | Interocular distance |
| [in] | screen | Focal length |
| [in] | isLeftHanded | Whether to build a LH projection |
| void Mtx_PerspStereoTilt | ( | C3D_Mtx * | mtx, |
| float | fovy, | ||
| float | aspect, | ||
| float | near, | ||
| float | far, | ||
| float | iod, | ||
| float | screen, | ||
| bool | isLeftHanded | ||
| ) |
Stereo perspective projection, tilted to account for the 3DS screen rotation.
| [out] | mtx | Output matrix |
| [in] | fovy | Vertical field of view in radians |
| [in] | aspect | Aspect ration of projection plane (width/height) |
| [in] | near | Near clip plane (Z=near) |
| [in] | far | Far clip plane (Z=far) |
| [in] | iod | Interocular distance |
| [in] | screen | Focal length |
| [in] | isLeftHanded | Whether to build a LH projection |
| void Mtx_PerspTilt | ( | C3D_Mtx * | mtx, |
| float | fovy, | ||
| float | aspect, | ||
| float | near, | ||
| float | far, | ||
| bool | isLeftHanded | ||
| ) |
Perspective projection, tilted to account for the 3DS screen rotation.
| [out] | mtx | Output matrix |
| [in] | fovy | Vertical field of view in radians |
| [in] | aspect | Aspect ration of projection plane (width/height) |
| [in] | near | Near clip plane (Z=near) |
| [in] | far | Far clip plane (Z=far) |
| [in] | isLeftHanded | Whether to build a LH projection |
3D Rotation
| [in,out] | mtx | Matrix to rotate |
| [in] | axis | Axis about which to rotate |
| [in] | angle | Radians to rotate |
| [in] | bRightSide | Whether to transform from the right side |
| void Mtx_RotateX | ( | C3D_Mtx * | mtx, |
| float | angle, | ||
| bool | bRightSide | ||
| ) |
3D Rotation about the X axis
| [in,out] | mtx | Matrix to rotate |
| [in] | angle | Radians to rotate |
| [in] | bRightSide | Whether to transform from the right side |
| void Mtx_RotateY | ( | C3D_Mtx * | mtx, |
| float | angle, | ||
| bool | bRightSide | ||
| ) |
3D Rotation about the Y axis
| [in,out] | mtx | Matrix to rotate |
| [in] | angle | Radians to rotate |
| [in] | bRightSide | Whether to transform from the right side |
| void Mtx_RotateZ | ( | C3D_Mtx * | mtx, |
| float | angle, | ||
| bool | bRightSide | ||
| ) |
3D Rotation about the Z axis
| [in,out] | mtx | Matrix to rotate |
| [in] | angle | Radians to rotate |
| [in] | bRightSide | Whether to transform from the right side |
| void Mtx_Scale | ( | C3D_Mtx * | mtx, |
| float | x, | ||
| float | y, | ||
| float | z | ||
| ) |
3D Scale
| [in,out] | mtx | Matrix to scale |
| [in] | x | X component to scale |
| [in] | y | Y component to scale |
| [in] | z | Z component to scale |
Matrix subtraction.
| [out] | out | Output matrix. |
| [in] | lhs | Left matrix. |
| [in] | rhs | Right matrix. |
| void Mtx_Translate | ( | C3D_Mtx * | mtx, |
| float | x, | ||
| float | y, | ||
| float | z, | ||
| bool | bRightSide | ||
| ) |
3D translation
| [in,out] | mtx | Matrix to translate |
| [in] | x | X component to translate |
| [in] | y | Y component to translate |
| [in] | z | Z component to translate |
| [in] | bRightSide | Whether to transform from the right side |
| void Mtx_Transpose | ( | C3D_Mtx * | out | ) |
Transposes the matrix. Row => Column, and vice versa.
| [in,out] | out | Output matrix. |
|
inlinestatic |
Zero matrix.
| [out] | out | Matrix to zero |
Quaternion conjugate.
| [in] | q | Quaternion of which to get conjugate |
Cross product of Quaternion and FVec3.
| [in] | q | Base Quaternion |
| [in] | v | Vector to cross |
Quaternion, created from a given axis and angle in radians.
| [in] | axis | C3D_FVec The axis to rotate around at. |
| [in] | angle | float The angle to rotate. Unit: Radians |
Get Quaternion equivalent to 4x4 matrix.
| [in] | m | Input Matrix |
| C3D_FQuat Quat_FromPitchYawRoll | ( | float | pitch, |
| float | yaw, | ||
| float | roll, | ||
| bool | bRightSide | ||
| ) |
Converting Pitch, Yaw, and Roll to Quaternion equivalent.
| [in] | pitch | The pitch angle in radians. |
| [in] | yaw | The yaw angle in radians. |
| [in] | roll | The roll angle in radians. |
| [in] | bRightSide | Whether to transform from the right side |
|
inlinestatic |
Identity Quaternion.
Quaternion inverse.
Quat_Pow(v, -1) | [in] | q | Quaternion of which to get inverse |
Multiply two Quaternions.
| [in] | lhs | Multiplicand |
| [in] | rhs | Multiplier |
Raise Quaternion to a power.
| [in] | q | Base Quaternion |
| [in] | p | Power |
3D Rotation
| [in] | q | Quaternion to rotate |
| [in] | axis | Axis about which to rotate |
| [in] | r | Radians to rotate |
| [in] | bRightSide | Whether to transform from the right side |
3D Rotation about the X axis
| [in] | q | Quaternion to rotate |
| [in] | r | Radians to rotate |
| [in] | bRightSide | Whether to transform from the right side |
3D Rotation about the Y axis
| [in] | q | Quaternion to rotate |
| [in] | r | Radians to rotate |
| [in] | bRightSide | Whether to transform from the right side |