Tramway SDK
trigger.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_TRIGGERCOMPONENT_H
5#define TRAM_SDK_COMPONENTS_TRIGGERCOMPONENT_H
6
7#include <physics/physics.h>
9
10#include <vector>
11
12class btCollisionShape;
13class btCollisionObject;
14
15namespace tram {
16
18public:
19 TriggerComponent() : model(this){}
21 void EventHandler(Event &event){};
22 void Start();
23
24 Physics::CollisionModel* GetModel() { return model.get(); }
25 void SetModel(name_t model) { this->model = Physics::CollisionModel::Find(model); }
26 void SetModel(Physics::CollisionModel* model) { this->model = model; }
28
29 void SetActivationCallback(void (*activation_callback)(TriggerComponent*, Physics::Collision)) { this->activation_callback = activation_callback; }
30 void SetDectivationCallback(void (*deactivation_callback)(TriggerComponent*, Physics::Collision)) { this->deactivation_callback = deactivation_callback; }
31 void SetFilterCallback(bool (*filter_callback)(TriggerComponent*, PhysicsComponent*)) { this->filter_callback = filter_callback; }
32
33 void SetCollisionMask(uint32_t flags);
34 void SetCollisionGroup(uint32_t flags);
35
36 void SetStoreCollisions(bool store_collisions) { this->store_collisions = store_collisions; }
37
38 uint32_t GetCollisionMask() { return collisionMask; }
39 uint32_t GetCollisionGroup() { return collisionGroup; }
40
41 void SetLocation(vec3 location);
42 void SetRotation(quat rotation);
43
44 const std::vector<Physics::Collision>& GetStoredCollisions() { return stored_collisions; }
45
46 void Collision(const Physics::Collision& collision);
47 void ResetCollisions();
48
49 std::vector<Physics::Collision> Poll ();
50private:
52
53 uint32_t collisionMask = -1;
54 uint32_t collisionGroup = -1;
55
56 vec3 location = vec3(0.0f, 0.0f, 0.0f);
57 quat rotation = vec3(0.0f, 0.0f, 0.0f);
58
59 Physics::collisionshape_t shape = {nullptr};
60 Physics::trigger_t trigger = {nullptr};
61
62 void (*activation_callback)(TriggerComponent*, Physics::Collision) = nullptr;
63 void (*deactivation_callback)(TriggerComponent*, Physics::Collision) = nullptr;
64 bool (*filter_callback)(TriggerComponent*, PhysicsComponent*) = nullptr;
65
66 bool store_collisions = false;
67
68 std::vector<std::pair<uint32_t, Physics::Collision>> active_collisions;
69
70 std::vector<Physics::Collision> stored_collisions;
71};
72
73}
74
75#endif // TRAM_SDK_COMPONENTS_TRIGGERCOMPONENT_H
Definition: entitycomponent.h:18
Definition: collisionmodel.h:12
static CollisionModel * Find(name_t model_name)
Finds a model.
Definition: collisionmodel.cpp:21
Definition: physics.h:13
Definition: resource.h:47
Definition: trigger.h:17
uint32_t GetCollisionMask()
Definition: trigger.h:38
void SetLocation(vec3 location)
Sets the location of the component.
Definition: trigger.cpp:71
void EventHandler(Event &event)
Definition: trigger.h:21
void SetModel(name_t model)
Definition: trigger.h:25
void SetActivationCallback(void(*activation_callback)(TriggerComponent *, Physics::Collision))
Definition: trigger.h:29
void SetDectivationCallback(void(*deactivation_callback)(TriggerComponent *, Physics::Collision))
Definition: trigger.h:30
void SetFilterCallback(bool(*filter_callback)(TriggerComponent *, PhysicsComponent *))
Definition: trigger.h:31
void Start()
Definition: trigger.cpp:15
void SetStoreCollisions(bool store_collisions)
Definition: trigger.h:36
void ResetCollisions()
Resets registered collisions.
Definition: trigger.cpp:118
void SetCollisionGroup(uint32_t flags)
Sets a collision group for the trigger.
Definition: trigger.cpp:62
uint32_t GetCollisionGroup()
Definition: trigger.h:39
~TriggerComponent()
Definition: trigger.cpp:37
void SetCollisionMask(uint32_t flags)
Sets a collision mask for the trigger.
Definition: trigger.cpp:51
Physics::CollisionModel * GetModel()
Definition: trigger.h:24
TriggerComponent()
Definition: trigger.h:19
void Collision(const Physics::Collision &collision)
Registers a collision.
Definition: trigger.cpp:90
std::vector< Physics::Collision > Poll()
Checks for collisions with the trigger.
Definition: trigger.cpp:186
void SetModel(Physics::CollisionModel *model)
Definition: trigger.h:26
void SetShape(Physics::CollisionShape shape)
Sets a collision shape for the trigger.
Definition: trigger.cpp:44
const std::vector< Physics::Collision > & GetStoredCollisions()
Definition: trigger.h:44
void SetRotation(quat rotation)
Sets the rotation of the component.
Definition: trigger.cpp:80
Definition: api.h:9
glm::vec3 vec3
Definition: math.h:12
glm::quat quat
Definition: math.h:13
Definition: event.h:24
Definition: physics.h:35
Definition: collisionshape.h:25
Definition: physics.h:44
Definition: uid.h:11