Hymn to Beauty
C++ 3D Engine
Shape.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <glm/vec3.hpp>
4#include <memory>
5
6class btCollisionShape;
8
9namespace Component {
10class RigidBody;
11}
12
13namespace Physics {
14class Trigger;
15
18class Shape {
19 friend class ::PhysicsManager;
20 friend class ::Component::RigidBody;
21 friend class Trigger;
22
23 public:
25 struct Sphere {
26 explicit Sphere(float radius) : radius(radius) {}
27 float radius;
28 };
29
31 struct Plane {
32 Plane(const glm::vec3& normal, float planeCoeff) : normal(normal), planeCoeff(planeCoeff) {}
33 glm::vec3 normal;
35 };
36
38 struct Box {
39 Box(float width, float height, float depth) : width(width), height(height), depth(depth) {}
40 float width;
41 float height;
42 float depth;
43 };
44
46 struct Cylinder {
48 float radius;
49 float length;
50 };
51
53 struct Cone {
54 Cone(float radius, float height) : radius(radius), height(height) {}
55 float radius;
56 float height;
57 };
58
60 struct Capsule {
62 float radius;
63 float height;
64 };
65
67 enum class Kind {
68 Sphere,
69 Plane,
70 Box,
72 Cone,
73 Capsule,
74 };
75
77
80 explicit Shape(const Sphere& params);
81
83
86 explicit Shape(const Plane& params);
87
89
92 explicit Shape(const Box& params);
93
95
98 explicit Shape(const Cylinder& params);
99
101
104 explicit Shape(const Cone& params);
105
107
110 explicit Shape(const Capsule& params);
111
113 ~Shape();
114
116
119 Kind GetKind() const;
120
122
125 const Sphere* GetSphereData() const;
126
128
131 const Plane* GetPlaneData() const;
132
134
137 const Box* GetBoxData() const;
138
140
143 const Cylinder* GetCylinderData() const;
144
146
149 const Cone* GetConeData() const;
150
152
155 const Capsule* GetCapsuleData() const;
156
157 private:
159
162 btCollisionShape* GetShape() const;
163
164 Shape(const Shape& other) = delete;
165
166 std::unique_ptr<btCollisionShape> shape;
167 Kind kind;
168 union {
175 };
176};
177} // namespace Physics
Definition: Shape.hpp:18
const Box * GetBoxData() const
Get box data of the shape.
Definition: Shape.cpp:64
Box box
Definition: Shape.hpp:171
~Shape()
Destructor.
Definition: Shape.cpp:50
Plane plane
Definition: Shape.hpp:170
const Sphere * GetSphereData() const
Get sphere data of the shape.
Definition: Shape.cpp:56
Cylinder cylinder
Definition: Shape.hpp:172
Kind GetKind() const
Get the type of wrapped shape.
Definition: Shape.cpp:52
Capsule capsule
Definition: Shape.hpp:174
Cone cone
Definition: Shape.hpp:173
const Plane * GetPlaneData() const
Get plane data of the shape.
Definition: Shape.cpp:60
Shape(const Sphere &params)
Construct a sphere shape.
Definition: Shape.cpp:6
const Cone * GetConeData() const
Get cone data of the shape.
Definition: Shape.cpp:72
const Capsule * GetCapsuleData() const
Get capsule data of the shape.
Definition: Shape.cpp:76
Kind
The various kinds of shapes that are wrapped by Shape.
Definition: Shape.hpp:67
const Cylinder * GetCylinderData() const
Get cylinder data of the shape.
Definition: Shape.cpp:68
Sphere sphere
Definition: Shape.hpp:169
Definition: Trigger.hpp:15
Updates the physics of the world.
Definition: PhysicsManager.hpp:28
Definition: BoxShapeEditor.hpp:5
Definition: IShapeEditor.hpp:7
Parameters used to create a box shape.
Definition: Shape.hpp:38
float height
Definition: Shape.hpp:41
float depth
Definition: Shape.hpp:42
float width
Definition: Shape.hpp:40
Box(float width, float height, float depth)
Definition: Shape.hpp:39
Parameters used to create a capsule shape.
Definition: Shape.hpp:60
float height
Definition: Shape.hpp:63
float radius
Definition: Shape.hpp:62
Capsule(float radius, float height)
Definition: Shape.hpp:61
Parameters used to create a cone shape.
Definition: Shape.hpp:53
float height
Definition: Shape.hpp:56
float radius
Definition: Shape.hpp:55
Cone(float radius, float height)
Definition: Shape.hpp:54
Parameters used to create a cylinder shape.
Definition: Shape.hpp:46
float length
Definition: Shape.hpp:49
Cylinder(float radius, float length)
Definition: Shape.hpp:47
float radius
Definition: Shape.hpp:48
Parameters used to create a plane shape.
Definition: Shape.hpp:31
Plane(const glm::vec3 &normal, float planeCoeff)
Definition: Shape.hpp:32
float planeCoeff
Definition: Shape.hpp:34
glm::vec3 normal
Definition: Shape.hpp:33
Parameters used to create a sphere shape.
Definition: Shape.hpp:25
float radius
Definition: Shape.hpp:27
Sphere(float radius)
Definition: Shape.hpp:26