LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
|
=== All about quaternions ===
LG_Quat lg_quat | ( | double | x, |
double | y, | ||
double | z, | ||
double | w | ||
) |
Multiply 2 quats
(From: https://github.com/mrdoob/three.js/blob/master/src/math/Quaternion.js) http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm#mul
LG_Quat lg_quat_from_euler_ang | ( | LG_EulerAng | an, |
const char * | rot_order | ||
) |
Get new quat from Euler angles
(From: https://github.com/mrdoob/three.js/blob/master/src/math/Quaternion.js)
an | A LG_EulerAng |
rot_order | One of "XYZ", "YXZ", "ZXY", "ZYX", "YZX", "XZY" |
Get quat from 3 x 3 rotation matrix
Using 'Converting a Rotation Matrix to a Quaternion' by Mike Day, Insomniac Games
https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2015/01/matrix-to-quat.pdf
https://www.opengl-tutorial.org/assets/faq_quaternions/index.html#Q55
https://danceswithcode.net/engineeringnotes/quaternions/quaternions.html
m | A 3 x 3 rotation matrix |
void lg_quat_conjugate | ( | LG_Quat * | q | ) |
void lg_quat_invert | ( | LG_Quat * | q | ) |
double lg_quat_magnitude | ( | LG_Quat | q | ) |
void lg_quat_set_identity | ( | LG_Quat * | q | ) |
LG_Quat lg_quat_get_identity | ( | ) |
Get identity quat
LG_EulerAng lg_euler_ang | ( | double | x_rot, |
double | y_rot, | ||
double | z_rot | ||
) |
Create a new euler angle
Use DEG_TO_RAD macro when necessary
x_rot | Rotation around X axis in radians |
y_rot | Rotation around Y axis in radians |
z_rot | Rotation around Z axis in radians |
Create a new axis and angle
Use DEG_TO_RAD macro when necessary
axis | Axis unit vector |
angle | Angle in radian |
LG_EulerAng lg_axis_angle_to_euler_ang | ( | LG_AxAng | axis_ang | ) |
Get Euler angles from axis and angle
(From: https://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToEuler/index.htm
Also check out 'terminological ambiguities' in: https://academicflight.com/articles/kinematics/rotation-formalisms/euler-angles/)
=== TODO: check this func is correct ===
axis_ang | A LG_AxAng |
mat3_t mat3 | ( | float | m00, |
float | m10, | ||
float | m20, | ||
float | m01, | ||
float | m11, | ||
float | m21, | ||
float | m02, | ||
float | m12, | ||
float | m22 | ||
) |
Create a 3 x 3, column-major order matrix, suitable to store pure rotations
-> MOVE THAT TO MATH_3D.H ?
m00 | Float value to store at m[0][0] |
m10 | Float value to store at m[1][0] |
m20 | Float value to store at m[2][0] |
m01 | Float value to store at m[0][1] |
m11 | Float value to store at m[1][1] |
m21 | Float value to store at m[2][1] |
m02 | Float value to store at m[0][2] |
m12 | Float value to store at m[1][2] |
m22 | Float value to store at m[2][2] |
Transpose a 3 x 3 matrix
-> MOVE THAT TO MATH_3D.H ?
matrix | A 3 x 3 matrix |
LG_QuatV* lg_quatv | ( | ) |
Return a static LG_QuatV struct, ie convenient precomputed quat values
So far:
Angles for x/y/z_small = M_PI * QUAT_PI_K (= M_PI / 200.0)
Rot order defined by ROT_SEQ in lg_quaternions.h
=== TODO: test this func is correct ===
Typical usage example: