couch/core/Transform.cpp

48 lines
1.2 KiB
C++
Raw Normal View History

2021-01-13 10:42:57 -06:00
#include "Transform.h"
Transform::Transform() {
position = Vector3(0.0f);
2021-01-14 11:52:01 -06:00
rotation = Vector3(0.0f);
2021-01-20 17:18:39 -06:00
scale = Vector3(1.0f, 1.0f, 1.0f);
2021-01-13 10:42:57 -06:00
}
2021-01-13 20:08:39 -06:00
Transform::Transform(Vector3 position, Vector3 rotation) {
2021-01-13 10:42:57 -06:00
this->position = position;
2021-01-13 20:08:39 -06:00
this->rotation = rotation;
2021-01-20 17:18:39 -06:00
this->scale = Vector3(1.0f, 1.0f, 1.0f);
2021-01-13 10:42:57 -06:00
}
2021-01-13 16:47:16 -06:00
2021-01-20 17:18:39 -06:00
Transform::Transform(Vector3 position, Vector3 rotation, Vector3 scale) {
this->position = position;
this->rotation = rotation;
this->scale = scale;
}
2021-01-13 16:47:16 -06:00
void Transform::Translate(cfloat x, cfloat y, cfloat z) {
position = position + Vector3(x, y, z);
}
2021-01-15 17:51:19 -06:00
2021-01-21 11:12:45 -06:00
Matrix Transform::RotationMatrix() {
2021-01-15 17:51:19 -06:00
Matrix mat(1.0f);
2021-01-20 22:17:33 -06:00
2021-01-15 17:51:19 -06:00
mat = glm::rotate(mat, this->rotation.z, Vector3(0.0f, 0.0f, 1.0f));
2021-01-20 22:17:33 -06:00
mat = glm::rotate(mat, this->rotation.y, Vector3(0.0f, 1.0f, 0.0f));
mat = glm::rotate(mat, this->rotation.x, Vector3(1.0f, 0.0f, 0.0f));
2021-01-21 11:12:45 -06:00
return mat;
}
Vector3 Transform::Forward() {
return glm::vec3(RotationMatrix() * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f));
}
Vector3 Transform::Up() {
return glm::vec3(RotationMatrix() * glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));
}
Vector3 Transform::Right() {
return glm::vec3(RotationMatrix() * glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
2021-01-15 17:51:19 -06:00
}