citro3d
Data Structures | Macros | Typedefs
Math Support Library

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. More...
 
#define C3D_AngleFromDegrees(_angle)   ((_angle)*M_TAU/360.0f)
 Convert an angle from degrees to radians. More...
 
#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. More...
 
static C3D_FVec FVec4_Add (C3D_FVec lhs, C3D_FVec rhs)
 Add two FVec4s. More...
 
static C3D_FVec FVec4_Subtract (C3D_FVec lhs, C3D_FVec rhs)
 Subtract two FVec4s. More...
 
static C3D_FVec FVec4_Negate (C3D_FVec v)
 Negate a FVec4. More...
 
static C3D_FVec FVec4_Scale (C3D_FVec v, float s)
 Scale a FVec4. More...
 
static C3D_FVec FVec4_PerspDivide (C3D_FVec v)
 Perspective divide. More...
 
static float FVec4_Dot (C3D_FVec lhs, C3D_FVec rhs)
 Dot product of two FVec4s. More...
 
static float FVec4_Magnitude (C3D_FVec v)
 Magnitude of a FVec4. More...
 
static C3D_FVec FVec4_Normalize (C3D_FVec v)
 Normalize a FVec4. More...
 
static C3D_FVec FVec3_New (float x, float y, float z)
 Create a new FVec3. More...
 
static float FVec3_Dot (C3D_FVec lhs, C3D_FVec rhs)
 Dot product of two FVec3s. More...
 
static float FVec3_Magnitude (C3D_FVec v)
 Magnitude of a FVec3. More...
 
static C3D_FVec FVec3_Normalize (C3D_FVec v)
 Normalize a FVec3. More...
 
static C3D_FVec FVec3_Add (C3D_FVec lhs, C3D_FVec rhs)
 Add two FVec3s. More...
 
static C3D_FVec FVec3_Subtract (C3D_FVec lhs, C3D_FVec rhs)
 Subtract two FVec3s. More...
 
static float FVec3_Distance (C3D_FVec lhs, C3D_FVec rhs)
 Distance between two 3D points. More...
 
static C3D_FVec FVec3_Scale (C3D_FVec v, float s)
 Scale a FVec3. More...
 
static C3D_FVec FVec3_Negate (C3D_FVec v)
 Negate a FVec3. More...
 
static C3D_FVec FVec3_Cross (C3D_FVec lhs, C3D_FVec rhs)
 Cross product of two FVec3s. More...
 

Matrix Math

Note
All matrices are 4x4 unless otherwise noted.
static void Mtx_Zeros (C3D_Mtx *out)
 Zero matrix. More...
 
static void Mtx_Copy (C3D_Mtx *out, const C3D_Mtx *in)
 Copy a matrix. More...
 
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. More...
 
static void Mtx_Identity (C3D_Mtx *out)
 Identity matrix. More...
 
void Mtx_Transpose (C3D_Mtx *out)
 Transposes the matrix. Row => Column, and vice versa. More...
 
static void Mtx_Add (C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs)
 Matrix addition. More...
 
static void Mtx_Subtract (C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs)
 Matrix subtraction. More...
 
void Mtx_Multiply (C3D_Mtx *out, const C3D_Mtx *a, const C3D_Mtx *b)
 Multiply two matrices. More...
 
float Mtx_Inverse (C3D_Mtx *out)
 Inverse a matrix. More...
 
C3D_FVec Mtx_MultiplyFVec3 (const C3D_Mtx *mtx, C3D_FVec v)
 Multiply 3x3 matrix by a FVec3. More...
 
C3D_FVec Mtx_MultiplyFVec4 (const C3D_Mtx *mtx, C3D_FVec v)
 Multiply 4x4 matrix by a FVec4. More...
 
static C3D_FVec Mtx_MultiplyFVecH (const C3D_Mtx *mtx, C3D_FVec v)
 Multiply 4x3 matrix by a FVec3. More...
 
