From 48701d9931ca4b137601315c3551d395d9e3d6d9 Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Tue, 24 Jun 2025 17:07:41 -0400 Subject: [PATCH] i done messed up --- utils/math/gryphn_mat4.h | 33 +++++++++++++++++++++++++++++++++ utils/math/gryphn_vec3.h | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/utils/math/gryphn_mat4.h b/utils/math/gryphn_mat4.h index 687730f..d49346d 100644 --- a/utils/math/gryphn_mat4.h +++ b/utils/math/gryphn_mat4.h @@ -79,6 +79,18 @@ static inline const gnMat4x4 gnRotate(gnVec3 axis, float rotation) { return rotate; } +static inline const gnMat4x4 gnScale(gnVec3 amount) { + gnMat4 rotate = { + .mat = { + { amount.x, 0.0f, 0.0f, 0.0f }, + { 0.0f, amount.y, 0.0f, 0.0f }, + { 0.0f, 0.0f, amount.z, 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f } + } + }; + return rotate; +} + // used GLMs lookAtLH from /glm/ext/matrix_transform.inl as a base static inline const gnMat4x4 gnLookAt(gnVec3 eye, gnVec3 center, gnVec3 up) { const gnVec3 f = gnVec3Normalize(gnVec3Subtract(center, eye)); @@ -94,3 +106,24 @@ static inline const gnMat4x4 gnLookAt(gnVec3 eye, gnVec3 center, gnVec3 up) { } }; } + +static inline const gnMat4x4 gnMultiply(gnMat4 a, gnMat4 b) { + gnMat4 result; + + for (int row = 0; row < 4; ++row) + for (int col = 0; col < 4; ++col) + result.mat[row][col] = a.mat[row][0] * b.mat[0][col] + + a.mat[row][1] * b.mat[1][col] + + a.mat[row][2] * b.mat[2][col] + + a.mat[row][3] * b.mat[3][col]; + + return result; +} + +static inline const gnVec3 gnMat4MultiplyVec3(gnMat4 m, gnVec3 v) { + gnVec3 result; + result.x = m.mat[0][0] * v.x + m.mat[1][0] * v.y + m.mat[2][0] * v.z + m.mat[3][0]; + result.y = m.mat[0][1] * v.x + m.mat[1][1] * v.y + m.mat[2][1] * v.z + m.mat[3][1]; + result.z = m.mat[0][2] * v.x + m.mat[1][2] * v.y + m.mat[2][2] * v.z + m.mat[3][2]; + return result; +} diff --git a/utils/math/gryphn_vec3.h b/utils/math/gryphn_vec3.h index 1f7a25f..8af2d71 100644 --- a/utils/math/gryphn_vec3.h +++ b/utils/math/gryphn_vec3.h @@ -35,7 +35,8 @@ static const inline gnVec3 gnVec3Normalize(gnVec3 in) { } static const inline gnVec3 gnVec3Cross(gnVec3 a, gnVec3 b) { return (gnVec3){a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; } static const inline float gnVec3Dot(gnVec3 a, gnVec3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } - +static const inline gnVec3 gnVec3Multiply(gnVec3 a, gnVec3 b) { return (gnVec3){ a.x * b.x, a.y * b.y, a.z * b.z }; } +static const inline gnVec3 gnVec3MultiplyBy(gnVec3 a, float b) { return (gnVec3){ a.x * b, a.y * b, a.z * b }; } typedef gnVec3 gnFVec3; typedef gnVec3 gnFloat3;