aboutsummaryrefslogtreecommitdiff
path: root/src/shared/movement.hh
blob: 375c030b116376c2e13a091f2601790600c558d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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