Tramway SDK
physics.h
Go to the documentation of this file.
1// TRAMWAY DRIFT AND DUNGEON EXPLORATION SIMULATOR 2022
2// All rights reserved.
3
4#ifndef TRAM_SDK_COMPONENTS_PHYSICSCOMPONENT_H
5#define TRAM_SDK_COMPONENTS_PHYSICSCOMPONENT_H
6
7#include <physics/physics.h>
10
11namespace tram {
12
14public:
15 PhysicsComponent() : collision_model(this) {}
17 void EventHandler(Event &event) {}
18 void Start();
19
21 void SetModel(name_t model);
22
23 void SetMass(float mass);
25
26 void Push(vec3 direction);
27 void Push(vec3 direction, vec3 local_position);
28 void Spin(vec3 direction);
29
30 void SetCollisionMask(uint32_t flags);
31 void SetCollisionGroup(uint32_t flags);
32
33 uint32_t GetCollisionMask();
34 uint32_t GetCollisionGroup();
35
36 void SetDebugDrawing(bool drawing);
37 void SetKinematic(bool kinematic);
38 void SetUpdateParentTransform(bool update);
39
40 void SetRotation(quat rotation);
41 void SetLocation(vec3 location);
42
44
45 void Awaken();
46 void Sleep();
47
48 void SetAngularFactor(vec3 factor);
49 void SetLinearFactor(vec3 factor);
50
51 void SetVelocity(const vec3& velocity);
53private:
55 Physics::collisionshape_t collision_shape = {nullptr};
56 Physics::rigidbody_t rigidbody = {nullptr};
57
58 float rigidbody_mass = 1.0f;
59
60 bool rigidbody_should_sleep = true;
61 bool rigidbody_should_awake = false;
62 bool update_parent_transform = true;
63 bool rigidbody_kinematic = false;
64 bool rigidbody_debug_draw = true;
65
66 vec3 rigidbody_position = {0.0f, 0.0f, 0.0f};
67 quat rigidbody_rotation = {1.0f, 0.0f, 0.0f, 0.0f};
68
69 vec3 rigidbody_offset = {0.0f, 0.0f, 0.0f};
70 vec3 rigidbody_angular_factor = {1.0f, 1.0f, 1.0f};
71 vec3 rigidbody_linear_factor = {1.0f, 1.0f, 1.0f};
72
73 uint32_t rigidbody_collision_mask = -1;
74 uint32_t rigidbody_collision_group = -1;
75};
76
77}
78
79#endif // TRAM_SDK_COMPONENTS_PHYSICSCOMPONENT_H
Definition: entitycomponent.h:18
Definition: physics.h:13
void SetRotation(quat rotation)
Sets the rotation of the physics object.
Definition: physics.cpp:254
void SetCollisionMask(uint32_t flags)
Sets the collision mask of the physics object.
Definition: physics.cpp:102
void Push(vec3 direction)
Pushes the physics object.
Definition: physics.cpp:148
void SetShape(Physics::CollisionShape shape)
Sets the collision shape of the physics object.
Definition: physics.cpp:128
void SetUpdateParentTransform(bool update)
Sets whether the movement of the rigibody should update parent Entity's transform.
Definition: physics.cpp:237
void Spin(vec3 direction)
Definition: physics.cpp:165
~PhysicsComponent()
Definition: physics.cpp:64
void SetAngularFactor(vec3 factor)
Sets the angular factor of the physics object.
Definition: physics.cpp:268
void EventHandler(Event &event)
Definition: physics.h:17
void SetLocation(vec3 location)
Sets the position of the physics object.
Definition: physics.cpp:242
vec3 GetVelocity()
Returns the velocity of the physics object.
Definition: physics.cpp:318
void SetCollisionGroup(uint32_t flags)
Sets the collision group of the physics object.
Definition: physics.cpp:117
uint32_t GetCollisionMask()
Returns the collision mask.
Definition: physics.cpp:87
void Start()
Definition: physics.cpp:15
void SetKinematic(bool kinematic)
Sets the physics object to kinematic.
Definition: physics.cpp:217
void SetVelocity(const vec3 &velocity)
Sets the velocity of the physics object.
Definition: physics.cpp:302
void Sleep()
Puts the object to sleep.
Definition: physics.cpp:185
void Awaken()
Awakens the object.
Definition: physics.cpp:175
uint32_t GetCollisionGroup()
Returns the collision group.
Definition: physics.cpp:93
void SetDebugDrawing(bool drawing)
Sets the debug drawing of a physics object.
Definition: physics.cpp:197
void SetLinearFactor(vec3 factor)
Sets the angular factor of the physics object.
Definition: physics.cpp:280
void DisableDeactivation()
Disables deactivation of the object.
Definition: physics.cpp:291
void SetModel(name_t model)
Sets the collision model.
Definition: physics.cpp:81
void SetMass(float mass)
Sets the mass of the physics object.
Definition: physics.cpp:136
PhysicsComponent()
Definition: physics.h:15
name_t GetModel()
Returns the name of the collision model.
Definition: physics.cpp:76
Definition: resource.h:47
Definition: api.h:9
glm::vec3 vec3
Definition: math.h:12
glm::quat quat
Definition: math.h:13
Definition: event.h:24
Definition: collisionshape.h:25
Definition: physics.h:44
Definition: uid.h:11