summaryrefslogtreecommitdiff
path: root/gfx/gl/transform.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-17 19:36:30 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-01-17 22:16:48 +0000
commit0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c (patch)
tree68a80976a247836bbb1eecc835af437e3489fbb7 /gfx/gl/transform.cpp
parentFirst cut modernizing and sanitizing (diff)
downloadilt-0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c.tar.bz2
ilt-0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c.tar.xz
ilt-0bf4ad9e4a9e1c97e92aa23a365405dfef89bd7c.zip
Big reshuffle
Fixes code quality warnings now picked up.
Diffstat (limited to 'gfx/gl/transform.cpp')
-rw-r--r--gfx/gl/transform.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/gfx/gl/transform.cpp b/gfx/gl/transform.cpp
new file mode 100644
index 0000000..7b256af
--- /dev/null
+++ b/gfx/gl/transform.cpp
@@ -0,0 +1,27 @@
+#include "transform.h"
+#include "camera.h"
+#include <glm/gtx/transform.hpp>
+
+Transform::Transform(glm::vec3 pos, glm::vec3 rot, glm::vec3 scale) : pos {pos}, rot {rot}, scale {scale} { }
+
+glm::mat4
+Transform::GetModel() const
+{
+ const auto posMat = glm::translate(pos);
+ const auto scaleMat = glm::scale(scale);
+ const auto rotX = glm::rotate(rot.x, glm::vec3(1.0, 0.0, 0.0));
+ const auto rotY = glm::rotate(rot.y, glm::vec3(0.0, 1.0, 0.0));
+ const auto rotZ = glm::rotate(rot.z, glm::vec3(0.0, 0.0, 1.0));
+ const auto rotMat = rotX * rotY * rotZ;
+
+ return posMat * rotMat * scaleMat;
+}
+
+glm::mat4
+Transform::GetMVP(const Camera & camera) const
+{
+ const auto VP = camera.GetViewProjection();
+ const auto M = GetModel();
+
+ return VP * M;
+}