}
void MasterState::OnRender(graphics::Viewport &viewport) {
+ if (cp.Shown()) {
+ cam.TopDown(cp.GetCreature(), 10.0f);
+ assets.shaders.planet_surface.Activate();
+ assets.shaders.planet_surface.SetV(cam.View());
+ assets.shaders.sun_surface.Activate();
+ assets.shaders.sun_surface.SetV(cam.View());
+ assets.shaders.creature_skin.Activate();
+ assets.shaders.creature_skin.SetV(cam.View());
+ }
+
int num_lights = 0;
for (auto sun : sim.Suns()) {
// TODO: source sun's light color and strength
// sunset
//.FirstPerson(3, glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(1.0f, -0.75f, 0.1f))
// from afar
- .MapView(0, glm::vec3(0.0f, 0.0f, 15.0f), 0.0f)
+ .MapView(0, glm::vec3(0.0f, 0.0f, 30.0f), 0.0f)
// from afar, rotating
//.Orbital(glm::vec3(-60.0f, 0.0f, 0.0f))
;
namespace blobs {
+namespace creature {
+ class Creature;
+}
namespace world {
class Body;
}
Camera &MapView(int surface, const glm::vec3 &pos, float roll = 0.0f) noexcept;
/// look at center, position relative to orbital reference plane for children
Camera &Orbital(const glm::vec3 &pos) noexcept;
+ /// look at creature from above
+ Camera &TopDown(const creature::Creature &, float distance, float roll = 0.0f);
const glm::mat4 &Projection() const noexcept { return projection; }
const glm::mat4 &View() const noexcept { return view; }
void Activate() noexcept;
void SetM(const glm::mat4 &m) noexcept;
+ void SetV(const glm::mat4 &v) noexcept;
void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
void SetTexture(ArrayTexture &) noexcept;
void Activate() noexcept;
void SetM(const glm::mat4 &m) noexcept;
+ void SetV(const glm::mat4 &v) noexcept;
void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
void SetNormal(const glm::vec3 &) noexcept;
void Activate() noexcept;
void SetM(const glm::mat4 &m) noexcept;
+ void SetV(const glm::mat4 &v) noexcept;
void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
void SetLight(const glm::vec3 &color, float strength) noexcept;
prog.Uniform(mvp_handle, mvp);
}
+void PlanetSurface::SetV(const glm::mat4 &vv) noexcept {
+ v = vv;
+ mv = v * m;
+ mvp = p * mv;
+ prog.Uniform(mv_handle, mv);
+ prog.Uniform(mvp_handle, mvp);
+}
+
void PlanetSurface::SetVP(const glm::mat4 &vv, const glm::mat4 &pp) noexcept {
v = vv;
p = pp;
prog.Uniform(mvp_handle, mvp);
}
+void SunSurface::SetV(const glm::mat4 &vv) noexcept {
+ v = vv;
+ mv = v * m;
+ mvp = p * mv;
+ prog.Uniform(mv_handle, mv);
+ prog.Uniform(mvp_handle, mvp);
+}
+
void SunSurface::SetVP(const glm::mat4 &vv, const glm::mat4 &pp) noexcept {
v = vv;
p = pp;
prog.Uniform(mvp_handle, mvp);
}
+void CreatureSkin::SetV(const glm::mat4 &vv) noexcept {
+ v = vv;
+ mv = v * m;
+ mvp = p * mv;
+ prog.Uniform(mv_handle, mv);
+ prog.Uniform(mvp_handle, mvp);
+}
+
void CreatureSkin::SetVP(const glm::mat4 &vv, const glm::mat4 &pp) noexcept {
v = vv;
p = pp;
#include "Camera.hpp"
#include "Viewport.hpp"
+#include "../creature/Creature.hpp"
#include "../math/const.hpp"
#include "../world/Body.hpp"
+#include "../world/Planet.hpp"
#include <cmath>
#include <GL/glew.h>
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;
}
+Camera &Camera::TopDown(const creature::Creature &c, float distance, float roll) {
+ const creature::Situation &s = c.GetSituation();
+ if (s.OnPlanet()) {
+ int srf = s.Surface();
+ glm::vec3 pos(s.Position());
+ pos[(srf + 2) % 3] += srf < 3 ? distance : -distance;
+ Reference(s.GetPlanet());
+ return MapView(srf, pos, roll);
+ } else {
+ glm::vec3 pos(s.Position());
+ pos += glm::normalize(pos) * distance;
+ return Orbital(pos);
+ }
+}
+
Camera &Camera::Orbital(const glm::vec3 &pos) noexcept {
track_orient = false;
view = glm::lookAt(pos, glm::vec3(0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
void Show(creature::Creature &);
void Hide() noexcept;
+ bool Shown() const noexcept { return c; }
+ const creature::Creature &GetCreature() const noexcept { return *c; }
+
void Draw(app::Assets &, graphics::Viewport &) noexcept;
private: