couch/core/Transform.cpp

35 lines
916 B
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
Vector3 Transform::Forward() {
Vector3 forward(0.0f, 0.0f, -1.0f);
Matrix mat(1.0f);
mat = glm::rotate(mat, this->rotation.x, Vector3(1.0f, 0.0f, 0.0f));
mat = glm::rotate(mat, this->rotation.y, Vector3(0.0f, 1.0f, 0.0f));
mat = glm::rotate(mat, this->rotation.z, Vector3(0.0f, 0.0f, 1.0f));
return mat * glm::vec4(forward, 1.0f);
}