20 #define M_TAU (6.28318530717958647692528676655900576)
24 #define M_PI (M_TAU/2)
32 #define C3D_Angle(_angle) ((_angle)*M_TAU)
39 #define C3D_AngleFromDegrees(_angle) ((_angle)*M_TAU/360.0f)
41 #define C3D_AspectRatioTop (400.0f / 240.0f)
42 #define C3D_AspectRatioBot (320.0f / 240.0f)
130 return lhs.
x*rhs.
x + lhs.
y*rhs.
y + lhs.
z*rhs.
z + lhs.
w*rhs.
w;
179 return lhs.
x*rhs.
x + lhs.
y*rhs.
y + lhs.
z*rhs.
z;
294 memset(out, 0,
sizeof(*out));
348 for (
int i = 0; i < 16; i++)
349 out->
m[i] = lhs->
m[i] + rhs->
m[i];
361 for (
int i = 0; i < 16; i++)
362 out->
m[i] = lhs->
m[i] - rhs->
m[i];
496 void Mtx_Ortho(
C3D_Mtx* mtx,
float left,
float right,
float bottom,
float top,
float near,
float far,
bool isLeftHanded);
510 void Mtx_Persp(
C3D_Mtx* mtx,
float fovy,
float aspect,
float near,
float far,
bool isLeftHanded);
532 void Mtx_PerspStereo(
C3D_Mtx* mtx,
float fovy,
float aspect,
float near,
float far,
float iod,
float screen,
bool isLeftHanded);
546 void Mtx_OrthoTilt(
C3D_Mtx* mtx,
float left,
float right,
float bottom,
float top,
float near,
float far,
bool isLeftHanded);
604 #define Quat_New(i,j,k,r) FVec4_New(i,j,k,r)
612 #define Quat_Negate(q) FVec4_Negate(q)
620 #define Quat_Add(lhs,rhs) FVec4_Add(lhs,rhs)
628 #define Quat_Subtract(lhs,rhs) FVec4_Subtract(lhs,rhs)
636 #define Quat_Scale(q,s) FVec4_Scale(q,s)
643 #define Quat_Normalize(q) FVec4_Normalize(q)
651 #define Quat_Dot(lhs,rhs) FVec4_Dot(lhs,rhs)
731 return Quat_New(0.0f, 0.0f, 0.0f, 1.0f);
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.
static C3D_FVec FVec3_Scale(C3D_FVec v, float s)
Scale a FVec3.
Definition: maths.h:249
C3D_FQuat Quat_RotateX(C3D_FQuat q, float r, bool bRightSide)
3D Rotation about the X axis
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.
#define Quat_New(i, j, k, r)
Create a new Quaternion.
Definition: maths.h:604
static C3D_FVec FVec4_New(float x, float y, float z, float w)
Create a new FVec4.
Definition: maths.h:57
static C3D_FVec FVec4_Add(C3D_FVec lhs, C3D_FVec rhs)
Add two FVec4s.
Definition: maths.h:68
void Mtx_Rotate(C3D_Mtx *mtx, C3D_FVec axis, float angle, bool bRightSide)
3D Rotation
static C3D_FVec FVec3_Subtract(C3D_FVec lhs, C3D_FVec rhs)
Subtract two FVec3s.
Definition: maths.h:225
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.
Definition: maths.h:315
C3D_FQuat Quat_FromPitchYawRoll(float pitch, float yaw, float roll, bool bRightSide)
Converting Pitch, Yaw, and Roll to Quaternion equivalent.
static C3D_FVec FVec4_Scale(C3D_FVec v, float s)
Scale a FVec4.
Definition: maths.h:104
static void Mtx_Identity(C3D_Mtx *out)
Identity matrix.
Definition: maths.h:328
void Mtx_Transpose(C3D_Mtx *out)
Transposes the matrix. Row => Column, and vice versa.
static float FVec3_Magnitude(C3D_FVec v)
Magnitude of a FVec3.
Definition: maths.h:187
static C3D_FVec FVec3_New(float x, float y, float z)
Create a new FVec3.
Definition: maths.h:165
void Mtx_Translate(C3D_Mtx *mtx, float x, float y, float z, bool bRightSide)
3D translation
static C3D_FQuat Quat_Identity(void)
Identity Quaternion.
Definition: maths.h:728
C3D_FVec Quat_CrossFVec3(C3D_FQuat q, C3D_FVec v)
Cross product of Quaternion and FVec3.
static C3D_FVec Mtx_MultiplyFVecH(const C3D_Mtx *mtx, C3D_FVec v)
Multiply 4x3 matrix by a FVec3.
Definition: maths.h:403
static C3D_FVec FVec3_Add(C3D_FVec lhs, C3D_FVec rhs)
Add two FVec3s.
Definition: maths.h:213
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_Persp(C3D_Mtx *mtx, float fovy, float aspect, float near, float far, bool isLeftHanded)
Perspective projection.
void Mtx_Scale(C3D_Mtx *mtx, float x, float y, float z)
3D Scale
static float FVec4_Dot(C3D_FVec lhs, C3D_FVec rhs)
Dot product of two FVec4s.
Definition: maths.h:127
static void Mtx_Copy(C3D_Mtx *out, const C3D_Mtx *in)
Copy a matrix.
Definition: maths.h:302
static C3D_FQuat Quat_Conjugate(C3D_FQuat q)
Quaternion conjugate.
Definition: maths.h:739
C3D_FQuat Quat_LookAt(C3D_FVec source, C3D_FVec target, C3D_FVec forwardVector, C3D_FVec upVector)
Quaternion Look-At.
static C3D_FVec FVec4_Subtract(C3D_FVec lhs, C3D_FVec rhs)
Subtract two FVec4s.
Definition: maths.h:80
static C3D_FVec FVec4_Negate(C3D_FVec v)
Negate a FVec4.
Definition: maths.h:92
C3D_FQuat Quat_FromAxisAngle(C3D_FVec axis, float angle)
Quaternion, created from a given axis and angle in radians.
static C3D_FVec FVec3_Normalize(C3D_FVec v)
Normalize a FVec3.
Definition: maths.h:198
void Mtx_LookAt(C3D_Mtx *out, C3D_FVec cameraPosition, C3D_FVec cameraTarget, C3D_FVec cameraUpVector, bool isLeftHanded)
Look-At matrix, based on DirectX implementation.
float Mtx_Inverse(C3D_Mtx *out)
Inverse a matrix.
static C3D_FVec FVec3_Cross(C3D_FVec lhs, C3D_FVec rhs)
Cross product of two FVec3s.
Definition: maths.h:275
static C3D_FQuat Quat_Inverse(C3D_FQuat q)
Quaternion inverse.
Definition: maths.h:751
static float FVec4_Magnitude(C3D_FVec v)
Magnitude of a FVec4.
Definition: maths.h:138
void Mtx_RotateY(C3D_Mtx *mtx, float angle, bool bRightSide)
3D Rotation about the Y axis
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.
void Mtx_Ortho(C3D_Mtx *mtx, float left, float right, float bottom, float top, float near, float far, bool isLeftHanded)
Orthogonal projection.
static void Mtx_Add(C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs)
Matrix addition.
Definition: maths.h:346
C3D_FVec Mtx_MultiplyFVec3(const C3D_Mtx *mtx, C3D_FVec v)
Multiply 3x3 matrix by a FVec3.
void Mtx_RotateX(C3D_Mtx *mtx, float angle, bool bRightSide)
3D Rotation about the X axis
void Mtx_Multiply(C3D_Mtx *out, const C3D_Mtx *a, const C3D_Mtx *b)
Multiply two matrices.
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.
static float FVec3_Dot(C3D_FVec lhs, C3D_FVec rhs)
Dot product of two FVec3s.
Definition: maths.h:176
C3D_FQuat Quat_RotateY(C3D_FQuat q, float r, bool bRightSide)
3D Rotation about the Y axis
C3D_FQuat Quat_Rotate(C3D_FQuat q, C3D_FVec axis, float r, bool bRightSide)
3D Rotation
static float FVec3_Distance(C3D_FVec lhs, C3D_FVec rhs)
Distance between two 3D points.
Definition: maths.h:237
static void Mtx_Subtract(C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs)
Matrix subtraction.
Definition: maths.h:359
static C3D_FVec FVec4_Normalize(C3D_FVec v)
Normalize a FVec4.
Definition: maths.h:149
static C3D_FVec FVec4_PerspDivide(C3D_FVec v)
Perspective divide.
Definition: maths.h:115
C3D_FVec Mtx_MultiplyFVec4(const C3D_Mtx *mtx, C3D_FVec v)
Multiply 4x4 matrix by a FVec4.
static C3D_FVec FVec3_CrossQuat(C3D_FVec v, C3D_FQuat q)
Cross product of FVec3 and Quaternion.
Definition: maths.h:766
void Mtx_FromQuat(C3D_Mtx *m, C3D_FQuat q)
Get 4x4 matrix equivalent to Quaternion.
static void Mtx_Zeros(C3D_Mtx *out)
Zero matrix.
Definition: maths.h:292
#define Quat_Dot(lhs, rhs)
Dot product of two Quaternions.
Definition: maths.h:651
void Mtx_RotateZ(C3D_Mtx *mtx, float angle, bool bRightSide)
3D Rotation about the Z axis
static C3D_FVec FVec3_Negate(C3D_FVec v)
Negate a FVec3.
Definition: maths.h:261
C3D_FQuat Quat_FromMtx(const C3D_Mtx *m)
Get Quaternion equivalent to 4x4 matrix.
C3D_FQuat Quat_RotateZ(C3D_FQuat q, float r, bool bRightSide)
3D Rotation about the Z axis
Float vector.
Definition: types.h:52
float x
X-component.
Definition: types.h:61
float j
J-component.
Definition: types.h:71
float z
Z-component.
Definition: types.h:59
float w
W-component.
Definition: types.h:58
float k
K-component.
Definition: types.h:70
float r
Real component.
Definition: types.h:69
float i
I-component.
Definition: types.h:72
float y
Y-component.
Definition: types.h:60
Row-major 4x4 matrix.
Definition: types.h:91
C3D_FVec r[4]
Rows are vectors.
Definition: types.h:92
float m[4 *4]
Raw access.
Definition: types.h:93