From e4483eca01b48b943cd0461e24a74ae1a3139ed4 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 21:57:46 +1100 Subject: Update to most recent version (old initial commit) --- src/shared/movement/movement.hh | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/shared/movement/movement.hh (limited to 'src/shared/movement/movement.hh') 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 +#include +#include + +#define GLM_ENABLE_EXPERIMENTAL +#include +#include + +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 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 +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; + +// 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 -- cgit v1.2.3