void Mtx_FromQuat (C3D_Mtx *m, C3D_FQuat q)
 Get 4x4 matrix equivalent to Quaternion. More...
 

3D Transformation Matrix Math

Note
bRightSide is used to determine which side to perform the transformation. With an input matrix A and a transformation matrix B, bRightSide being true yields AB, while being false yield BA.
void Mtx_Translate (C3D_Mtx *mtx, float x, float y, float z, bool bRightSide)
 3D translation More...
 
void Mtx_Scale (C3D_Mtx *mtx, float x, float y, float z)
 3D Scale More...
 
void Mtx_Rotate (C3D_Mtx *mtx, C3D_FVec axis, float angle, bool bRightSide)
 3D Rotation More...
 
void Mtx_RotateX (C3D_Mtx *mtx, float angle, bool bRightSide)
 3D Rotation about the X axis More...
 
void Mtx_RotateY (C3D_Mtx *mtx, float angle, bool bRightSide)
 3D Rotation about the Y axis More...
 
void Mtx_RotateZ (C3D_Mtx *mtx, float angle, bool bRightSide)
 3D Rotation about the Z axis More...
 

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. More...
 
void Mtx_Persp (C3D_Mtx *mtx, float fovy, float aspect, float near, float far, bool isLeftHanded)
 Perspective projection. More...
 
void Mtx_PerspStereo (C3D_Mtx *mtx, float fovy, float aspect, float near, float far, float iod, float screen, bool isLeftHanded)
 Stereo perspective projection. More...
 
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. More...
 
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. More...
 
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. More...
 
void Mtx_LookAt (C3D_Mtx *out, C3D_FVec cameraPosition, C3D_FVec cameraTarget, C3D_FVec cameraUpVector, bool isLeftHanded)
 Look-At matrix, based on DirectX implementation. More...
 

Quaternion Math

C3D_FQuat Quat_Multiply (C3D_FQuat lhs, C3D_FQuat rhs)
 Multiply two Quaternions. More...
 
C3D_FQuat Quat_Pow (C3D_FQuat q, float p)
 Raise Quaternion to a power. More...
 
C3D_FVec Quat_CrossFVec3 (C3D_FQuat q, C3D_FVec v)
 Cross product of Quaternion and FVec3. More...
 
C3D_FQuat Quat_Rotate (C3D_FQuat q, C3D_FVec axis, float r, bool bRightSide)
 3D Rotation More...
 
C3D_FQuat Quat_RotateX (C3D_FQuat q, float r, bool bRightSide)
 3D Rotation about the X axis More...
 
C3D_FQuat Quat_RotateY (C3D_FQuat q, float r, bool bRightSide)
 3D Rotation about the Y axis More...
 
C3D_FQuat Quat_RotateZ (C3D_FQuat q, float r, bool bRightSide)
 3D Rotation about the Z axis More...
 
C3D_FQuat Quat_FromMtx (const C3D_Mtx *m)
 Get Quaternion equivalent to 4x4 matrix. More...
 
static C3D_FQuat Quat_Identity (void)
 Identity Quaternion. More...
 
static C3D_FQuat Quat_Conjugate (C3D_FQuat q)
 Quaternion conjugate. More...
 
static C3D_FQuat Quat_Inverse (C3D_FQuat q)
 Quaternion inverse. More...
 
static C3D_FVec FVec3_CrossQuat (C3D_FVec v, C3D_FQuat q)
 Cross product of FVec3 and Quaternion. More...
 
C3D_FQuat Quat_FromPitchYawRoll (float pitch, float yaw, float roll, bool bRightSide)
 Converting Pitch, Yaw, and Roll to Quaternion equivalent. More...
 
C3D_FQuat Quat_LookAt (C3D_FVec source, C3D_FVec target, C3D_FVec forwardVector, C3D_FVec upVector)
 Quaternion Look-At. More...
 
