summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-03 00:08:47 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-03 00:08:47 +0000
commit94311f9c4e82b7475802b1934cc0c5b243e0cd2f (patch)
tree5ef23f6c1151917eb723b67c262da0168e42343c /gfx
parentOur own matrix rotations (diff)
downloadilt-94311f9c4e82b7475802b1934cc0c5b243e0cd2f.tar.bz2
ilt-94311f9c4e82b7475802b1934cc0c5b243e0cd2f.tar.xz
ilt-94311f9c4e82b7475802b1934cc0c5b243e0cd2f.zip
Replace Transform with Location
Simpler, unbinds the transformation matrices for location, now done just in the shader.
Diffstat (limited to 'gfx')
-rw-r--r--gfx/followCameraController.cpp4
-rw-r--r--gfx/gl/shader.cpp6
-rw-r--r--gfx/gl/shader.h4
-rw-r--r--gfx/gl/transform.cpp16
-rw-r--r--gfx/gl/transform.h53
5 files changed, 10 insertions, 73 deletions
diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp
index 25861b6..1ee385a 100644
--- a/gfx/followCameraController.cpp
+++ b/gfx/followCameraController.cpp
@@ -1,8 +1,8 @@
#include "followCameraController.h"
#include "game/vehicles/vehicle.h"
-#include "gfx/gl/transform.h"
#include <gfx/gl/camera.h>
#include <glm/glm.hpp>
+#include <location.hpp>
#include <maths.h>
#include <memory>
#include <tuple>
@@ -15,7 +15,7 @@ FollowCameraController::updateCamera(Camera * camera) const
{
const auto [pos, rot] = [this]() {
const auto t {target.lock()};
- return std::tie(t->location.GetPos(), t->location.GetRot());
+ return std::tie(t->location.pos, t->location.rot);
}();
switch (mode) {
diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp
index f30af5c..04d5ac6 100644
--- a/gfx/gl/shader.cpp
+++ b/gfx/gl/shader.cpp
@@ -8,6 +8,9 @@
#include <gfx/gl/shaders/vs-landmassShader.h>
#include <gfx/gl/shaders/vs-waterShader.h>
#include <glm/glm.hpp>
+#include <glm/gtx/transform.hpp>
+#include <location.hpp>
+#include <maths.h>
#include <stdexcept>
#include <string>
@@ -67,10 +70,11 @@ Shader::setUniform(const GLchar * uniform, glm::vec3 v) const
}
void
-Shader::setModel(glm::mat4 model, Program pid) const
+Shader::setModel(const Location & loc, Program pid) const
{
auto & prog = programs[(int)pid];
glUseProgram(prog.m_program);
+ const auto model {glm::translate(loc.pos) * rotate_ypr(loc.rot)};
glUniformMatrix4fv(prog.model_uniform, 1, GL_FALSE, &model[0][0]);
}
diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h
index e4904ed..f1fe705 100644
--- a/gfx/gl/shader.h
+++ b/gfx/gl/shader.h
@@ -7,6 +7,8 @@
#include <glm/glm.hpp>
#include <string_view>
+class Location;
+
class Shader {
public:
enum class Program { Basic = 0, Water = 1, LandMass = 2 };
@@ -14,7 +16,7 @@ public:
Shader();
void setView(glm::mat4 view) const;
- void setModel(glm::mat4 model, Program = Program::Basic) const;
+ void setModel(const Location &, Program = Program::Basic) const;
void setUniform(const GLchar *, glm::vec3 dir) const;
static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);
diff --git a/gfx/gl/transform.cpp b/gfx/gl/transform.cpp
deleted file mode 100644
index c7004ba..0000000
--- a/gfx/gl/transform.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "transform.h"
-#include <glm/gtx/transform.hpp>
-#include <maths.h>
-
-Transform::Transform(glm::vec3 pos, glm::vec3 rot) : pos {pos}, rot {rot} { }
-
-glm::mat4
-Transform::GetModel() const
-{
- const auto posMat = glm::translate(pos);
- const auto rotX = glm::rotate(rot.x, west);
- const auto rotY = glm::rotate(rot.y, up);
- const auto rotZ = glm::rotate(rot.z, north);
-
- return posMat * rotY * rotX * rotZ;
-}
diff --git a/gfx/gl/transform.h b/gfx/gl/transform.h
deleted file mode 100644
index 61b571d..0000000
--- a/gfx/gl/transform.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef TRANSFORM_INCLUDED_H
-#define TRANSFORM_INCLUDED_H
-
-#include <glm/glm.hpp>
-
-class Transform {
-public:
- explicit Transform(glm::vec3 pos = {}, glm::vec3 rot = {});
-
- [[nodiscard]] glm::mat4 GetModel() const;
-
- [[nodiscard]] inline glm::vec3 &
- GetPos()
- {
- return pos;
- }
-
- [[nodiscard]] inline const glm::vec3 &
- GetPos() const
- {
- return pos;
- }
-
- [[nodiscard]] inline glm::vec3 &
- GetRot()
- {
- return rot;
- }
-
- [[nodiscard]] inline const glm::vec3 &
- GetRot() const
- {
- return rot;
- }
-
- inline void
- SetPos(glm::vec3 && pos)
- {
- this->pos = pos;
- }
-
- inline void
- SetRot(glm::vec3 && rot)
- {
- this->rot = rot;
- }
-
-private:
- glm::vec3 pos;
- glm::vec3 rot;
-};
-
-#endif