aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Rigidbody.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-07 20:08:09 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-07 20:08:09 +0100
commit1c4156ee127b14760ed3b1a0cd16ad12180c7ac6 (patch)
tree211505d5328f24c9f9beabf8f874d9e13ef92130 /src/crepe/api/Rigidbody.h
parent9df087ede0b539ecbd2778236c7d1143362b384d (diff)
parent3d2428af8e8d9d49b4ade52d4806a7dae4cf1ab8 (diff)
merge `master` into `loek/savemgr`
Diffstat (limited to 'src/crepe/api/Rigidbody.h')
-rw-r--r--src/crepe/api/Rigidbody.h108
1 files changed, 91 insertions, 17 deletions
diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h
index 518ed94..68481f4 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -4,27 +4,101 @@
#include "../Component.h"
-namespace crepe {
+#include "Vector2.h"
-// FIXME: can't this enum be defined inside the class declaration of Rigidbody?
-enum class BodyType {
- //! Does not move (e.g. walls, ground ...)
- STATIC,
- //! Moves and responds to forces (e.g. player, physics objects ...)
- DYNAMIC,
- //! Moves but does not respond to forces (e.g. moving platforms ...)
- KINEMATIC,
-};
+namespace crepe {
+/**
+ * \brief Rigidbody class
+ *
+ * This class is used by the physics sytem and collision system.
+ * It configures how to system interact with the gameobject for movement and collisions.
+ */
class Rigidbody : public Component {
public:
- Rigidbody(uint32_t game_object_id, int mass, int gravity_scale,
- BodyType body_type);
- int32_t velocity_x;
- int32_t velocity_y;
- int mass;
- int gravity_scale;
- BodyType body_type;
+ /**
+ * \brief BodyType enum
+ *
+ * This enum provides three bodytypes the physics sytem and collision system use.
+ */
+ enum class BodyType {
+ //! Does not move (e.g. walls, ground ...)
+ STATIC,
+ //! Moves and responds to forces (e.g. player, physics objects ...)
+ DYNAMIC,
+ //! Moves but does not respond to forces (e.g. moving platforms ...)
+ KINEMATIC,
+ };
+ /**
+ * \brief PhysicsConstraints to constrain movement
+ *
+ * This struct configures the movement constraint for this object.
+ * If a constraint is enabled the systems will not move the object.
+ */
+ struct PhysicsConstraints {
+ //! X constraint
+ bool x = false;
+ //! Y constraint
+ bool y = false;
+ //! rotation constraint
+ bool rotation = false;
+ };
+
+public:
+ /**
+ * \brief struct for Rigidbody data
+ *
+ * This struct holds the data for the Rigidbody.
+ */
+ struct Data {
+ //! objects mass
+ double mass = 0.0;
+ //! gravtiy scale
+ double gravity_scale = 0.0;
+ //! Changes if physics apply
+ BodyType body_type = BodyType::DYNAMIC;
+ //! linear velocity of object
+ Vector2 linear_velocity;
+ //! maximum linear velocity of object
+ Vector2 max_linear_velocity;
+ //! linear damping of object
+ Vector2 linear_damping;
+ //! angular velocity of object
+ double angular_velocity = 0.0;
+ //! max angular velocity of object
+ double max_angular_velocity = 0.0;
+ //! angular damping of object
+ double angular_damping = 0.0;
+ //! movements constraints of object
+ PhysicsConstraints constraints;
+ //! if gravity applies
+ bool use_gravity = true;
+ //! if object bounces
+ bool bounce = false;
+ };
+
+public:
+ /**
+ * \param game_object_id id of the gameobject the rigibody is added to.
+ * \param data struct to configure the rigidbody.
+ */
+ Rigidbody(uint32_t game_object_id, const Data & data);
+ //! struct to hold data of rigidbody
+ Data data;
+
+public:
+ /**
+ * \brief add a linear force to the Rigidbody.
+ *
+ * \param force Vector2 that is added to the linear force.
+ */
+ void add_force_linear(const Vector2 & force);
+ /**
+ * \brief add a angular force to the Rigidbody.
+ *
+ * \param force Vector2 that is added to the angular force.
+ */
+ void add_force_angular(double force);
};
} // namespace crepe