CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Body.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
13
15
22
23namespace CeresEngine {
24
25 struct CE_SCRIPT_EXPORT() RigidBodyComponent final : public Component<RigidBodyComponent> {
27 struct Accessor;
28
31 double mass = 0.0;
32
35 Vector3 localInertia;
36
39 double linearDamping;
40
43 double angularDamping;
44
47 double friction;
48
51 double rollingFriction;
52
55 double spinningFriction;
56
59 double restitution;
60
64 bool fixed = false;
65
67 HMesh mesh = nullptr;
68
71 Any engineContext;
72
73 public: // Reflection
76 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
77 CE_REFL_DATA(mass);
78 CE_REFL_DATA(localInertia);
79 CE_REFL_DATA(linearDamping);
80 CE_REFL_DATA(angularDamping);
81 CE_REFL_DATA(friction);
82 CE_REFL_DATA(rollingFriction);
83 CE_REFL_DATA(spinningFriction);
84 CE_REFL_DATA(restitution);
85 CE_REFL_DATA(fixed);
86 CE_REFL_DATA(mesh);
87 }
88 };
89
90 struct RigidBodyComponent::Accessor : public Component<RigidBodyComponent>::Accessor {
92
96
99 void setMass(double mass) noexcept;
100
103
106
109
112
115
118
121
123 void setFriction(double friction);
124
127
130
133
136
139
142
145
147 void setFixed(bool fixed);
148
151
154
159 void applyForce(Vector3 force, Vector3 relativePosition = Vector3(0.0)) const;
160
161 public: // Reflection
176 };
177
178 // ---------------------------------------------------------------------------------------------
179
180 struct CE_SCRIPT_EXPORT() SoftBodyComponent final : public Component<SoftBodyComponent> {
182 struct Accessor;
183
184 public: // Reflection
187 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
188 // CE_REFL_DATA(mass);
189 }
190 };
191
192 struct SoftBodyComponent::Accessor : public Component<SoftBodyComponent>::Accessor {
194
199 void applyForce(Vector3 force, Vector3 relativePosition = Vector3(0.0)) const;
200
201 public: // Reflection
205 // CE_REFL_DATA_GETSET(mass, getMass, setMass);
206 }
207 };
208
209 // ---------------------------------------------------------------------------------------------
210
223
224 // ---------------------------------------------------------------------------------------------
225
227 class CE_SCRIPT_EXPORT() StaticBody final : public EntityObject<RigidBodyComponent, TransformComponent> {
228 public:
229 using EntityObject::EntityObject;
230 };
231
233 class CE_SCRIPT_EXPORT() RigidBody final : public EntityObject<RigidBodyComponent, Motion, TransformComponent> {
234 public:
235 using EntityObject::EntityObject;
236 };
237
239 class CE_SCRIPT_EXPORT() SoftBody final : public EntityObject<SoftBodyComponent, Motion, TransformComponent> {
240 public:
241 using EntityObject::EntityObject;
242 };
243
244} // namespace CeresEngine
245
248
251
254
257
260
#define CE_EXTERN_COMPONENT(T)
Definition Component.hpp:600
#define CE_ENTITY_OBJECT_HASH(T)
Definition Entity.hpp:784
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFLECTABLE_STRUCT
Definition IReflectable.hpp:47
#define CE_REFL_DATA_GETSET(N, G, S)
Definition Macros.hpp:549
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Definition Any.hpp:13
A type-safe entity type.
Definition Entity.hpp:538
A rigid body is a body that can be collided with and can be moved.
Definition Body.hpp:233
A soft body is a body that can have deformations.
Definition Body.hpp:239
A static body is a body that can be collided with, but cannot be moved.
Definition Body.hpp:227
Definition Application.hpp:19
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Body.hpp:211
Vector3 force
The force to be applied.
Definition Body.hpp:213
ApplyForce(Vector3 force, Vector3 relativePosition=Vector3(0.0))
Creates a new ApplyForce action.
Vector3 relativePosition
The relative position to apply the force at.
Definition Body.hpp:216
Accessor(const Entity &entity)
Definition Component.hpp:181
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
A class that must be inherited by concrete action types.
Definition Action.hpp:33
void setFriction(double friction)
The body's friction factor.
void setSpinningFriction(double spinningFriction)
The body's spinning friction factor.
double getRollingFriction() const
The body's rolling friction factor.
double getSpinningFriction() const
The body's spinning friction factor.
void setLinearDamping(double linearDamping)
The body's linear damping factor.
void setRollingFriction(double rollingFriction)
The body's rolling friction factor.
void applyForce(Vector3 force, Vector3 relativePosition=Vector3(0.0)) const
Applies a force in a body.
void setMass(double mass) noexcept
The rigid body mass.
double getFriction() const
The body's friction factor.
Vector3 getLocalInertia() const
The rigid body local inertia.
double getAngularDamping() const
The body's angular damping factor.
double getLinearDamping() const
The body's linear damping factor.
void setRestitution(double restitution)
The body's restitution factor.
void setAngularDamping(double angularDamping)
The body's angular damping factor.
double getRestitution() const
The body's restitution factor.
void setFixed(bool fixed)
If set to true, if the body is non-movable and the engine might use this to optimize calculations.
void setLocalInertia(Vector3 localInertia)
The rigid body local inertia.
double getMass() const noexcept
The rigid body mass.
bool isFixed() const
If set to true, if the body is non-movable and the engine might use this to optimize calculations.
Definition Body.hpp:25
HMesh mesh
A mesh to be used for collision computations.
Definition Body.hpp:67
double friction
The body's friction factor.
Definition Body.hpp:47
double rollingFriction
The body's rolling friction factor.
Definition Body.hpp:51
double spinningFriction
The body's spinning friction factor.
Definition Body.hpp:55
double angularDamping
The body's angular damping factor.
Definition Body.hpp:43
double restitution
The body's restitution factor.
Definition Body.hpp:59
double mass
The rigid body mass.
Definition Body.hpp:31
bool fixed
If set to true, if the body is non-movable and the engine might use this to optimize calculations.
Definition Body.hpp:64
Vector3 localInertia
The rigid body local inertia.
Definition Body.hpp:35
double linearDamping
The body's linear damping factor.
Definition Body.hpp:39
void applyForce(Vector3 force, Vector3 relativePosition=Vector3(0.0)) const
Applies a force in a body.
Definition Body.hpp:180
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition Body.hpp:187