postponing implementing CompoundShapes

This commit is contained in:
2026-02-05 18:42:41 +02:00
parent ed09c14f93
commit 4b6d71eb4a
3 changed files with 13 additions and 12 deletions

View File

@@ -1,3 +1,6 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "CompoundShape.hpp" #include "CompoundShape.hpp"
// constructors // constructors
@@ -16,9 +19,12 @@ CompoundShape::CompoundShape(const std::vector<Shape> shapes)
void CompoundShape::draw() { void CompoundShape::draw() {
for (auto& shape : this->shapes) { for (auto& shape : this->shapes) {
glm::mat4 orig_transform { shape.transform }; glm::mat4 orig_transform { shape.transform };
shape.transform *= shape.transform; shape.transform = glm::rotate(shape.transform, glm::radians(90.0f), glm::vec3 { 0.0f, 0.0f, 1.0f });
shape.draw(); shape.draw();
shape.transform = orig_transform; shape.transform = orig_transform;
} }
} }
void CompoundShape::rotate(const float rotation_rad, const glm::vec3& axis) {
this->transform = glm::rotate(this->transform, rotation_rad, axis);
}

View File

@@ -10,7 +10,7 @@ public:
CompoundShape(const std::vector<Shape> shapes); CompoundShape(const std::vector<Shape> shapes);
void draw() const; void draw();
void reset_transform(); void reset_transform();
void translate(const glm::vec3& translation); void translate(const glm::vec3& translation);
void rotate(const float rotation_rad, const glm::vec3& axis); void rotate(const float rotation_rad, const glm::vec3& axis);

View File

@@ -3,7 +3,6 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include <cstdlib>
#include "glad/glad.h" #include "glad/glad.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@@ -15,7 +14,6 @@
#include "Camera.hpp" #include "Camera.hpp"
#include "Shader.hpp" #include "Shader.hpp"
#include "Shape.hpp" #include "Shape.hpp"
#include "CompoundShape.hpp"
#include "quit.hpp" #include "quit.hpp"
#include "settings.hpp" #include "settings.hpp"
@@ -184,12 +182,8 @@ int main() {
plane.rotate(glm::radians(90.0f), glm::vec3 { 1.0f, 0.0f, 0.0f }); plane.rotate(glm::radians(90.0f), glm::vec3 { 1.0f, 0.0f, 0.0f });
plane.scale(glm::vec3 { 1.0f } * 100.0f); plane.scale(glm::vec3 { 1.0f } * 100.0f);
Shape tri1 { shader, shapes.at("triangle") }; Shape cube { shader, shapes.at("cube") };
Shape tri2 { shader, shapes.at("triangle") }; cube.init();
tri2.rotate(glm::radians(180.0f), glm::vec3 { 0.0f, 0.0f, 1.0f });
CompoundShape rectangle { {
tri1, tri2
} };
long unsigned int frame { 0 }; long unsigned int frame { 0 };
double last_frame_time { 0 }; double last_frame_time { 0 };
@@ -227,8 +221,9 @@ int main() {
shader->set_vec4("color", glm::normalize(glm::vec4 { 207.0f, 90.0f, 28.0f, 1.0f })); shader->set_vec4("color", glm::normalize(glm::vec4 { 207.0f, 90.0f, 28.0f, 1.0f }));
plane.draw(); plane.draw();
shader->set_vec4("color", glm::vec4 { 0.0f, 0.0f, 0.0f, 1.0f }); shader->set_vec4("color", glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f });
rectangle.draw(); cube.rotate(glm::radians(1.0f), glm::vec3 { 0.0f, 1.0f, 0.0f });
cube.draw();
const double time_since_last_frame { glfwGetTime() - last_frame_time }; const double time_since_last_frame { glfwGetTime() - last_frame_time };
if (time_since_last_frame < fps_lock) { if (time_since_last_frame < fps_lock) {