C3D_FQuat Quat_FromAxisAngle (C3D_FVec axis, float angle)
 Quaternion, created from a given axis and angle in radians. More...
 
#define Quat_New(i, j, k, r)   FVec4_New(i,j,k,r)
 Create a new Quaternion. More...
 
#define Quat_Negate(q)   FVec4_Negate(q)
 Negate a Quaternion. More...
 
#define Quat_Add(lhs, rhs)   FVec4_Add(lhs,rhs)
 Add two Quaternions. More...
 
#define Quat_Subtract(lhs, rhs)   FVec4_Subtract(lhs,rhs)
 Subtract two Quaternions. More...
 
#define Quat_Scale(q, s)   FVec4_Scale(q,s)
 Scale a Quaternion. More...
 
#define Quat_Normalize(q)   FVec4_Normalize(q)
 Normalize a Quaternion. More...
 
#define Quat_Dot(lhs, rhs)   FVec4_Dot(lhs,rhs)
 Dot product of two Quaternions. More...
 

Detailed Description

Implementations of matrix, vector, and quaternion operations.

Macro Definition Documentation

◆ C3D_Angle

#define C3D_Angle (   _angle)    ((_angle)*M_TAU)

Convert an angle from revolutions to radians.

Parameters
[in]_angleProportion of a full revolution
Returns
Angle in radians

◆ C3D_AngleFromDegrees

#define C3D_AngleFromDegrees (   _angle)    ((_angle)*M_TAU/360.0f)

Convert an angle from degrees to radians.

Parameters
[in]_angleAngle in degrees
Returns
Angle in radians

◆ M_TAU

#define M_TAU   (6.28318530717958647692528676655900576)

The one true circumference-to-radius ratio. See http://tauday.com/tau-manifesto

◆ Quat_Add

#define Quat_Add (   lhs,
  rhs 
)    FVec4_Add(lhs,rhs)

Add two Quaternions.

Parameters
[in]lhsAugend
[in]rhsAddend
Returns
lhs+rhs (sum)

◆ Quat_Dot

#define Quat_Dot (   lhs,
  rhs 
)    FVec4_Dot(lhs,rhs)

Dot product of two Quaternions.

Parameters
[in]lhsLeft-side Quaternion
[in]rhsRight-side Quaternion
Returns
lhs∙rhs

◆ Quat_Negate

#define Quat_Negate (   q)    FVec4_Negate(q)

Negate a Quaternion.

Note
This is equivalent to Quat_Scale(v, -1)
Parameters
[in]qQuaternion to negate
Returns
-q

◆ Quat_New

#define Quat_New (   i,
  j,
  k,
 
)    FVec4_New(i,j,k,r)

Create a new Quaternion.

Parameters
[in]iI-component
[in]jJ-component
[in]kK-component
[in]rReal component
Returns
New Quaternion

◆ Quat_Normalize

#define Quat_Normalize (   q)    FVec4_Normalize(q)

Normalize a Quaternion.

Parameters
[in]qQuaternion to normalize
Returns
q/‖q‖

◆ Quat_Scale

#define Quat_Scale (   q,
 
)    FVec4_Scale(q,s)

Scale a Quaternion.

Parameters
[in]qQuaternion to scale
[in]sScale factor
Returns
q*s

◆ Quat_Subtract

#define Quat_Subtract (   lhs,
  rhs 
)    FVec4_Subtract(lhs,rhs)

Subtract two Quaternions.

Parameters
[in]lhsMinuend
[in]rhsSubtrahend
Returns
lhs-rhs (difference)

Function Documentation

◆ FVec3_Add()

static C3D_FVec FVec3_Add ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Add two FVec3s.

Parameters
[in]lhsAugend
[in]rhsAddend
Returns
lhs+rhs (sum)

◆ FVec3_Cross()

static C3D_FVec FVec3_Cross ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Cross product of two FVec3s.

