nngn
Loading...
Searching...
No Matches
colliders.h
Go to the documentation of this file.
1#ifndef NNGN_COLLISION_COLLIDERS_H
2#define NNGN_COLLISION_COLLIDERS_H
3
4#include "lua/table.h"
5#include "math/vec2.h"
6#include "math/vec3.h"
7#include "math/vec4.h"
8#include "utils/def.h"
9#include "utils/flags.h"
10
11struct Entity;
12
13namespace nngn {
14
15struct Collider {
16 enum Type : u8 {
18 };
19 enum Flag : u8 {
20 COLLIDING = 1 << 0,
21 TRIGGER = 1 << 1,
22 SOLID = 1 << 2,
23 };
24 Entity *entity = nullptr;
25 vec3 pos = {}, vel = {};
26 float m = {};
28 Collider() = default;
29 explicit Collider(vec3 p) : pos(p) {}
30 Collider(vec3 p, float p_m) : pos(p), m(p_m) {}
32};
33
35 vec2 rel_center = {}, rel_bl = {}, rel_tr = {};
36 vec2 center = {}, bl = {}, tr = {};
37 float radius = {};
38 AABBCollider() = default;
39 AABBCollider(vec2 p_bl, vec2 p_tr);
40 static void update(std::span<AABBCollider> s);
42};
43
45 float cos = {}, sin = {};
46 BBCollider() = default;
47 BBCollider(vec2 p_bl, vec2 p_tr, float p_cos, float p_sin) :
48 AABBCollider(p_bl, p_tr), cos(p_cos), sin(p_sin) {}
49 static void update(std::span<BBCollider> s);
51};
52
54 float r = 0;
55 SphereCollider() = default;
56 SphereCollider(vec3 p_pos, float p_r) : Collider(p_pos), r(p_r) {}
57 static void update(std::span<SphereCollider> s);
59};
60
62 vec4 abcd = {};
63 PlaneCollider() = default;
65 static void update(std::span<PlaneCollider> s);
67};
68
70 static constexpr float G = 6.674e-11f;
71 float max_distance2 = {};
72 GravityCollider() = default;
73 GravityCollider(vec3 p, float p_m, float max_distance)
74 : Collider(p, p_m), max_distance2(max_distance * max_distance) {}
75 static void update(std::span<GravityCollider> s);
76 void load(const nngn::lua::table &t);
77};
78
79}
80
81#endif
update
Definition img_common.lua:42
pos
Definition lua_audio.cpp:17
Definition audio.cpp:7
std::uint8_t u8
Definition def.h:12
load
Definition entity.lua:7
v[1]
Definition math.lua:22
Definition entity.h:24
Definition colliders.h:34
vec2 tr
Definition colliders.h:36
vec2 rel_bl
Definition colliders.h:35
vec2 center
Definition colliders.h:36
vec2 bl
Definition colliders.h:36
vec2 rel_center
Definition colliders.h:35
vec2 rel_tr
Definition colliders.h:35
AABBCollider()=default
float radius
Definition colliders.h:37
Definition colliders.h:44
BBCollider(vec2 p_bl, vec2 p_tr, float p_cos, float p_sin)
Definition colliders.h:47
float cos
Definition colliders.h:45
BBCollider()=default
float sin
Definition colliders.h:45
Definition colliders.h:15
Type
Definition colliders.h:16
@ GRAVITY
Definition colliders.h:17
@ SPHERE
Definition colliders.h:17
@ PLANE
Definition colliders.h:17
@ NONE
Definition colliders.h:17
@ AABB
Definition colliders.h:17
@ BB
Definition colliders.h:17
@ N_TYPES
Definition colliders.h:17
Collider()=default
Collider(vec3 p)
Definition colliders.h:29
Entity * entity
Definition colliders.h:24
float m
Definition colliders.h:26
Flag
Definition colliders.h:19
@ COLLIDING
Definition colliders.h:20
@ TRIGGER
Definition colliders.h:21
@ SOLID
Definition colliders.h:22
Flags< Flag > flags
Definition colliders.h:27
vec3 vel
Definition colliders.h:25
Collider(vec3 p, float p_m)
Definition colliders.h:30
Wrapper for a small unsigned integral representing flags.
Definition flags.h:18
Definition colliders.h:69
GravityCollider(vec3 p, float p_m, float max_distance)
Definition colliders.h:73
static constexpr float G
Definition colliders.h:70
float max_distance2
Definition colliders.h:71
Definition colliders.h:61
PlaneCollider()=default
PlaneCollider(vec3 p, vec4 v)
Definition colliders.h:64
vec4 abcd
Definition colliders.h:62
Definition colliders.h:53
SphereCollider()=default
float r
Definition colliders.h:54
SphereCollider(vec3 p_pos, float p_r)
Definition colliders.h:56
Non-owning reference to a table on the stack.
Definition table.h:166
Owning reference to a table on the stack, popped when destroyed.
Definition table.h:172
Operations on table values.
std::chrono::seconds s
Definition timing.cpp:6