System that processes heading and rotation physics. More...
Declaration
class helios::engine::modules::physics::motion::systems::SteeringSystem { ... }
Public Member Typedefs Index
Public Member Functions Index
| void | update (helios::engine::runtime::world::UpdateContext &updateContext) noexcept |
|
Updates the heading of entities. More...
|
|
Private Member Functions Index
| void | updateHeading (helios::engine::modules::physics::motion::components::SteeringComponent *cmp, float deltaTime) noexcept |
|
Performs the rotation physics update for a SteeringComponent. More...
|
|
Description
System that processes heading and rotation physics.
This system updates the rotation state of entities based on their SteeringComponent. It calculates the target rotation from input, applies rotation speed and dampening, and updates the RotationStateComponent and DirectionComponent.
Definition at line 40 of file SteeringSystem.ixx.
Public Member Typedefs
EngineRoleTag
| using helios::engine::modules::physics::motion::systems::SteeringSystem::EngineRoleTag = helios::engine::common::tags::SystemRole |
|
Public Member Functions
update()
Updates the heading of entities.
- Parameters
-
| updateContext | Context containing frame timing and game state. |
Definition at line 124 of file SteeringSystem.ixx.
125
126
127 for (auto [entity, hc, rsc, dc, active] : updateContext.view<
132 >().whereEnabled()) {
133
134
135 if (hc->stateChanged()) {
136 auto direction = hc->steeringInput();
138 auto rotationAngleDelta = std::fmod((targetRotationAngle - hc->currentRotationAngle()) + 540.0f, 360.0f) - 180.0f;
139
140 float turnBoostFactor = 0.5f;
141 float turnBoost = 1.0f + turnBoostFactor * std::clamp((abs(rotationAngleDelta))/180.f, 0.0f, 1.0f);
142 float currentRotationSpeed = turnBoost * hc->rotationSpeed() * hc->turnIntensity();
143
144 hc->setTargetRotationAngle(targetRotationAngle);
145 hc->setRotationAngleDelta(rotationAngleDelta);
146 hc->setCurrentRotationSpeed(currentRotationSpeed);
147
148 }
149
150 updateHeading(hc, updateContext.deltaTime());
151
152 float rotationAngle = hc->currentRotationAngle();
153 rsc->setHeadingRotationAngle(rotationAngle);
154 rsc->setHeadingRotationAxis(hc->rotationAxis());
155
157
158 if (hc->directionFromSteering()) {
160 }
161
162
163 }
164
165 }
References helios::math::degrees and helios::math::radians.
Private Member Functions
updateHeading()
Performs the rotation physics update for a SteeringComponent.
Applies dampening when input is inactive, calculates rotation steps, and snaps to target when within threshold.
- Parameters
-
| cmp | The SteeringComponent to update. Must not be nullptr. |
| deltaTime | Time elapsed since last frame in seconds. |
Definition at line 53 of file SteeringSystem.ixx.
53 void updateHeading(
55 float deltaTime
56 ) noexcept {
57
58 assert(cmp != nullptr && "Unexpected invalid SteeringComponent passed");
59 assert(deltaTime >= 0 && "Unexpected negative value for deltaTime");
60
61 if (deltaTime == 0) {
62 return;
63 }
64
69
70
71 if (!headingStateChanged) {
73
74 if (currentRotationSpeed < cmp->rotationSpeedThreshold()) {
75 currentRotationSpeed = 0.0f;
76 }
77
79 }
80
81
82 if (currentRotationSpeed > 0.0f) {
83
86
87 } else {
88 float rotationStep = std::copysign(
89 std::min(
90 std::abs(rotationAngleDelta),
91 currentRotationSpeed * deltaTime
92 ),
93 rotationAngleDelta
94 );
95 currentRotationAngle = currentRotationAngle + rotationStep;
96 }
97
98 rotationAngleDelta = std::fmod((cmp->targetRotationAngle() - currentRotationAngle) + 540.0f, 360.0f) - 180.0f;
99
100
101 if (std::abs(rotationAngleDelta) <= 0.5f) {
103 rotationAngleDelta = 0.0f;
104 currentRotationSpeed = 0.0f;
105 }
106
110 }
111
112 }
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.