Note
This returns a pseudo-vector which is perpendicular to the plane spanned by the two input vectors.
Parameters
[in]lhsLeft-side FVec3
[in]rhsRight-side FVec3
Returns
lhs×rhs

◆ FVec3_CrossQuat()

static C3D_FVec FVec3_CrossQuat ( C3D_FVec  v,
C3D_FQuat  q 
)
inlinestatic

Cross product of FVec3 and Quaternion.

Parameters
[in]vBase FVec3
[in]qQuaternion to cross
Returns
v×q

◆ FVec3_Distance()

static float FVec3_Distance ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Distance between two 3D points.

Parameters
[in]lhsRelative origin
[in]rhsRelative point of interest
Returns
‖lhs-rhs‖

◆ FVec3_Dot()

static float FVec3_Dot ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Dot product of two FVec3s.

Parameters
[in]lhsLeft-side FVec3
[in]rhsRight-side FVec3
Returns
lhs∙rhs

◆ FVec3_Magnitude()

static float FVec3_Magnitude ( C3D_FVec  v)
inlinestatic

Magnitude of a FVec3.

Parameters
[in]vVector
Returns
‖v‖

◆ FVec3_Negate()

static C3D_FVec FVec3_Negate ( C3D_FVec  v)
inlinestatic

Negate a FVec3.

Note
This is equivalent to FVec3_Scale(v, -1)
Parameters
[in]vVector to negate
Returns
-v

◆ FVec3_New()

static C3D_FVec FVec3_New ( float  x,
float  y,
float  z 
)
inlinestatic

Create a new FVec3.

Parameters
[in]xX-component
[in]yY-component
[in]zZ-component
Returns
New FVec3

◆ FVec3_Normalize()

static C3D_FVec FVec3_Normalize ( C3D_FVec  v)
inlinestatic

Normalize a FVec3.

Parameters
[in]vFVec3 to normalize
Returns
v/‖v‖

◆ FVec3_Scale()

static C3D_FVec FVec3_Scale ( C3D_FVec  v,
float  s 
)
inlinestatic

Scale a FVec3.

Parameters
[in]vVector to scale
[in]sScale factor
Returns
v*s

◆ FVec3_Subtract()

static C3D_FVec FVec3_Subtract ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Subtract two FVec3s.

Parameters
[in]lhsMinuend
[in]rhsSubtrahend
Returns
lhs-rhs (difference)

◆ FVec4_Add()

static C3D_FVec FVec4_Add ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Add two FVec4s.

Parameters
[in]lhsAugend
[in]rhsAddend
Returns
lhs+rhs (sum)

◆ FVec4_Dot()

static float FVec4_Dot ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Dot product of two FVec4s.

Parameters
[in]lhsLeft-side FVec4
[in]rhsRight-side FVec4
Returns
lhs∙rhs

◆ FVec4_Magnitude()

static float FVec4_Magnitude ( C3D_FVec  v)
inlinestatic

Magnitude of a FVec4.

Parameters
[in]vVector
Returns
‖v‖

◆ FVec4_Negate()

static C3D_FVec FVec4_Negate ( C3D_FVec  v)
inlinestatic

Negate a FVec4.

Note
This is equivalent to FVec4_Scale(v, -1)
Parameters
[in]vVector to negate
Returns
-v

◆ FVec4_New()

static C3D_FVec FVec4_New ( float  x,
float  y,
float  z,
float  w 
)
inlinestatic

Create a new FVec4.

Parameters
[in]xX-component
[in]yY-component
[in]zZ-component
[in]wW-component
Returns
New FVec4

◆ FVec4_Normalize()

static C3D_FVec FVec4_Normalize ( C3D_FVec  v)
inlinestatic

Normalize a FVec4.

Parameters
[in]vFVec4 to normalize
Returns
v/‖v‖

◆ FVec4_PerspDivide()

