feat: assignment 2
This commit is contained in:
35
src/model.cpp
Normal file
35
src/model.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user