aboutsummaryrefslogtreecommitdiff
path: root/src/vec4ops/rotations4d.cpp
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-13 16:03:58 -0500
committerDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-13 16:03:58 -0500
commit23d8f83bfcfdb48ed18bf01204d262322c4e41e4 (patch)
treec98656786fd5a7d6e861ead75d9562db85c036ba /src/vec4ops/rotations4d.cpp
parentd2a1eea88205e7ee77463bcda771c64f33136d71 (diff)
parent6e27cd596611758bf82f58cff25ad6310bb5ad6e (diff)
Merge branch 'main' of https://github.com/NicholasBottone/the-all-americans-in-cs1230
merge.
Diffstat (limited to 'src/vec4ops/rotations4d.cpp')
-rw-r--r--src/vec4ops/rotations4d.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/vec4ops/rotations4d.cpp b/src/vec4ops/rotations4d.cpp
index 37997de..1ff43a7 100644
--- a/src/vec4ops/rotations4d.cpp
+++ b/src/vec4ops/rotations4d.cpp
@@ -72,3 +72,46 @@ glm::mat4 Vec4Ops::getRotationMatrix4ZW(
result[1][1] = 1;
return result;
}
+
+glm::mat4 Vec4Ops::getRotationMatrix4(
+ std::vector<float> anglesRadians)
+{
+ // make the identity
+ glm::mat4 result = glm::mat4(0.f);
+ result[0][0] = 1.f;
+ result[1][1] = 1.f;
+ result[2][2] = 1.f;
+ result[3][3] = 1.f;
+
+ // apply the rotations, starting with the last angle, which corresponds to ZW
+ if (anglesRadians.size() != 6) {
+ throw std::runtime_error("invalid rotation angle array");
+ }
+ for (int i = 5; i >= 0; i--) {
+ switch (i) {
+ case 0:
+ result *= getRotationMatrix4XY(anglesRadians[i]) * result;
+ break;
+ case 1:
+ result *= getRotationMatrix4ZX(anglesRadians[i]) * result;
+ break;
+ case 2:
+ result *= getRotationMatrix4YZ(anglesRadians[i]) * result;
+ break;
+ case 3:
+ result *= getRotationMatrix4XW(anglesRadians[i]) * result;
+ break;
+ case 4:
+ result *= getRotationMatrix4YW(anglesRadians[i]) * result;
+ break;
+ case 5:
+ result *= getRotationMatrix4ZW(anglesRadians[i]) * result;
+ break;
+ default:
+ throw std::runtime_error("invalid rotation matrix");
+ }
+ }
+
+ return result;
+}
+