aboutsummaryrefslogtreecommitdiff
path: root/src/shared/movement.hh
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 18:05:18 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 18:05:18 +1100
commit1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (patch)
tree222dfcd07a1e40716127a347bbfd7119ce3d0984 /src/shared/movement.hh
initial commit
Diffstat (limited to 'src/shared/movement.hh')
-rw-r--r--src/shared/movement.hh67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/shared/movement.hh b/src/shared/movement.hh
new file mode 100644
index 0000000..375c030
--- /dev/null
+++ b/src/shared/movement.hh
@@ -0,0 +1,67 @@
+#ifndef SHARED_MOVEMENT_HH_
+#define SHARED_MOVEMENT_HH_
+
+#include "shared/math.hh"
+#include "shared/player.hh"
+#include "shared/shared.hh"
+#include "shared/world.hh"
+
+#include <algorithm>
+#include <array>
+
+#include <glm/glm.hpp>
+#include <glm/gtx/norm.hpp>
+
+namespace shared {
+namespace movement {
+
+struct aabb {
+ glm::vec3 min;
+ glm::vec3 max;
+};
+bool intersect_aabbs(const aabb& a, const aabb& b) noexcept;
+
+struct line {
+ glm::vec3 origin;
+ glm::vec3 dir;
+};
+struct ray_aabb_ret {
+ glm::vec3 position;
+ float time;
+ glm::vec3 normal;
+};
+std::optional<ray_aabb_ret> intersect_ray_aabb(const line& line,
+ const aabb& aabb) noexcept;
+struct moving_aabb {
+ struct aabb aabb;
+ glm::vec3 velocity;
+};
+struct moving_aabb_ret {
+ float time;
+ glm::vec3 normal;
+};
+std::optional<moving_aabb_ret>
+intersect_moving_aabbs(const moving_aabb& a, const moving_aabb& b) noexcept;
+
+// A block with a bit more info.
+struct blockinfo {
+ shared::world::block block;
+ struct aabb aabb;
+ shared::math::coords chunk_pos;
+ glm::ivec3 pos;
+};
+// /WE/ should use this function to generate our blockdatas.
+constexpr int move_width =
+ static_cast<int>(1.0f + 2 * shared::player::HALFWIDTH + 1.0f);
+constexpr int move_height = static_cast<int>(1.0f + shared::player::HEIGHT);
+
+// Walking a player is fairly complicated, and requires a std::vector of
+// blockdata that represents all the blocks near a player.
+// TODO provide an additional deltatime arugment to enable prediction.
+void move(shared::player& player, const std::vector<blockinfo>& blockinfos,
+ const float deltatime) noexcept;
+
+} // namespace movement
+} // namespace shared
+
+#endif