Implement bone matrix computation

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-01 21:05:52 +01:00
1 parent e81061ad22
commit 998d5e88e1
6 files changed
+132

No files matched your search

+57
View File
@@ -74,3 +74,60 @@ mat4_t mat4_perspective(float aspect, float fov, float near, float far)
{ 0, 0, -far * near / (far - near), 0 },
};
}
mat4_t mat4_translate_vec3(vec3_t v)
{
return (mat4_t) {
{ 1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 1, 0 },
{ v.x, v.y, v.z, 1 },
};
}
mat4_t mat4_scale_vec3(vec3_t v)
{
return (mat4_t) {
{ v.x, 0, 0, 0 },
{ 0, v.y, 0, 0 },
{ 0, 0, v.z, 0 },
{ 0, 0, 0, 1 },
};
}
mat4_t mat4_rotate_quaternion(vec4_t q)
{
const float xx = q.x * q.x;
const float xy = q.x * q.y;
const float xz = q.x * q.z;
const float xw = q.x * q.w;
const float yy = q.y * q.y;
const float yz = q.y * q.z;
const float yw = q.y * q.w;
const float zz = q.z * q.z;
const float zw = q.z * q.w;
return (mat4_t) {
{
1 - 2 * (yy + zz),
2 * (xy + zw),
2 * (xz - yw),
0,
},
{
2 * (xy - zw),
1 - 2 * (xx + zz),
2 * (yz + xw),
0,
},
{
2 * (xz + yw),
2 * (yz - xw),
1 - 2 * (xx + yy),
0,
},
{ 0, 0, 0, 1 },
};
}