16 #define M_TAU (2*M_PI)
23 #define C3D_Angle(_angle) ((_angle)*M_TAU)
30 #define C3D_AngleFromDegrees(_angle) ((_angle)*M_TAU/360.0f)
32 #define C3D_AspectRatioTop (400.0f / 240.0f)
33 #define C3D_AspectRatioBot (320.0f / 240.0f)
121 return lhs.
x*rhs.
x + lhs.
y*rhs.
y + lhs.
z*rhs.
z + lhs.
w*rhs.
w;
170 return lhs.
x*rhs.
x + lhs.
y*rhs.
y + lhs.
z*rhs.
z;
285 memset(out, 0,
sizeof(*out));
339 for (
int i = 0; i < 16; i++)
340 out->
m[i] = lhs->
m[i] + rhs->
m[i];
352 for (
int i = 0; i < 16; i++)
353 out->
m[i] = lhs->
m[i] - rhs->
m[i];
487 void Mtx_Ortho(
C3D_Mtx* mtx,
float left,
float right,
float bottom,
float top,
float near,
float far,
bool isLeftHanded);
501 void Mtx_Persp(
C3D_Mtx* mtx,
float fovy,
float aspect,
float near,
float far,
bool isLeftHanded);
523 void Mtx_PerspStereo(
C3D_Mtx* mtx,
float fovy,
float aspect,
float near,
float far,
float iod,
float screen,
bool isLeftHanded);
537 void Mtx_OrthoTilt(
C3D_Mtx* mtx,
float left,
float right,
float bottom,
float top,
float near,
float far,
bool isLeftHanded);
551 void Mtx_PerspTilt(
C3D_Mtx* mtx,
float fovy,
float aspect,
float near,
float far,
bool isLeftHanded);
568 void Mtx_PerspStereoTilt(
C3D_Mtx* mtx,
float fovy,
float aspect,
float near,
float far,
float iod,
float screen,
bool isLeftHanded);
595 #define Quat_New(i,j,k,r) FVec4_New(i,j,k,r)
603 #define Quat_Negate(q) FVec4_Negate(q)
611 #define Quat_Add(lhs,rhs) FVec4_Add(lhs,rhs)
619 #define Quat_Subtract(lhs,rhs) FVec4_Subtract(lhs,rhs)
627 #define Quat_Scale(q,s) FVec4_Scale(q,s)
634 #define Quat_Normalize(q) FVec4_Normalize(q)
642 #define Quat_Dot(lhs,rhs) FVec4_Dot(lhs,rhs)
722 return Quat_New(0.0f, 0.0f, 0.0f, 1.0f);
733 return Quat_New(-q.i, -q.j, -q.k, q.r);
748 return Quat_New(c.i/d, c.j/d, c.k/d, c.r/d);
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.
Definition: mtx_perspstereotilt.c:3
static C3D_FVec FVec3_Scale(C3D_FVec v, float s)
Scale a FVec3.
Definition: maths.h:240
C3D_FQuat Quat_RotateX(C3D_FQuat q, float r, bool bRightSide)
3D Rotation about the X axis
Definition: quat_rotatex.c:3
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.
Definition: mtx_orthotilt.c:3
#define Quat_New(i, j, k, r)
Create a new Quaternion.
Definition: maths.h:595
static C3D_FVec FVec4_New(float x, float y, float z, float w)
Create a new FVec4.
Definition: maths.h:48
static C3D_FVec FVec4_Add(C3D_FVec lhs, C3D_FVec rhs)
Add two FVec4s.
Definition: maths.h:59
void Mtx_Rotate(C3D_Mtx *mtx, C3D_FVec axis, float angle, bool bRightSide)
3D Rotation
Definition: mtx_rotate.c:3
static C3D_FVec FVec3_Subtract(C3D_FVec lhs, C3D_FVec rhs)
Subtract two FVec3s.
Definition: maths.h:216
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:306
C3D_FQuat Quat_FromPitchYawRoll(float pitch, float yaw, float roll, bool bRightSide)
Converting Pitch, Yaw, and Roll to Quaternion equivalent.
Definition: quat_frompitchyawroll.c:3
static C3D_FVec FVec4_Scale(C3D_FVec v, float s)
Scale a FVec4.
Definition: maths.h:95
static void Mtx_Identity(C3D_Mtx *out)
Identity matrix.
Definition: maths.h:319
void Mtx_Transpose(C3D_Mtx *out)
Transposes the matrix. Row => Column, and vice versa.
Definition: mtx_transpose.c:3
static float FVec3_Magnitude(C3D_FVec v)
Magnitude of a FVec3.
Definition: maths.h:178
static C3D_FVec FVec3_New(float x, float y, float z)
Create a new FVec3.
Definition: maths.h:156
void Mtx_Translate(C3D_Mtx *mtx, float x, float y, float z, bool bRightSide)
3D translation
Definition: mtx_translate.c:3
static C3D_FQuat Quat_Identity(void)
Identity Quaternion.
Definition: maths.h:719
C3D_FVec Quat_CrossFVec3(C3D_FQuat q, C3D_FVec v)
Cross product of Quaternion and FVec3.
Definition: quat_crossfvec3.c:3
static C3D_FVec Mtx_MultiplyFVecH(const C3D_Mtx *mtx, C3D_FVec v)
Multiply 4x3 matrix by a FVec3.
Definition: maths.h:394
static C3D_FVec FVec3_Add(C3D_FVec lhs, C3D_FVec rhs)
Add two FVec3s.
Definition: maths.h:204
void Mtx_PerspStereo(C3D_Mtx *mtx, float fovy, float aspect, float near, float far, float iod, float screen, bool isLeftHanded)
Stereo perspective projection.
Definition: mtx_perspstereo.c:3
void Mtx_Persp(C3D_Mtx *mtx, float fovy, float aspect, float near, float far, bool isLeftHanded)
Perspective projection.
Definition: mtx_persp.c:3
void Mtx_Scale(C3D_Mtx *mtx, float x, float y, float z)
3D Scale
Definition: mtx_scale.c:3
static float FVec4_Dot(C3D_FVec lhs, C3D_FVec rhs)
Dot product of two FVec4s.
Definition: maths.h:118
static void Mtx_Copy(C3D_Mtx *out, const C3D_Mtx *in)
Copy a matrix.
Definition: maths.h:293
static C3D_FQuat Quat_Conjugate(C3D_FQuat q)
Quaternion conjugate.
Definition: maths.h:730
C3D_FQuat Quat_LookAt(C3D_FVec source, C3D_FVec target, C3D_FVec forwardVector, C3D_FVec upVector)
Quaternion Look-At.
Definition: quat_lookat.c:4
static C3D_FVec FVec4_Subtract(C3D_FVec lhs, C3D_FVec rhs)
Subtract two FVec4s.
Definition: maths.h:71
static C3D_FVec FVec4_Negate(C3D_FVec v)
Negate a FVec4.
Definition: maths.h:83
C3D_FQuat Quat_FromAxisAngle(C3D_FVec axis, float angle)
Quaternion, created from a given axis and angle in radians.
Definition: quat_fromaxisangle.c:3
static C3D_FVec FVec3_Normalize(C3D_FVec v)
Normalize a FVec3.
Definition: maths.h:189
void Mtx_LookAt(C3D_Mtx *out, C3D_FVec cameraPosition, C3D_FVec cameraTarget, C3D_FVec cameraUpVector, bool isLeftHanded)
Look-At matrix, based on DirectX implementation.
Definition: mtx_lookat.c:3
float Mtx_Inverse(C3D_Mtx *out)
Inverse a matrix.
Definition: mtx_inverse.c:4
static C3D_FVec FVec3_Cross(C3D_FVec lhs, C3D_FVec rhs)
Cross product of two FVec3s.
Definition: maths.h:266
static C3D_FQuat Quat_Inverse(C3D_FQuat q)
Quaternion inverse.
Definition: maths.h:742
static float FVec4_Magnitude(C3D_FVec v)
Magnitude of a FVec4.
Definition: maths.h:129
void Mtx_RotateY(C3D_Mtx *mtx, float angle, bool bRightSide)
3D Rotation about the Y axis
Definition: mtx_rotatey.c:3
C3D_FQuat Quat_Multiply(C3D_FQuat lhs, C3D_FQuat rhs)
Multiply two Quaternions.
Definition: quat_multiply.c:3
C3D_FQuat Quat_Pow(C3D_FQuat q, float p)
Raise Quaternion to a power.
Definition: quat_pow.c:4
void Mtx_Ortho(C3D_Mtx *mtx, float left, float right, float bottom, float top, float near, float far, bool isLeftHanded)
Orthogonal projection.
Definition: mtx_ortho.c:3
static void Mtx_Add(C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs)
Matrix addition.
Definition: maths.h:337
C3D_FVec Mtx_MultiplyFVec3(const C3D_Mtx *mtx, C3D_FVec v)
Multiply 3x3 matrix by a FVec3.
Definition: mtx_multiplyfvec3.c:3
void Mtx_RotateX(C3D_Mtx *mtx, float angle, bool bRightSide)
3D Rotation about the X axis
Definition: mtx_rotatex.c:3
void Mtx_Multiply(C3D_Mtx *out, const C3D_Mtx *a, const C3D_Mtx *b)
Multiply two matrices.
Definition: mtx_multiply.c:3
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.
Definition: mtx_persptilt.c:3
static float FVec3_Dot(C3D_FVec lhs, C3D_FVec rhs)
Dot product of two FVec3s.
Definition: maths.h:167
C3D_FQuat Quat_RotateY(C3D_FQuat q, float r, bool bRightSide)
3D Rotation about the Y axis
Definition: quat_rotatey.c:3
C3D_FQuat Quat_Rotate(C3D_FQuat q, C3D_FVec axis, float r, bool bRightSide)
3D Rotation
Definition: quat_rotate.c:3
static float FVec3_Distance(C3D_FVec lhs, C3D_FVec rhs)
Distance between two 3D points.
Definition: maths.h:228
static void Mtx_Subtract(C3D_Mtx *out, const C3D_Mtx *lhs, const C3D_Mtx *rhs)
Matrix subtraction.
Definition: maths.h:350
static C3D_FVec FVec4_Normalize(C3D_FVec v)
Normalize a FVec4.
Definition: maths.h:140
static C3D_FVec FVec4_PerspDivide(C3D_FVec v)
Perspective divide.
Definition: maths.h:106
C3D_FVec Mtx_MultiplyFVec4(const C3D_Mtx *mtx, C3D_FVec v)
Multiply 4x4 matrix by a FVec4.
Definition: mtx_multiplyfvec4.c:3
static C3D_FVec FVec3_CrossQuat(C3D_FVec v, C3D_FQuat q)
Cross product of FVec3 and Quaternion.
Definition: maths.h:757
void Mtx_FromQuat(C3D_Mtx *m, C3D_FQuat q)
Get 4x4 matrix equivalent to Quaternion.
Definition: mtx_fromquat.c:3
static void Mtx_Zeros(C3D_Mtx *out)
Zero matrix.
Definition: maths.h:283
#define Quat_Dot(lhs, rhs)
Dot product of two Quaternions.
Definition: maths.h:642
void Mtx_RotateZ(C3D_Mtx *mtx, float angle, bool bRightSide)
3D Rotation about the Z axis
Definition: mtx_rotatez.c:3
static C3D_FVec FVec3_Negate(C3D_FVec v)
Negate a FVec3.
Definition: maths.h:252
C3D_FQuat Quat_FromMtx(const C3D_Mtx *m)
Get Quaternion equivalent to 4x4 matrix.
Definition: quat_frommtx.c:3
C3D_FQuat Quat_RotateZ(C3D_FQuat q, float r, bool bRightSide)
3D Rotation about the Z axis
Definition: quat_rotatez.c:3
Float quaternion. See C3D_FVec.
Float vector.
Definition: types.h:37
float x
X-component.
Definition: types.h:46
float z
Z-component.
Definition: types.h:44
float w
W-component.
Definition: types.h:43
float y
Y-component.
Definition: types.h:45
Row-major 4x4 matrix.
Definition: types.h:77
C3D_FVec r[4]
Rows are vectors.
Definition: types.h:78
float m[4 *4]
Raw access.
Definition: types.h:79