diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-16 18:09:15 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-16 18:09:15 +0000 |
commit | 400410fcd436d5e4310bfa779f0309c5fae5b2c2 (patch) | |
tree | 89661918c487e63b6c71f2e9281b553928010606 /transform.h | |
download | ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.tar.bz2 ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.tar.xz ilt-400410fcd436d5e4310bfa779f0309c5fae5b2c2.zip |
Initial commit
Stripped back and formatted from https://github.com/BennyQBD/ModernOpenGLTutorial/
Diffstat (limited to 'transform.h')
-rw-r--r-- | transform.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/transform.h b/transform.h new file mode 100644 index 0000000..ed9b703 --- /dev/null +++ b/transform.h @@ -0,0 +1,79 @@ +#ifndef TRANSFORM_INCLUDED_H
+#define TRANSFORM_INCLUDED_H
+
+#include "camera.h"
+#include <glm/glm.hpp>
+#include <glm/gtx/transform.hpp>
+
+struct Transform {
+public:
+ Transform(const glm::vec3 & pos = glm::vec3(), const glm::vec3 & rot = glm::vec3(),
+ const glm::vec3 & scale = glm::vec3(1.0f, 1.0f, 1.0f))
+ {
+ this->pos = pos;
+ this->rot = rot;
+ this->scale = scale;
+ }
+
+ inline glm::mat4
+ GetModel() const
+ {
+ glm::mat4 posMat = glm::translate(pos);
+ glm::mat4 scaleMat = glm::scale(scale);
+ glm::mat4 rotX = glm::rotate(rot.x, glm::vec3(1.0, 0.0, 0.0));
+ glm::mat4 rotY = glm::rotate(rot.y, glm::vec3(0.0, 1.0, 0.0));
+ glm::mat4 rotZ = glm::rotate(rot.z, glm::vec3(0.0, 0.0, 1.0));
+ glm::mat4 rotMat = rotX * rotY * rotZ;
+
+ return posMat * rotMat * scaleMat;
+ }
+
+ inline glm::mat4
+ GetMVP(const Camera & camera) const
+ {
+ glm::mat4 VP = camera.GetViewProjection();
+ glm::mat4 M = GetModel();
+
+ return VP * M; // camera.GetViewProjection() * GetModel();
+ }
+
+ inline glm::vec3 *
+ GetPos()
+ {
+ return &pos;
+ }
+ inline glm::vec3 *
+ GetRot()
+ {
+ return &rot;
+ }
+ inline glm::vec3 *
+ GetScale()
+ {
+ return &scale;
+ }
+
+ inline void
+ SetPos(glm::vec3 & pos)
+ {
+ this->pos = pos;
+ }
+ inline void
+ SetRot(glm::vec3 & rot)
+ {
+ this->rot = rot;
+ }
+ inline void
+ SetScale(glm::vec3 & scale)
+ {
+ this->scale = scale;
+ }
+
+protected:
+private:
+ glm::vec3 pos;
+ glm::vec3 rot;
+ glm::vec3 scale;
+};
+
+#endif
|