Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
RigidBodyComponent.hpp
1#pragma once
2
3#include <Jolt/Physics/Body/BodyID.h>
4
5#include <Common/Math.hpp>
6#include <Common/PhysicsLayer.hpp>
7#include <EngineCore/ECS/Entity.hpp>
8#include <EngineCore/Reflection/ComponentReflection.hpp>
9
10#include "ColliderComponent.hpp"
11
12class btRigidBody;
13
14namespace Grindstone {
15 struct TransformComponent;
16 class WorldContextSet;
17
18 namespace Physics {
19 struct ColliderComponent;
20
21 struct RigidBodyComponent {
22 RigidBodyComponent() = default;
23 RigidBodyComponent(float mass, ColliderComponent* colliderComponent);
24 RigidBodyComponent Clone(Grindstone::WorldContextSet& cxt, entt::entity newEntityId) const;
25 static void Construct(Grindstone::WorldContextSet&, entt::entity);
26 static void Destroy(Grindstone::WorldContextSet&, entt::entity);
27
28 void SetIsStatic(bool isStatic);
29 void SetLayer(Grindstone::Physics::Layer layer);
30 void SetFriction(float friction);
31 void SetRestitution(float restitution);
32 void SetPosition(Math::Float3 pos);
33 void SetRotation(Math::Quaternion rot);
34
35 void ApplyForce(Math::Float3 pos, Math::Float3 force);
36 void ApplyCentralForce(Math::Float3 force);
37 void ApplyImpulse(Math::Float3 pos, Math::Float3 force);
38 void ApplyCentralImpulse(Math::Float3 force);
39
40 bool GetIsStatic() const;
41 Grindstone::Physics::Layer GetLayer() const;
42 float GetMass() const;
43 float GetFriction() const;
44 float GetRestitution() const;
45 Math::Float3 GetPosition() const;
46 Math::Quaternion GetRotation() const;
47
48 void SetBodyID(JPH::BodyID bodyId);
49 JPH::BodyID GetBodyID() const;
50
51 bool isStatic = false;
52 Grindstone::Physics::Layer layer = 0;
53
54 float mass = 0.0f;
55 float friction = 0.0f;
56 float restitution = 0.0f;
57 JPH::BodyID rigidBody;
58
59 public:
60
61 REFLECT("RigidBody")
62 };
63
64 void SetupRigidBodyComponentWithCollider(
65 Grindstone::WorldContextSet& cxt,
66 RigidBodyComponent* rigidBodyComponent,
67 TransformComponent* transformComponent,
68 ColliderComponent* colliderComponent
69 );
70 }
71}
Definition WorldContextSet.hpp:11
Definition PhysicsLayer.hpp:6
Definition ArchiveContentFile.hpp:8
Definition ColliderComponent.hpp:14
Definition RigidBodyComponent.hpp:19
Definition TransformComponent.hpp:12