83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#ifndef OBJECT_H
|
|
#define OBJECT_H
|
|
|
|
#include "pch.hpp"
|
|
|
|
#include "extratools.h"
|
|
|
|
#include "utils/Renderer/RenderTarget.h"
|
|
|
|
namespace Archimedes {
|
|
|
|
class Object {
|
|
|
|
public:
|
|
|
|
Object(glm::mat4 t)
|
|
: worldTransform(t) {}
|
|
|
|
~Object() {};
|
|
|
|
///scales an object absolutely
|
|
///scale factors less than zero do nothing
|
|
float scaleTo(float s) {
|
|
if(s > 0) {
|
|
worldTransform = glm::scale(worldTransform, glm::vec3(s / scale));
|
|
scale = s;
|
|
}
|
|
|
|
return scale;
|
|
}
|
|
|
|
float scaleRel(float s) {
|
|
return scaleTo(scale * s);
|
|
}
|
|
|
|
float scaleAdd(float s) {
|
|
return scaleTo(scale + s);
|
|
}
|
|
|
|
glm::vec3 moveTo(glm::vec3 pos) {
|
|
worldTransform = glm::translate(worldTransform, pos - position);
|
|
position = pos;
|
|
|
|
return position;
|
|
}
|
|
|
|
glm::vec3 moveRel(glm::vec3 pos) {
|
|
return moveTo(pos + position);
|
|
}
|
|
|
|
glm::vec3 rotateTo(glm::vec3 angles) {
|
|
worldTransform = glm::rotate(worldTransform, angles.x - rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
|
|
worldTransform = glm::rotate(worldTransform, angles.y - rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
worldTransform = glm::rotate(worldTransform, angles.z - rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
|
|
rotation = angles;
|
|
|
|
return rotation;
|
|
}
|
|
|
|
glm::vec3 rotateRel(glm::vec3 angles) {
|
|
return rotateTo(angles + rotation);
|
|
}
|
|
|
|
glm::vec3& getPosition() { return position; }
|
|
glm::vec3& getRotation() { return rotation; }
|
|
float& getScale() { return scale; }
|
|
|
|
const glm::mat4& getTransform() { return worldTransform; }
|
|
void setTransform(const glm::mat4 m) { worldTransform = m; }
|
|
|
|
private:
|
|
|
|
glm::vec3 position = glm::vec3(0);
|
|
glm::vec3 rotation = glm::vec3(0);
|
|
float scale = 1.0f;
|
|
|
|
glm::mat4 worldTransform = glm::mat4(1.0f);
|
|
|
|
};
|
|
}
|
|
|
|
#endif
|