static C3D_FVec FVec4_PerspDivide ( C3D_FVec  v)
inlinestatic

Perspective divide.

Parameters
[in]vVector to divide
Returns
v/v.w

◆ FVec4_Scale()

static C3D_FVec FVec4_Scale ( C3D_FVec  v,
float  s 
)
inlinestatic

Scale a FVec4.

Parameters
[in]vVector to scale
[in]sScale factor
Returns
v*s

◆ FVec4_Subtract()

static C3D_FVec FVec4_Subtract ( C3D_FVec  lhs,
C3D_FVec  rhs 
)
inlinestatic

Subtract two FVec4s.

Parameters
[in]lhsMinuend
[in]rhsSubtrahend
Returns
lhs-rhs (difference)

◆ Mtx_Add()

static void Mtx_Add ( C3D_Mtx out,
const C3D_Mtx lhs,
const C3D_Mtx rhs 
)
inlinestatic

Matrix addition.

Parameters
[out]outOutput matrix.
[in]lhsLeft matrix.
[in]rhsRight matrix.
Returns
lhs+rhs (sum)

◆ Mtx_Copy()

static void Mtx_Copy ( C3D_Mtx out,
const C3D_Mtx in 
)
inlinestatic

Copy a matrix.

Parameters
[out]outOutput matrix
[in]inInput matrix

◆ Mtx_Diagonal()

static void Mtx_Diagonal ( C3D_Mtx out,
float  x,
float  y,
float  z,
float  w 
)
inlinestatic

Creates a matrix with the diagonal using the given parameters.

Parameters
[out]outOutput matrix.
[in]xThe X component.
[in]yThe Y component.
[in]zThe Z component.
[in]wThe W component.

◆ Mtx_FromQuat()

void Mtx_FromQuat ( C3D_Mtx m,
C3D_FQuat  q 
)

Get 4x4 matrix equivalent to Quaternion.

Parameters
[out]mOutput matrix
[in]qInput Quaternion

◆ Mtx_Identity()

static void Mtx_Identity ( C3D_Mtx out)
inlinestatic

Identity matrix.

Parameters
[out]outMatrix to fill

◆ Mtx_Inverse()

float Mtx_Inverse ( C3D_Mtx out)

Inverse a matrix.

Parameters
[in,out]outMatrix to inverse
Return values
0.0fDegenerate matrix (no inverse)
Returns
determinant

◆ Mtx_LookAt()

void Mtx_LookAt ( C3D_Mtx out,
C3D_FVec  cameraPosition,
C3D_FVec  cameraTarget,
C3D_FVec  cameraUpVector,
bool  isLeftHanded 
)

Look-At matrix, based on DirectX implementation.

Note
See https://msdn.microsoft.com/en-us/library/windows/desktop/bb205342
Parameters
[out]outOutput matrix.
[in]cameraPositionPosition of the intended camera in 3D space.
[in]cameraTargetPosition of the intended target the camera is supposed to face in 3D space.
[in]cameraUpVectorThe vector that points straight up depending on the camera's "Up" direction.
[in]isLeftHandedWhether to build a LH projection

◆ Mtx_Multiply()

void Mtx_Multiply ( C3D_Mtx out,
const C3D_Mtx a,
const C3D_Mtx b 
)

Multiply two matrices.

Parameters
[out]outOutput matrix
[in]aMultiplicand
[in]bMultiplier

◆ Mtx_MultiplyFVec3()

C3D_FVec Mtx_MultiplyFVec3 ( const C3D_Mtx mtx,
C3D_FVec  v 
)

Multiply 3x3 matrix by a FVec3.

Parameters
[in]mtxMatrix
[in]vVector
Returns
mtx*v (product)

◆ Mtx_MultiplyFVec4()

C3D_FVec Mtx_MultiplyFVec4 ( const C3D_Mtx mtx,
C3D_FVec  v 
)

Multiply 4x4 matrix by a FVec4.

