diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-12-08 13:58:54 -0500 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-12-08 13:58:54 -0500 |
commit | df15d0f234f464f53cfb2480f31a901f9df51ba7 (patch) | |
tree | 00b10ed9ef685317846ec38b9117ab8b439d516e | |
parent | 965859204890f980594f5fff1d20a46bb8606f55 (diff) |
cleaup sceneparser.cpp file
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-d8c16986ac54f14e6ad2.json (renamed from cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-bacf5e2e80ef1d2e1af1.json) | 2 | ||||
-rw-r--r-- | cmake-build-debug/.cmake/api/v1/reply/index-2023-12-08T18-39-18-0017.json (renamed from cmake-build-debug/.cmake/api/v1/reply/index-2023-12-08T18-02-24-0883.json) | 4 | ||||
-rw-r--r-- | cmake-build-debug/.cmake/api/v1/reply/target-projects_ray-Debug-435ebb35886eb992308e.json (renamed from cmake-build-debug/.cmake/api/v1/reply/target-projects_ray-Debug-81d0b664d25bd1619433.json) | 8 | ||||
-rw-r--r-- | cmake-build-debug/CMakeFiles/projects_ray_autogen.dir/AutogenInfo.json | 4 | ||||
-rw-r--r-- | cmake-build-debug/Testing/Temporary/LastTest.log | 4 | ||||
-rw-r--r-- | cmake-build-debug/build.ninja | 2 | ||||
-rw-r--r-- | src/4dvecops/rotations4d.cpp | 28 | ||||
-rw-r--r-- | src/4dvecops/vec4ops.h | 26 | ||||
-rw-r--r-- | src/raytracer/raytracer.h | 3 | ||||
-rw-r--r-- | src/utils/sceneparser.cpp | 58 | ||||
-rw-r--r-- | src/utils/sceneparser.h | 6 |
12 files changed, 102 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f3b2471..3af6982 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ add_executable(${PROJECT_NAME} src/4dvecops/vec4operations.cpp src/4dvecops/rotations4d.cpp src/4dvecops/transform4d.cpp + src/4dvecops/vec4ops.h ) # GLM: this creates its library and allows you to `#include "glm/..."` diff --git a/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-bacf5e2e80ef1d2e1af1.json b/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-d8c16986ac54f14e6ad2.json index f24fa75..234c68a 100644 --- a/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-bacf5e2e80ef1d2e1af1.json +++ b/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-d8c16986ac54f14e6ad2.json @@ -59,7 +59,7 @@ { "directoryIndex" : 0, "id" : "projects_ray::@6890427a1f51a3e7e1df", - "jsonFile" : "target-projects_ray-Debug-81d0b664d25bd1619433.json", + "jsonFile" : "target-projects_ray-Debug-435ebb35886eb992308e.json", "name" : "projects_ray", "projectIndex" : 0 }, diff --git a/cmake-build-debug/.cmake/api/v1/reply/index-2023-12-08T18-02-24-0883.json b/cmake-build-debug/.cmake/api/v1/reply/index-2023-12-08T18-39-18-0017.json index d1fbb20..752320c 100644 --- a/cmake-build-debug/.cmake/api/v1/reply/index-2023-12-08T18-02-24-0883.json +++ b/cmake-build-debug/.cmake/api/v1/reply/index-2023-12-08T18-39-18-0017.json @@ -26,7 +26,7 @@ "objects" : [ { - "jsonFile" : "codemodel-v2-bacf5e2e80ef1d2e1af1.json", + "jsonFile" : "codemodel-v2-d8c16986ac54f14e6ad2.json", "kind" : "codemodel", "version" : { @@ -86,7 +86,7 @@ }, "codemodel-v2" : { - "jsonFile" : "codemodel-v2-bacf5e2e80ef1d2e1af1.json", + "jsonFile" : "codemodel-v2-d8c16986ac54f14e6ad2.json", "kind" : "codemodel", "version" : { diff --git a/cmake-build-debug/.cmake/api/v1/reply/target-projects_ray-Debug-81d0b664d25bd1619433.json b/cmake-build-debug/.cmake/api/v1/reply/target-projects_ray-Debug-435ebb35886eb992308e.json index fe0f381..3ae76e6 100644 --- a/cmake-build-debug/.cmake/api/v1/reply/target-projects_ray-Debug-81d0b664d25bd1619433.json +++ b/cmake-build-debug/.cmake/api/v1/reply/target-projects_ray-Debug-435ebb35886eb992308e.json @@ -534,11 +534,11 @@ "dependencies" : [ { - "backtrace" : 0, - "id" : "projects_ray_autogen::@6890427a1f51a3e7e1df" + "id" : "projects_ray_autogen_timestamp_deps::@6890427a1f51a3e7e1df" }, { - "id" : "projects_ray_autogen_timestamp_deps::@6890427a1f51a3e7e1df" + "backtrace" : 0, + "id" : "projects_ray_autogen::@6890427a1f51a3e7e1df" } ], "id" : "projects_ray::@6890427a1f51a3e7e1df", @@ -922,7 +922,7 @@ }, { "backtrace" : 1, - "path" : "src/4dvecops/transform4d.h", + "path" : "src/4dvecops/vec4ops.h", "sourceGroupIndex" : 1 }, { diff --git a/cmake-build-debug/CMakeFiles/projects_ray_autogen.dir/AutogenInfo.json b/cmake-build-debug/CMakeFiles/projects_ray_autogen.dir/AutogenInfo.json index bf8fbd3..9acceb5 100644 --- a/cmake-build-debug/CMakeFiles/projects_ray_autogen.dir/AutogenInfo.json +++ b/cmake-build-debug/CMakeFiles/projects_ray_autogen.dir/AutogenInfo.json @@ -392,9 +392,9 @@ "HEADERS" : [ [ - "/Users/sotech117/Documents/master/graphics/the-all-americans-in-cs1230/src/4dvecops/transform4d.h", + "/Users/sotech117/Documents/master/graphics/the-all-americans-in-cs1230/src/4dvecops/vec4ops.h", "MU", - "SDN2X6DTVW/moc_transform4d.cpp", + "SDN2X6DTVW/moc_vec4ops.cpp", null ], [ diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log index b8aa3dd..0c30d59 100644 --- a/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Dec 08 13:02 EST +Start testing: Dec 08 13:39 EST ---------------------------------------------------------- -End testing: Dec 08 13:02 EST +End testing: Dec 08 13:39 EST diff --git a/cmake-build-debug/build.ninja b/cmake-build-debug/build.ninja index 5304fab..85377a1 100644 --- a/cmake-build-debug/build.ninja +++ b/cmake-build-debug/build.ninja @@ -358,7 +358,7 @@ build projects_ray_autogen/timestamp projects_ray_autogen/mocs_compilation.cpp | ############################################# # Phony custom command for CMakeFiles/projects_ray_autogen_timestamp_deps -build CMakeFiles/projects_ray_autogen_timestamp_deps | ${cmake_ninja_workdir}CMakeFiles/projects_ray_autogen_timestamp_deps: phony /Users/sotech117/Qt/6.5.2/macos/./libexec/uic /Users/sotech117/Qt/6.5.2/macos/./libexec/moc +build CMakeFiles/projects_ray_autogen_timestamp_deps | ${cmake_ninja_workdir}CMakeFiles/projects_ray_autogen_timestamp_deps: phony /Users/sotech117/Qt/6.5.2/macos/./libexec/moc /Users/sotech117/Qt/6.5.2/macos/./libexec/uic ############################################# 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); }; |