couch/core/Transform.cpp

65 lines
1.7 KiB
C++
Raw Permalink Normal View History

2021-01-26 23:28:20 -06:00
/*
Dane Johnson <dane@danejohnson.org>
LICENSE
Couch Copyright (C) 2021 Dane Johnson
This program comes with ABSOLUTELY NO WARRANTY; without event the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for details at
https://www.gnu.org/licenses/gpl-3.0.html
This is free software, and you are welcome to redistribute it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
DESCRIPTION
A transform represents various aspects of 3d space.
*/
2021-01-13 10:42:57 -06:00
#include "Transform.h"
2021-01-26 23:28:20 -06:00
#include <glm/gtc/matrix_transform.hpp>
2021-01-13 10:42:57 -06:00
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-26 23:28:20 -06:00
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));
2021-01-13 16:47:16 -06:00
}
2021-01-15 17:51:19 -06:00
2021-01-26 23:28:20 -06:00
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
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;
}