feat: assignment 2

This commit is contained in:
2025-10-13 15:04:53 +02:00
parent 986e31dbef
commit f981cee4e0
17 changed files with 649 additions and 56 deletions

35
src/model.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "model.h"
#include "mesh.h"
#include "state.h"
#include "../lib/glm/gtc/matrix_transform.hpp"
Model::Model(const std::shared_ptr<Mesh>& mesh)
: mesh_(mesh)
{
}
void Model::draw()
{
if (!mesh_)
return;
// Build model matrix: Translation * Rotation * Scale
glm::mat4 model = glm::mat4(1.0f);
// Translation
model = glm::translate(model, position_);
// Rotation (applying X, Y, Z rotations)
model = glm::rotate(model, rotation_.x, glm::vec3(1.0f, 0.0f, 0.0f));
model = glm::rotate(model, rotation_.y, glm::vec3(0.0f, 1.0f, 0.0f));
model = glm::rotate(model, rotation_.z, glm::vec3(0.0f, 0.0f, 1.0f));
// Scale
model = glm::scale(model, scale_);
// Set the model matrix in State
State::modelMatrix = model;
// Draw the mesh
mesh_->draw();
}