aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/4dvecops/rotations4d.cpp28
-rw-r--r--src/4dvecops/vec4ops.h26
-rw-r--r--src/raytracer/raytracer.h3
-rw-r--r--src/utils/sceneparser.cpp58
-rw-r--r--src/utils/sceneparser.h6
5 files changed, 89 insertions, 32 deletions
diff --git a/src/4dvecops/rotations4d.cpp b/src/4dvecops/rotations4d.cpp
index 62746eb..4943c7f 100644
--- a/src/4dvecops/rotations4d.cpp
+++ b/src/4dvecops/rotations4d.cpp
@@ -1,6 +1,7 @@
#include "raytracer/raytracer.h"
+#include "4dvecops/vec4ops.h"
-glm::mat4 getRotationMatrix4XY(
+glm::mat4 Vec4Ops::getRotationMatrix4XY(
float angleRadians) {
glm::mat4 result;
result[0][0] = cos(angleRadians);
@@ -12,7 +13,7 @@ glm::mat4 getRotationMatrix4XY(
return result;
}
-glm::mat4 getRotationMatrix4YZ(
+glm::mat4 Vec4Ops::getRotationMatrix4YZ(
float angleRadians) {
glm::mat4 result;
result[1][1] = cos(angleRadians);
@@ -24,7 +25,7 @@ glm::mat4 getRotationMatrix4YZ(
return result;
}
-glm::mat4 getRotationMatrix4ZX(
+glm::mat4 Vec4Ops::getRotationMatrix4ZX(
float angleRadians) {
glm::mat4 result;
result[2][2] = cos(angleRadians);
@@ -36,7 +37,7 @@ glm::mat4 getRotationMatrix4ZX(
return result;
}
-glm::mat4 getRotationMatrix4XW(
+glm::mat4 Vec4Ops::getRotationMatrix4XW(
float angleRadians) {
glm::mat4 result;
result[0][0] = cos(angleRadians);
@@ -48,7 +49,7 @@ glm::mat4 getRotationMatrix4XW(
return result;
}
-glm::mat4 getRotationMatrix4YW(
+glm::mat4 Vec4Ops::getRotationMatrix4YW(
float angleRadians) {
glm::mat4 result;
result[1][1] = cos(angleRadians);
@@ -60,7 +61,7 @@ glm::mat4 getRotationMatrix4YW(
return result;
}
-glm::mat4 getRotationMatrix4ZW(
+glm::mat4 Vec4Ops::getRotationMatrix4ZW(
float angleRadians) {
glm::mat4 result;
result[2][2] = cos(angleRadians);
@@ -70,19 +71,4 @@ glm::mat4 getRotationMatrix4ZW(
result[0][0] = 1;
result[1][1] = 1;
return result;
-}
-
-glm::mat4 RayTracer::getRotationMatrix4(
- float angleRadiansXY,
- float angleRadiansYZ,
- float angleRadiansZX,
- float angleRadiansXW,
- float angleRadiansYW,
- float angleRadiansZW) {
- return getRotationMatrix4XY(angleRadiansXY) *
- getRotationMatrix4YZ(angleRadiansYZ) *
- getRotationMatrix4ZX(angleRadiansZX) *
- getRotationMatrix4XW(angleRadiansXW) *
- getRotationMatrix4YW(angleRadiansYW) *
- getRotationMatrix4ZW(angleRadiansZW);
} \ No newline at end of file
diff --git a/src/4dvecops/vec4ops.h b/src/4dvecops/vec4ops.h
new file mode 100644
index 0000000..48d9139
--- /dev/null
+++ b/src/4dvecops/vec4ops.h
@@ -0,0 +1,26 @@
+//
+// Created by Michael Foiani on 12/8/23.
+//
+
+#ifndef PROJECTS_RAY_VEC4OPS_H
+#define PROJECTS_RAY_VEC4OPS_H
+
+#include <glm/glm.hpp>
+
+class Vec4Ops {
+public:
+
+ static glm::mat4 getRotationMatrix4XY(float angleRadians);
+
+ static glm::mat4 getRotationMatrix4YZ(float angleRadians);
+
+ static glm::mat4 getRotationMatrix4ZX(float angleRadians);
+
+ static glm::mat4 getRotationMatrix4XW(float angleRadians);
+
+ static glm::mat4 getRotationMatrix4YW(float angleRadians);
+
+ static glm::mat4 getRotationMatrix4ZW(float angleRadians);
+};
+
+#endif //PROJECTS_RAY_VEC4OPS_H
diff --git a/src/raytracer/raytracer.h b/src/raytracer/raytracer.h
index 4bdca6f..4df9200 100644
--- a/src/raytracer/raytracer.h
+++ b/src/raytracer/raytracer.h
@@ -165,8 +165,7 @@ public:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
- glm::mat4 getRotationMatrix4(float angleRadiansXY, float angleRadiansYZ, float angleRadiansZX, float angleRadiansXW,
- float angleRadiansYW, float angleRadiansZW);
+ glm::mat4 getRotationMatrix4(float angle, glm::vec3 axis3, glm::vec3 axisW);
signals:
void xyRotationChanged(float value);
void xzRotationChanged(float value);
diff --git a/src/utils/sceneparser.cpp b/src/utils/sceneparser.cpp
index 991dcfd..12f83bc 100644
--- a/src/utils/sceneparser.cpp
+++ b/src/utils/sceneparser.cpp
@@ -1,5 +1,6 @@
#include "sceneparser.h"
#include "scenefilereader.h"
+#include "4dvecops/vec4ops.h"
#include <glm/gtx/transform.hpp>
#include <QImage>
#include <iostream>
@@ -39,16 +40,13 @@ void initTree(SceneNode* currentNode, std::vector<RenderShapeData> *shapes, std:
switch (t->type)
{
case TransformationType::TRANSFORMATION_TRANSLATE:
- currentCTM *= glm::translate(glm::vec3(t->translate));
- currentTranslation4d *= glm::vec4(t->translate); // TODO
+ SceneParser::translate4(currentTranslation4d, t->translate);
break;
case TransformationType::TRANSFORMATION_SCALE:
- currentCTM *= glm::scale(glm::vec3(t->scale));
- currentTranslation4d *= glm::vec4(t->scale); // TODO
+ SceneParser::scale4(currentTranslation4d, t->scale);
break;
case TransformationType::TRANSFORMATION_ROTATE:
- currentCTM *= glm::rotate(t->angle, glm::vec3(t->rotate[0], t->rotate[1], t->rotate[2]));
- // TODO: 4d rotation
+ currentCTM *= SceneParser::getRotationMatrix4(t->angle, t->rotate3, t->rotateW);
break;
case TransformationType::TRANSFORMATION_MATRIX:
currentCTM *= glm::mat4(t->matrix);
@@ -68,7 +66,7 @@ void initTree(SceneNode* currentNode, std::vector<RenderShapeData> *shapes, std:
ctm: currentCTM,
translation4d: currentTranslation4d,
inverseCTM: glm::inverse(currentCTM),
- inverseTranslation4d: glm::inverse(currentTranslation4d)
+ inverseTranslation4d: -currentTranslation4d,
};
shapes->push_back(rsd);
}
@@ -114,7 +112,7 @@ void initTree(SceneNode* currentNode, std::vector<RenderShapeData> *shapes, std:
}
for (auto child : currentNode->children) {
- initTree(child, shapes, lights, currentCTM);
+ initTree(child, shapes, lights, currentCTM, currentTranslation4d);
}
}
@@ -139,8 +137,50 @@ bool SceneParser::parse(std::string filepath, RenderData &renderData) {
renderData.shapes.clear();
renderData.lights.clear();
auto currentCTM = glm::mat4(1.0f);
+ auto currentTranslation4d = glm::vec4(0.0f);
- initTree(root, &renderData.shapes, &renderData.lights, currentCTM);
+ initTree(root, &renderData.shapes, &renderData.lights, currentCTM, currentTranslation4d);
return true;
}
+
+glm::mat4 SceneParser::getRotationMatrix4(
+ float angle,
+ glm::vec3 axis3,
+ glm::vec3 axisW) {
+ // start with the normal rotation from the normal 3d axes
+ if (axis3.x > 0)
+ return Vec4Ops::getRotationMatrix4XY(angle);
+ else if (axis3.y > 0)
+ return Vec4Ops::getRotationMatrix4YZ(angle);
+ else if (axis3.z > 0)
+ return Vec4Ops::getRotationMatrix4ZX(angle);
+ else if (axisW.x > 0)
+ return Vec4Ops::getRotationMatrix4XW(angle);
+ else if (axisW.y > 0)
+ return Vec4Ops::getRotationMatrix4YW(angle);
+ else if (axisW.z > 0)
+ return Vec4Ops::getRotationMatrix4ZW(angle);
+ else
+ throw std::runtime_error("invalid axis");
+}
+
+void SceneParser::translate4(
+ glm::vec4 &v1,
+ glm::vec4 v2
+ ) {
+ v1.x += v2.x;
+ v1.y += v2.y;
+ v1.z += v2.z;
+ v1.w += v2.w;
+}
+
+void SceneParser::scale4(
+ glm::vec4 &v1,
+ glm::vec4 v2
+ ) {
+ v1.x *= v2.x;
+ v1.y *= v2.y;
+ v1.z *= v2.z;
+ v1.w *= v2.w;
+} \ No newline at end of file
diff --git a/src/utils/sceneparser.h b/src/utils/sceneparser.h
index 8155ca8..fa8a2ac 100644
--- a/src/utils/sceneparser.h
+++ b/src/utils/sceneparser.h
@@ -30,4 +30,10 @@ public:
// @param renderData On return, this will contain the metadata of the loaded scene.
// @return A boolean value indicating whether the parse was successful.
static bool parse(std::string filepath, RenderData &renderData);
+
+ static glm::mat4 getRotationMatrix4(float angle, glm::vec3 axis3, glm::vec3 axisW);
+
+ static void translate4(glm::vec4 &v1, glm::vec4 v2);
+
+ static void scale4(glm::vec4 &v1, glm::vec4 v2);
};