Parameters
[in]mtxMatrix
[in]vVector
Returns
mtx*v (product)

◆ Mtx_MultiplyFVecH()

static C3D_FVec Mtx_MultiplyFVecH ( const C3D_Mtx mtx,
C3D_FVec  v 
)
inlinestatic

Multiply 4x3 matrix by a FVec3.

Parameters
[in]mtxMatrix
[in]vVector
Returns
mtx*v (product)

◆ Mtx_Ortho()

void Mtx_Ortho ( C3D_Mtx mtx,
float  left,
float  right,
float  bottom,
float  top,
float  near,
float  far,
bool  isLeftHanded 
)

Orthogonal projection.

Parameters
[out]mtxOutput matrix
[in]leftLeft clip plane (X=left)
[in]rightRight clip plane (X=right)
[in]bottomBottom clip plane (Y=bottom)
[in]topTop clip plane (Y=top)
[in]nearNear clip plane (Z=near)
[in]farFar clip plane (Z=far)
[in]isLeftHandedWhether to build a LH projection
See also
Mtx_OrthoTilt

◆ Mtx_OrthoTilt()

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.

Parameters
[out]mtxOutput matrix
[in]leftLeft clip plane (X=left)
[in]rightRight clip plane (X=right)
[in]bottomBottom clip plane (Y=bottom)
[in]topTop clip plane (Y=top)
[in]nearNear clip plane (Z=near)
[in]farFar clip plane (Z=far)
[in]isLeftHandedWhether to build a LH projection
See also
Mtx_Ortho

◆ Mtx_Persp()

void Mtx_Persp ( C3D_Mtx mtx,
float  fovy,
float  aspect,
float  near,
float  far,
bool  isLeftHanded 
)

Perspective projection.

Parameters
[out]mtxOutput matrix
[in]fovyVertical field of view in radians
[in]aspectAspect ration of projection plane (width/height)
[in]nearNear clip plane (Z=near)
[in]farFar clip plane (Z=far)
[in]isLeftHandedWhether to build a LH projection
See also
Mtx_PerspTilt
Mtx_PerspStereo
Mtx_PerspStereoTilt

◆ Mtx_PerspStereo()

void Mtx_PerspStereo ( C3D_Mtx mtx,
float  fovy,
float  aspect,
float  near,
float  far,
float  iod,
float  screen,
bool  isLeftHanded 
)

Stereo perspective projection.

Note
Typically you will use iod to mean the distance between the eyes. Plug in -iod for the left eye and iod for the right eye.
The focal length is defined by screen. If objects are further than this, they will appear to be inside the screen. If objects are closer than this, they will appear to pop out of the screen. Objects at this distance appear to be at the screen.
Parameters
[out]mtxOutput matrix
[in]fovyVertical field of view in radians
[in]aspectAspect ration of projection plane (width/height)
[in]nearNear clip plane (Z=near)
[in]farFar clip plane (Z=far)
[in]iodInterocular distance
[in]screenFocal length
[in]isLeftHandedWhether to build a LH projection
See also
Mtx_Persp
Mtx_PerspTilt
Mtx_PerspStereoTilt

◆ Mtx_PerspStereoTilt()

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.

Note
See the notes for Mtx_PerspStereo
Parameters
[out]mtxOutput matrix
[in]fovyVertical field of view in radians
[in]aspectAspect ration of projection plane (width/height)
[in]nearNear clip plane (Z=near)
[in]farFar clip plane (Z=far)
[in]iodInterocular distance
[in]screenFocal length
[in]isLeftHandedWhether to build a LH projection
See also
Mtx_Persp
Mtx_PerspTilt
Mtx_PerspStereo

◆ Mtx_PerspTilt()

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.

