qt-scene-editor/FinalProject/renderable.cpp

46 lines
1.1 KiB
C++

#pragma once
#include <GLM/ext/matrix_transform.hpp>
#include "renderable.h"
Renderable::Renderable(Model* model) : _model(model) {}
Renderable::Renderable(Model* model, glm::vec3 position) : _model(model), _position(position) {}
void Renderable::move(glm::vec3 deltaVec) {
_position += deltaVec;
}
void Renderable::setPosition(glm::vec3 position) {
_position = position;
}
void Renderable::rotate(glm::vec3 axis, float deltaAngle) {
_rotation = glm::rotate(_rotation, deltaAngle, axis);
}
void Renderable::setRotation(glm::vec3 axis, float angle) {
_rotation = glm::rotate(glm::mat4(1.0f), angle, axis);
}
void Renderable::scale(float deltaScale) {
_scale += deltaScale;
}
void Renderable::setScale(float scale) {
_scale = glm::vec3(scale);
}
inline glm::mat4 Renderable::modelMatrix() const {
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, _position);
model = model * _rotation;
model = glm::scale(model, _scale);
return model;
}
void Renderable::render(ShaderProgram shader) {
_model->render(shader);
}