X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2Fviewport.cpp;h=6137eb2620d6f463445f45f80091088f62beb5ea;hb=dd8b3145a03ed676b0ae6311c29fc3d68f666b15;hp=636f3c35c1015f9cc9612ef9d62c4f592d740692;hpb=76b630bd0a147bf7c78d3380237c86b9bfc48530;p=blobs.git diff --git a/src/graphics/viewport.cpp b/src/graphics/viewport.cpp index 636f3c3..6137eb2 100644 --- a/src/graphics/viewport.cpp +++ b/src/graphics/viewport.cpp @@ -1,11 +1,15 @@ #include "Camera.hpp" #include "Viewport.hpp" -#include "../const.hpp" +#include "../creature/Creature.hpp" +#include "../math/const.hpp" #include "../world/Body.hpp" +#include "../world/Planet.hpp" #include #include +#include +#include #include @@ -66,8 +70,7 @@ Camera &Camera::FirstPerson(int srf, const glm::vec3 &pos, const glm::vec3 &at) position[(srf + 1) % 3] = pos.y; position[(srf + 2) % 3] = dir * (pos.z + Reference().Radius()); - glm::vec3 up(0.0f); - up[(srf + 2) % 3] = dir; + glm::vec3 up(world::Planet::SurfaceNormal(srf)); glm::vec3 target; target[(srf + 0) % 3] = at.x; @@ -84,20 +87,15 @@ Camera &Camera::MapView(int srf, const glm::vec3 &pos, float roll) noexcept { float dir = srf < 3 ? 1.0f : -1.0f; - glm::vec3 position; - position[(srf + 0) % 3] = pos.x; - position[(srf + 1) % 3] = pos.y; - position[(srf + 2) % 3] = dir * (pos.z + Reference().Radius()); - glm::vec3 up(0.0f); - up[(srf + 0) % 3] = std::cos(roll); - up[(srf + 1) % 3] = std::sin(roll); + up[(srf + 0) % 3] = std::sin(roll); + up[(srf + 1) % 3] = std::cos(roll); up[(srf + 2) % 3] = 0.0f; - glm::vec3 target = position; + glm::vec3 target = pos; target[(srf + 2) % 3] -= dir; - view = glm::lookAt(position, target, up); + view = glm::lookAt(pos, target, up); return *this; } @@ -108,6 +106,44 @@ Camera &Camera::Orbital(const glm::vec3 &pos) noexcept { return *this; } +Camera &Camera::TopDown(const creature::Creature &c, double distance, double roll) { + const creature::Situation &s = c.GetSituation(); + if (s.OnSurface()) { + int srf = s.Surface(); + glm::vec3 pos(s.Position() + (world::Planet::SurfaceNormal(srf) * distance)); + Reference(s.GetPlanet()); + return MapView(srf, pos, roll); + } else { + glm::vec3 pos(s.Position()); + pos += glm::normalize(pos) * float(distance); + return Orbital(pos); + } +} + +Camera &Camera::Radial(const creature::Creature &c, double distance, const glm::dvec3 &angle) { + const creature::Situation &s = c.GetSituation(); + glm::dvec3 pos(s.Position()); + glm::dvec3 up(0.0); + glm::dvec3 dir(0.0, 0.0, -distance); + if (s.OnSurface()) { + Reference(s.GetPlanet()); + track_orient = true; + int srf = s.Surface(); + up = world::Planet::SurfaceNormal(srf); + dir = + world::Planet::SurfaceOrientation(srf) + * glm::dmat3(glm::eulerAngleYX(angle.y, -angle.x)) + * dir; + } else { + up.y = 1.0; + dir = glm::dmat3(glm::eulerAngleYX(angle.y, -angle.x)) * dir; + } + pos += up * (c.Size() * 0.5); + up = glm::rotate(up, angle.z, glm::normalize(-dir)); + view = glm::lookAt(pos - dir, pos, up); + return *this; +} + glm::mat4 Camera::Model(const world::Body &b) const noexcept { if (&b == ref) { return track_orient ? glm::mat4(1.0f) : glm::mat4(ref->LocalTransform());