Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
collision_shapes.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "node.h"
4 
5 enum class BodyType { STATIC, DYNAMIC, KINEMATIC };
6 
7 enum class ShapeType {
8  RECTANGLE,
9  CIRCLE,
10  POLYGON,
11  CAPSULE
12 
13 };
14 
16  b2ShapeId id = b2_nullShapeId;
19 
20  glm::vec2 offset = glm::vec2(0.0f);
21 
22  virtual ~CollisionShape() = default;
23 };
24 
26  glm::vec2 size = glm::vec2(32.0f, 32.0f);
27 
28  explicit RectangleShape(const glm::vec2& size = glm::vec2(32.0f, 32.0f),
29  BodyType body_type = BodyType::STATIC,const glm::vec2& offset = glm::vec2(0.0f)) {
30  this->size = size;
31  this->offset = offset;
32  this->body_type = body_type;
34  }
35 };
36 
37 struct CircleShape final : CollisionShape {
38  float radius = 16.0f;
39 
40  explicit CircleShape(float radius = 16.0f, BodyType body_type = BodyType::STATIC,const glm::vec2& offset = glm::vec2(0.0f)) {
41  this->radius = radius;
42  this->offset = offset;
43  this->body_type = body_type;
45  }
46 };
47 
48 struct CapsuleShape final : CollisionShape {
49  float radius = 16.0f;
50  float height = 32.0f;
51 
52  explicit CapsuleShape(float radius = 16.0f, float height = 32.0f,
53  BodyType body_type = BodyType::STATIC,const glm::vec2& offset = glm::vec2(0.0f)) {
54  this->radius = radius;
55  this->height = height;
56  this->offset = offset;
57  this->body_type = body_type;
59  }
60 };
61 
62 struct PolygonShape final : CollisionShape {
63  std::vector<glm::vec2> vertices;
64 
65  explicit PolygonShape(const std::vector<glm::vec2>& verts = {},
66  BodyType body_type = BodyType::STATIC,const glm::vec2& offset = glm::vec2(0.0f)) {
67  this->vertices = verts;
68  this->offset = offset;
69  this->body_type = body_type;
71  }
72 };
ShapeType
Definition: collision_shapes.h:7
BodyType
Definition: collision_shapes.h:5
Definition: collision_shapes.h:48
CapsuleShape(float radius=16.0f, float height=32.0f, BodyType body_type=BodyType::STATIC, const glm::vec2 &offset=glm::vec2(0.0f))
Definition: collision_shapes.h:52
float radius
Definition: collision_shapes.h:49
float height
Definition: collision_shapes.h:50
Definition: collision_shapes.h:37
float radius
Definition: collision_shapes.h:38
CircleShape(float radius=16.0f, BodyType body_type=BodyType::STATIC, const glm::vec2 &offset=glm::vec2(0.0f))
Definition: collision_shapes.h:40
Definition: collision_shapes.h:15
BodyType body_type
Definition: collision_shapes.h:17
glm::vec2 offset
Definition: collision_shapes.h:20
virtual ~CollisionShape()=default
ShapeType shape_type
Definition: collision_shapes.h:18
Definition: collision_shapes.h:62
PolygonShape(const std::vector< glm::vec2 > &verts={}, BodyType body_type=BodyType::STATIC, const glm::vec2 &offset=glm::vec2(0.0f))
Definition: collision_shapes.h:65
std::vector< glm::vec2 > vertices
Definition: collision_shapes.h:63
Definition: collision_shapes.h:25
RectangleShape(const glm::vec2 &size=glm::vec2(32.0f, 32.0f), BodyType body_type=BodyType::STATIC, const glm::vec2 &offset=glm::vec2(0.0f))
Definition: collision_shapes.h:28
glm::vec2 size
Definition: collision_shapes.h:26