aboutsummaryrefslogtreecommitdiff
path: root/src/shared/movement/movement.hh
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
commite4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch)
treeed58c3c246e3af1af337697695d780aa31f6ad9a /src/shared/movement/movement.hh
parent1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff)
Update to most recent version (old initial commit)
Diffstat (limited to 'src/shared/movement/movement.hh')
-rw-r--r--src/shared/movement/movement.hh75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/shared/movement/movement.hh b/src/shared/movement/movement.hh
new file mode 100644
index 0000000..9c6e17d
--- /dev/null
+++ b/src/shared/movement/movement.hh
@@ -0,0 +1,75 @@
+#ifndef SHARED_MOVEMENT_MOVEMENT_HH_
+#define SHARED_MOVEMENT_MOVEMENT_HH_
+
+#include "shared/entity/animate.hh"
+#include "shared/entity/moveable.hh"
+#include "shared/math/math.hh"
+#include "shared/movement/struct.hh"
+#include "shared/shared.hh"
+#include "shared/world/chunk.hh"
+
+#include <algorithm>
+#include <array>
+#include <cstdint>
+
+#define GLM_ENABLE_EXPERIMENTAL
+#include <glm/glm.hpp>
+#include <glm/gtx/norm.hpp>
+
+namespace shared {
+namespace movement {
+
+// Returns a local pos relative to the base chunk pos, which can be negative,
+// or over 16.0f.
+glm::vec3 make_relative(const shared::math::coords& base_chunk_pos,
+ const glm::vec3& other_local_pos,
+ const shared::math::coords& other_chunk_pos) noexcept;
+
+void normalise_position(glm::vec3& local_pos,
+ shared::math::coords& chunk_pos) noexcept;
+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;
+
+// We need more information about the block during movement code.
+struct block {
+ shared::world::block block;
+ struct aabb aabb;
+ shared::math::coords chunk_pos;
+ glm::ivec3 pos;
+};
+using blocks = std::vector<block>;
+
+// Returns a vec2 describing how wide and tall the array of blocks should be (to
+// ensure you never fall through anything at variable tickrates).
+glm::ivec2 get_move_xy(const std::uint32_t& tickrate,
+ const moveable& moveable) noexcept;
+
+[[nodiscard]] shared::animate move(const shared::moveable& moveable,
+ const blocks& blocks,
+ const std::uint32_t& tickrate) noexcept;
+
+} // namespace movement
+} // namespace shared
+
+#endif