X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcreature%2FSituation.hpp;h=3c4a28a567ef4877b09ad68c94575c12545179cf;hb=b4deadd9f4e399207e2530ea39a447c0d9d260a3;hp=12b7490914783c6aac2bb9219d0bcd2f2f9c9c82;hpb=8a3907bb0bed257bf5d6f40f39f15114e8345913;p=blobs.git diff --git a/src/creature/Situation.hpp b/src/creature/Situation.hpp index 12b7490..3c4a28a 100644 --- a/src/creature/Situation.hpp +++ b/src/creature/Situation.hpp @@ -1,7 +1,7 @@ #ifndef BLOBS_CREATURE_SITUATION_HPP_ #define BLOBS_CREATURE_SITUATION_HPP_ -#include "../graphics/glm.hpp" +#include "../math/glm.hpp" namespace blobs { @@ -14,25 +14,69 @@ namespace creature { class Situation { +public: + struct State { + // position + glm::dvec3 pos; + // velocity + glm::dvec3 vel; + // face direction, normalized + glm::dvec3 dir; + State( + const glm::dvec3 &pos = glm::dvec3(0.0), + const glm::dvec3 &vel = glm::dvec3(0.0), + const glm::dvec3 &dir = glm::dvec3(0.0, 0.0, -1.0)) + : pos(pos), vel(vel), dir(dir) { } + }; + struct Derivative { + // velocity + glm::dvec3 vel; + // acceleration + glm::dvec3 acc; + Derivative( + const glm::dvec3 &vel = glm::dvec3(0.0), + const glm::dvec3 &acc = glm::dvec3(0.0)) + : vel(vel), acc(acc) { } + }; + public: Situation(); ~Situation(); + Situation(const Situation &) = delete; + Situation &operator =(const Situation &) = delete; + + Situation(Situation &&) = delete; + Situation &operator =(Situation &&) = delete; + public: bool OnPlanet() const noexcept; world::Planet &GetPlanet() const noexcept { return *planet; } bool OnSurface() const noexcept; int Surface() const noexcept { return surface; } - const glm::dvec3 &Position() const noexcept { return position; } + const glm::dvec3 &Position() const noexcept { return state.pos; } + bool OnTile() const noexcept; + glm::ivec2 SurfacePosition() const noexcept; world::Tile &GetTile() const noexcept; const world::TileType &GetTileType() const noexcept; + void SetState(const State &s) noexcept { state = s; } + const State &GetState() const noexcept { return state; } + + const glm::dvec3 &Velocity() const noexcept { return state.vel; } + bool Moving() const noexcept { return glm::length2(state.vel) > 0.0000001; } void Move(const glm::dvec3 &dp) noexcept; + void Accelerate(const glm::dvec3 &dv) noexcept; + void EnforceConstraints(State &) noexcept; + + void Heading(const glm::dvec3 &h) noexcept { state.dir = h; } + const glm::dvec3 &Heading() const noexcept { return state.dir; } + void SetPlanetSurface(world::Planet &, int srf, const glm::dvec3 &pos) noexcept; public: world::Planet *planet; - glm::dvec3 position; + State state; int surface; enum { LOST,