diff options
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/followCameraController.cpp | 2 | ||||
-rw-r--r-- | gfx/gl/camera.cpp | 42 | ||||
-rw-r--r-- | gfx/gl/camera.h | 6 | ||||
-rw-r--r-- | gfx/gl/shaders/landmassShader.vs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/waterShader.vs | 6 | ||||
-rw-r--r-- | gfx/manualCameraController.cpp | 2 | ||||
-rw-r--r-- | gfx/models/obj.h | 12 | ||||
-rw-r--r-- | gfx/models/obj.impl.cpp | 13 |
8 files changed, 23 insertions, 62 deletions
diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp index 9e32e21..42d1666 100644 --- a/gfx/followCameraController.cpp +++ b/gfx/followCameraController.cpp @@ -32,7 +32,7 @@ FollowCameraController::updateCamera(Camera * camera) const case Mode::ISO: camera->pos = pos + ((up + north + east) * 40.F); - camera->forward = -glm::normalize(up + north + east); + camera->forward = glm::normalize(down + south + west); camera->up = glm::normalize(up - north - east); break; } diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index c98ff70..c957b2c 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -1,9 +1,9 @@ #include "camera.h" #include <glm/gtx/transform.hpp> +#include <maths.h> Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) : - pos {pos}, forward {0.0F, 0.0F, 1.0F}, up {0.0F, 1.0F, 0.0F}, projection { - glm::perspective(fov, aspect, zNear, zFar)} + pos {pos}, forward {::north}, up {::up}, projection {glm::perspective(fov, aspect, zNear, zFar)} { } @@ -12,41 +12,3 @@ Camera::GetViewProjection() const { return projection * glm::lookAt(pos, pos + forward, up); } - -void -Camera::MoveForward(float amt) -{ - pos += forward * amt; -} - -void -Camera::SlideForward(float amt) -{ - pos += forward * amt * glm::vec3 {1, 0, 1}; -} - -void -Camera::MoveRight(float amt) -{ - pos += glm::cross(up, forward) * amt; -} - -void -Camera::Pitch(float angle) -{ - const auto right = glm::normalize(glm::cross(up, forward)); - - forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0))); - up = glm::normalize(glm::cross(forward, right)); -} - -void -Camera::RotateY(float angle) -{ - static constexpr glm::vec3 UP {0.0F, 1.0F, 0.0F}; - - const auto rotation = glm::rotate(angle, UP); - - forward = glm::vec3(glm::normalize(rotation * glm::vec4(forward, 0.0))); - up = glm::vec3(glm::normalize(rotation * glm::vec4(up, 0.0))); -} diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h index 3d8ece4..72f699d 100644 --- a/gfx/gl/camera.h +++ b/gfx/gl/camera.h @@ -9,12 +9,6 @@ public: [[nodiscard]] glm::mat4 GetViewProjection() const;
- void MoveForward(float amt);
- void SlideForward(float amt);
- void MoveRight(float amt);
- void Pitch(float angle);
- void RotateY(float angle);
-
glm::vec3 pos;
glm::vec3 forward;
glm::vec3 up;
diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs index 44eed39..94d819d 100644 --- a/gfx/gl/shaders/landmassShader.vs +++ b/gfx/gl/shaders/landmassShader.vs @@ -15,5 +15,5 @@ void main() gl_Position = viewProjection * vec4(position, 1.0); texCoord0 = texCoord; normal0 = normal; - height = position.y; + height = position.z; } diff --git a/gfx/gl/shaders/waterShader.vs b/gfx/gl/shaders/waterShader.vs index 7a641b0..2bcedb4 100644 --- a/gfx/gl/shaders/waterShader.vs +++ b/gfx/gl/shaders/waterShader.vs @@ -14,9 +14,9 @@ void main() { vec3 wpos = vec3( position.x + cos(waves.x), - cos(waves.x + position.x + (position.z / 8)) * .3, - position.z + cos(waves.x * waves.z / 2)); + position.y + cos(waves.x * waves.y / 2), + cos(waves.x + position.x + (position.y / 8)) * .3); gl_Position = viewProjection * vec4(wpos, 1.0); texCoord0 = texCoord; - depth = position.y; + depth = position.z; } diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp index 268920a..022fb72 100644 --- a/gfx/manualCameraController.cpp +++ b/gfx/manualCameraController.cpp @@ -47,7 +47,7 @@ ManualCameraController::handleInput(SDL_Event & e) pitch = std::clamp(pitch - 0.01F * (float)e.motion.yrel, 0.1F, half_pi); } else { - focus += rotate_flat(-direction) * glm::vec2 {e.motion.xrel, e.motion.yrel}; + focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel}; } } return true; diff --git a/gfx/models/obj.h b/gfx/models/obj.h index a2d874f..9a2a30e 100644 --- a/gfx/models/obj.h +++ b/gfx/models/obj.h @@ -17,16 +17,8 @@ class Vertex; class ObjParser : yyFlexLexer { public: - explicit ObjParser(const std::filesystem::path & fileName) : ObjParser {std::make_unique<std::ifstream>(fileName)} - { - } - - explicit ObjParser(std::unique_ptr<std::istream> in) : yyFlexLexer(in.get()) - { - assert(in); - ObjParser::yylex(); - assert(in->good()); - } + explicit ObjParser(const std::filesystem::path & fileName); + explicit ObjParser(std::unique_ptr<std::istream> in); int yylex() override; diff --git a/gfx/models/obj.impl.cpp b/gfx/models/obj.impl.cpp index 330e851..0701d13 100644 --- a/gfx/models/obj.impl.cpp +++ b/gfx/models/obj.impl.cpp @@ -9,6 +9,19 @@ #include <utility> #include <vector> +ObjParser::ObjParser(const std::filesystem::path & fileName) : ObjParser {std::make_unique<std::ifstream>(fileName)} { } + +ObjParser::ObjParser(std::unique_ptr<std::istream> in) : yyFlexLexer(in.get()) +{ + assert(in); + ObjParser::yylex(); + assert(in->good()); + std::for_each(vertices.begin(), vertices.end(), [](auto & v) { + std::swap(v.y, v.z); + v.x = -v.x; + }); +} + ObjParser::NamedMeshes ObjParser::createMeshes() const { |