90 lines
1.7 KiB
C++
90 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <queue>
|
|
#include "IDrawable.h"
|
|
|
|
enum Transformation
|
|
{
|
|
Rotation,
|
|
Translation,
|
|
Scaling
|
|
};
|
|
|
|
class ADrawable : IDrawable {
|
|
protected:
|
|
std::vector<std::pair<glm::vec4, Transformation>> _transformations;
|
|
Model _model;
|
|
|
|
void effectTransformations()
|
|
{
|
|
for (auto pair : _transformations)
|
|
{
|
|
switch (pair.second)
|
|
{
|
|
case(Rotation):
|
|
_model.glRotate(pair.first.w, pair.first.x, pair.first.y, pair.first.z);
|
|
break;
|
|
case(Translation):
|
|
_model.glTranslate(pair.first.x, pair.first.y, pair.first.z);
|
|
break;
|
|
case(Scaling):
|
|
_model.glScale(pair.first.x, pair.first.y, pair.first.z);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public:
|
|
|
|
virtual void draw(ShaderProgram *shader, glm::mat4x4 proj_matrix, glm::mat4x4 view_matrix) = 0;
|
|
virtual DrawableType getType() = 0;
|
|
|
|
void addRotation(glm::vec4 vec) override
|
|
{
|
|
_transformations.emplace_back(vec, Rotation);
|
|
}
|
|
|
|
void addTranslation(glm::vec4 vec) override
|
|
{
|
|
_transformations.emplace_back(vec, Translation);
|
|
}
|
|
|
|
void addScaling(glm::vec4 vec) override
|
|
{
|
|
_transformations.emplace_back(vec, Scaling);
|
|
}
|
|
|
|
glm::vec4 translateToPivot(glm::vec3 pivot) override
|
|
{
|
|
glm::vec4 curr_pos = { 0, 0, 0, 0 };
|
|
glm::vec4 h_pivot = { pivot.x, pivot.y, pivot.z, 0 };
|
|
|
|
for (auto pair : _transformations)
|
|
{
|
|
if (pair.second == Translation)
|
|
curr_pos += pair.first;
|
|
}
|
|
addTranslation(h_pivot - curr_pos);
|
|
return curr_pos - h_pivot;
|
|
}
|
|
|
|
void removeLastTransformations(int n = 1) override
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
_transformations.pop_back();
|
|
}
|
|
|
|
glm::vec3 getPosition() override
|
|
{
|
|
glm::vec4 curr_pos = { 0, 0, 0, 0 };
|
|
|
|
for (auto pair : _transformations)
|
|
{
|
|
if (pair.second == Translation)
|
|
curr_pos += pair.first;
|
|
}
|
|
|
|
return curr_pos;
|
|
}
|
|
|
|
}; |