diff --git a/common/mathlib.cc b/common/mathlib.cc index 3c26ab6e..359e6e4f 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -167,6 +167,44 @@ glm::vec3 mangle_from_vec(const glm::vec3 &v) return mangle; } +glm::mat3x3 RotateAboutX(float t) +{ + //https://en.wikipedia.org/wiki/Rotation_matrix#Examples + + const float cost = cos(t); + const float sint = sin(t); + + return glm::mat3x3 { + 1, 0, 0, //col0 + 0, cost, sint, // col1 + 0, -sint, cost // col1 + }; +} + +glm::mat3x3 RotateAboutY(float t) +{ + const float cost = cos(t); + const float sint = sin(t); + + return glm::mat3x3{ + cost, 0, -sint, // col0 + 0, 1, 0, // col1 + sint, 0, cost //col2 + }; +} + +glm::mat3x3 RotateAboutZ(float t) +{ + const float cost = cos(t); + const float sint = sin(t); + + return glm::mat3x3{ + cost, sint, 0, // col0 + -sint, cost, 0, // col1 + 0, 0, 1 //col2 + }; +} + // Returns a 3x3 matrix that rotates (0,0,1) to the given surface normal. glm::mat3x3 RotateFromUpToSurfaceNormal(const glm::vec3 &surfaceNormal) { diff --git a/include/common/mathlib.hh b/include/common/mathlib.hh index f1bcac8a..5395c5e6 100644 --- a/include/common/mathlib.hh +++ b/include/common/mathlib.hh @@ -224,6 +224,9 @@ void RandomDir(vec3_t dir); glm::vec3 CosineWeightedHemisphereSample(float u1, float u2); glm::vec3 vec_from_mangle(const glm::vec3 &m); glm::vec3 mangle_from_vec(const glm::vec3 &v); +glm::mat3x3 RotateAboutX(float t); +glm::mat3x3 RotateAboutY(float t); +glm::mat3x3 RotateAboutZ(float t); glm::mat3x3 RotateFromUpToSurfaceNormal(const glm::vec3 &surfaceNormal); bool AABBsDisjoint(const vec3_t minsA, const vec3_t maxsA, const vec3_t minsB, const vec3_t maxsB); void AABB_Init(vec3_t mins, vec3_t maxs, const vec3_t pt);