Tramway SDK
controller.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_CONTROLLERCOMPONENT_H
5#define TRAM_SDK_COMPONENTS_CONTROLLERCOMPONENT_H
6
7#include <framework/core.h>
9#include <physics/physics.h>
10
11namespace tram {
12
13class PhysicsComponent;
14class TriggerComponent;
15
17public:
18 void Start();
19 void EventHandler(Event &event) {}
20
21 void Move(vec3 local_direction);
22
23 void Run();
24 void Crouch();
25 void Jump();
26 void TurnLeft();
27 void TurnRight();
28
29 void Push(vec3 direction);
30
31 inline void SetLookDirection(quat direction) { look_direction = direction; }
32 inline quat GetLookDirection() const { return look_direction; }
33
34 inline void SetCollisionSize(float width, float height, float crouch_height) {
35 collision_width = width;
36 collision_height = height;
37 collision_height_crouch = crouch_height;
38 }
39
40 inline void SetStepHeight(float height, float crouch_height) {
41 step_height = height;
42 step_height_crouch = crouch_height;
43 }
44
46 wallbonk_callback = callback;
47 }
48
49 inline void SetWalkSpeed(float walk_speed) { this->walk_speed = walk_speed; }
50 inline void SetRunSpeed(float run_speed) { this->run_speed = run_speed; }
51 inline void SetCrouchSpeed(float crouch_speed) { this->crouch_speed = crouch_speed; }
52 inline void SetFriction(float friction) { this->friction = friction; }
53 inline void SetCollisionGroup(uint32_t group) { this->collision_group = group; }
54
55 static void Update();
56protected:
59
62
64
65 void ApplyDynamics();
67 void ResetMove();
68
69 vec3 velocity = {0.0f, 0.0f, 0.0f};
70 vec3 move_direction = {0.0f, 0.0f, 0.0f};
71 quat look_direction = {1.0f, 0.0f, 0.0f, 0.0f};
72
73 bool is_in_air = false;
74
75 float collision_width = 0.35f;
76 float collision_height = 1.85f;
78
79 float step_height = 0.35f;
80 float step_height_crouch = 0.15f;
81
82 float walk_speed = 0.1f;
83 float run_speed = 0.2f;
84 float crouch_speed = 0.05f;
85
86 float friction = 0.89f;
87
88 bool crouching = false;
89 bool running = false;
90
94
96
97 void (*wallbonk_callback)(ControllerComponent*, Physics::Collision) = nullptr;
98
99 template <typename> friend class Pool;
100};
101
102}
103
104#endif // TRAM_SDK_COMPONENTS_CONTROLLERCOMPONENT_H
Wrapper for an EntityComponent pointer.
Definition: entitycomponent.h:53
Definition: controller.h:16
vec3 velocity
Definition: controller.h:69
void TurnLeft()
Definition: controller.cpp:64
bool running
Definition: controller.h:89
void Jump()
Definition: controller.cpp:57
void SetWalkSpeed(float walk_speed)
Definition: controller.h:49
void TurnRight()
Definition: controller.cpp:68
void SetFriction(float friction)
Definition: controller.h:52
void Move(vec3 local_direction)
Definition: controller.cpp:45
void SetRunSpeed(float run_speed)
Definition: controller.h:50
Component< TriggerComponent > walk_collision
Definition: controller.h:60
float collision_width
Definition: controller.h:75
id_t standing_on
Definition: controller.h:91
float collision_height
Definition: controller.h:76
float friction
Definition: controller.h:86
void SetCollisionSize(float width, float height, float crouch_height)
Definition: controller.h:34
Component< TriggerComponent > crouch_collision
Definition: controller.h:61
void ApplyDynamics()
Definition: controller.cpp:73
vec3 standing_pos
Definition: controller.h:93
void Run()
Definition: controller.cpp:49
vec3 move_direction
Definition: controller.h:70
id_t standing_on_prev
Definition: controller.h:92
float run_speed
Definition: controller.h:83
float walk_speed
Definition: controller.h:82
void SetStepHeight(float height, float crouch_height)
Definition: controller.h:40
bool crouching
Definition: controller.h:88
uint32_t collision_group
Definition: controller.h:95
void Push(vec3 direction)
Definition: controller.cpp:41
float step_height_crouch
Definition: controller.h:80
void SetLookDirection(quat direction)
Definition: controller.h:31
void SetWallCollisionCallback(void(*callback)(ControllerComponent *, Physics::Collision))
Definition: controller.h:45
void EventHandler(Event &event)
Definition: controller.h:19
quat GetLookDirection() const
Definition: controller.h:32
bool is_in_air
Definition: controller.h:73
void Start()
Definition: controller.cpp:15
float step_height
Definition: controller.h:79
void ResetMove()
Definition: controller.cpp:255
float collision_height_crouch
Definition: controller.h:77
quat look_direction
Definition: controller.h:71
void SetCrouchSpeed(float crouch_speed)
Definition: controller.h:51
void Crouch()
Definition: controller.cpp:53
static void Update()
Updates the ControllerComponents.
Definition: controller.cpp:265
Component< PhysicsComponent > physics_body
Definition: controller.h:63
void SetCollisionGroup(uint32_t group)
Definition: controller.h:53
float crouch_speed
Definition: controller.h:84
void RecoverFromCollisions()
Definition: controller.cpp:114
Definition: entitycomponent.h:18
Definition: pool.h:14
@ COLL_PLAYER
Definition: physics.h:30
Definition: api.h:9
uint32_t id_t
Definition: core.h:11
glm::vec3 vec3
Definition: math.h:12
glm::quat quat
Definition: math.h:13
Definition: event.h:24
Definition: physics.h:35