Parameters
[out]mtxOutput matrix
[in]fovyVertical field of view in radians
[in]aspectAspect ration of projection plane (width/height)
[in]nearNear clip plane (Z=near)
[in]farFar clip plane (Z=far)
[in]isLeftHandedWhether to build a LH projection
See also
Mtx_Persp
Mtx_PerspStereo
Mtx_PerspStereoTilt

◆ Mtx_Rotate()

void Mtx_Rotate ( C3D_Mtx mtx,
C3D_FVec  axis,
float  angle,
bool  bRightSide 
)

3D Rotation

Parameters
[in,out]mtxMatrix to rotate
[in]axisAxis about which to rotate
[in]angleRadians to rotate
[in]bRightSideWhether to transform from the right side

◆ Mtx_RotateX()

void Mtx_RotateX ( C3D_Mtx mtx,
float  angle,
bool  bRightSide 
)

3D Rotation about the X axis

Parameters
[in,out]mtxMatrix to rotate
[in]angleRadians to rotate
[in]bRightSideWhether to transform from the right side

◆ Mtx_RotateY()

void Mtx_RotateY ( C3D_Mtx mtx,
float  angle,
bool  bRightSide 
)

3D Rotation about the Y axis

Parameters
[in,out]mtxMatrix to rotate
[in]angleRadians to rotate
[in]bRightSideWhether to transform from the right side

◆ Mtx_RotateZ()

void Mtx_RotateZ ( C3D_Mtx mtx,
float  angle,
bool  bRightSide 
)

3D Rotation about the Z axis

Parameters
[in,out]mtxMatrix to rotate
[in]angleRadians to rotate
[in]bRightSideWhether to transform from the right side

◆ Mtx_Scale()

void Mtx_Scale ( C3D_Mtx mtx,
float  x,
float  y,
float  z 
)

3D Scale

Parameters
[in,out]mtxMatrix to scale
[in]xX component to scale
[in]yY component to scale
[in]zZ component to scale

◆ Mtx_Subtract()

static void Mtx_Subtract ( C3D_Mtx out,
const C3D_Mtx lhs,
const C3D_Mtx rhs 
)
inlinestatic

Matrix subtraction.

Parameters
[out]outOutput matrix.
[in]lhsLeft matrix.
[in]rhsRight matrix.
Returns
lhs-rhs (difference)

◆ Mtx_Translate()

void Mtx_Translate ( C3D_Mtx mtx,
float  x,
float  y,
float  z,
bool  bRightSide 
)

3D translation

Parameters
[in,out]mtxMatrix to translate
[in]xX component to translate
[in]yY component to translate
[in]zZ component to translate
[in]bRightSideWhether to transform from the right side

◆ Mtx_Transpose()

void Mtx_Transpose ( C3D_Mtx out)

Transposes the matrix. Row => Column, and vice versa.

Parameters
[in,out]outOutput matrix.

◆ Mtx_Zeros()

static void Mtx_Zeros ( C3D_Mtx out)
inlinestatic

Zero matrix.

Parameters
[out]outMatrix to zero

◆ Quat_Conjugate()

static C3D_FQuat Quat_Conjugate ( C3D_FQuat  q)
inlinestatic

Quaternion conjugate.

Parameters
[in]qQuaternion of which to get conjugate
Returns
q*

◆ Quat_CrossFVec3()

C3D_FVec Quat_CrossFVec3 ( C3D_FQuat  q,
C3D_FVec  v 
)

Cross product of Quaternion and FVec3.

Parameters
[in]qBase Quaternion
[in]vVector to cross
Returns
q×v

◆ Quat_FromAxisAngle()

C3D_FQuat Quat_FromAxisAngle ( C3D_FVec  axis,
float  angle 
)

Quaternion, created from a given axis and angle in radians.

Parameters
[in]axisC3D_FVec The axis to rotate around at.
[in]anglefloat The angle to rotate. Unit: Radians
Returns
Quaternion rotation based on the axis and angle. Axis doesn't have to be orthogonal.

◆ Quat_FromMtx()

C3D_FQuat Quat_FromMtx ( const C3D_Mtx m)

Get Quaternion equivalent to 4x4 matrix.

Note
If the matrix is orthogonal or special orthogonal, where determinant(matrix) = +1.0f, then the matrix can be converted.
Parameters
[in]mInput Matrix
Returns
Generated Quaternion

◆ Quat_FromPitchYawRoll()

C3D_FQuat Quat_FromPitchYawRoll ( float  pitch,
float  yaw,
float  roll,
bool  bRightSide 
)

Converting Pitch, Yaw, and Roll to Quaternion equivalent.

Parameters
[in]pitchThe pitch angle in radians.
[in]yawThe yaw angle in radians.
[in]rollThe roll angle in radians.
[in]bRightSideWhether to transform from the right side
Returns
C3D_FQuat The Quaternion equivalent with the pitch, yaw, and roll (in that order) orientations applied.

◆ Quat_Identity()

static C3D_FQuat Quat_Identity ( void  )
inlinestatic

Identity Quaternion.

Returns
Identity Quaternion

◆ Quat_Inverse()

static C3D_FQuat Quat_Inverse ( C3D_FQuat  q)
inlinestatic

Quaternion inverse.

Note
This is equivalent to Quat_Pow(v, -1)
Parameters
[in]qQuaternion of which to get inverse
Returns
q-1

◆ Quat_LookAt()

C3D_FQuat Quat_LookAt ( C3D_FVec  source,
C3D_FVec  target,
C3D_FVec  forwardVector,
C3D_FVec  upVector 
)

Quaternion Look-At.

Parameters
[in]sourceC3D_FVec Starting position. Origin of rotation.
[in]targetC3D_FVec Target position to orient towards.
[in]forwardVectorC3D_FVec The Up vector.
[in]upVectorC3D_FVec The Up vector.
Returns
Quaternion rotation.

◆ Quat_Multiply()

C3D_FQuat Quat_Multiply ( C3D_FQuat  lhs,
C3D_FQuat  rhs 
)

Multiply two Quaternions.

Parameters
[in]lhsMultiplicand
[in]rhsMultiplier
Returns
lhs*rhs

◆ Quat_Pow()

C3D_FQuat Quat_Pow ( C3D_FQuat  q,
float  p 
)

Raise Quaternion to a power.

Note
If p is 0, this returns the identity Quaternion. If p is 1, this returns q.
Parameters
[in]qBase Quaternion
[in]pPower
Returns
qp

◆ Quat_Rotate()

C3D_FQuat Quat_Rotate ( C3D_FQuat  q,
C3D_FVec  axis,
float  r,
bool  bRightSide 
)

3D Rotation

Parameters
[in]qQuaternion to rotate
[in]axisAxis about which to rotate
[in]rRadians to rotate
[in]bRightSideWhether to transform from the right side
Returns
Rotated Quaternion

◆ Quat_RotateX()

C3D_FQuat Quat_RotateX ( C3D_FQuat  q,
float  r,
bool  bRightSide 
)

3D Rotation about the X axis

Parameters
[in]qQuaternion to rotate
[in]rRadians to rotate
[in]bRightSideWhether to transform from the right side
Returns
Rotated Quaternion

◆ Quat_RotateY()

C3D_FQuat Quat_RotateY ( C3D_FQuat  q,
float  r,
bool  bRightSide 
)

3D Rotation about the Y axis

Parameters
[in]qQuaternion to rotate
[in]rRadians to rotate
[in]bRightSideWhether to transform from the right side
Returns
Rotated Quaternion

◆ Quat_RotateZ()

C3D_FQuat Quat_RotateZ ( C3D_FQuat  q,
float  r,
bool  bRightSide 
)

3D Rotation about the Z axis

Parameters
[in]qQuaternion to rotate
[in]rRadians to rotate
[in]bRightSideWhether to transform from the right side
Returns
Rotated Quaternion