Move2DComponent.ixx File
Component for 2D physics-based movement . More...
Included Headers
#include <algorithm>
#include <cassert>
#include <cmath>
#include <memory>
#include <helios.engine.modules.scene.components.SceneNodeComponent>
#include <helios.engine.ecs.GameObject>
#include <helios.math>
#include <helios.core.units.Unit>
#include <helios.core.spatial.Transform>
#include <helios.util.Guid>
#include <helios.scene.SceneNode>
Namespaces Index
| namespace | helios |
| namespace | engine |
|
Main engine module aggregating core infrastructure and game systems. More... | |
| namespace | modules |
|
Domain-specific components and systems. More... | |
| namespace | physics |
|
Physics simulation and collision detection subsystem for the game engine. More... | |
| namespace | motion |
|
Motion physics components and systems. More... | |
| namespace | components |
|
Physics and movement components for game entities. More... | |
Classes Index
| class | Move2DComponent |
|
Component for 2D physics-based movement. More... | |
Description
Component for 2D physics-based movement .
File Listing
The file content with the documentation metadata removed is:
24export namespace helios::engine::modules::physics::motion::components {
43 class Move2DComponent {
56 static constexpr float DEFAULT_MOVEMENT_SPEED_THRESHOLD = 0.1f;
62 static constexpr float DEFAULT_MOVEMENT_ACCELERATION = 30.0f;
67 static constexpr float DEFAULT_MOVEMENT_SPEED = 30.0f;
73 static constexpr float DEFAULT_MOVEMENT_DAMPENING = 0.1f;
93 float movementSpeed_ = DEFAULT_MOVEMENT_SPEED;
108 float currentMovementSpeed_ = 0.0f;
113 bool stateChanged_ = true;
144 bool useInstantAcceleration_ = false;
149 bool isEnabled_ = true;
155 currentMovementSpeed_ = 0.0f;
156 stateChanged_ = true;
157 throttle_ = 0.0f;
158 direction_ = {};
159 velocity_ = {};
160 inheritedVelocity_ = {};
171 return isEnabled_;
178 isEnabled_ = true;
185 isEnabled_ = false;
191 Move2DComponent() = default;
199 explicit Move2DComponent(
200 float movementSpeed,
201 float movementAcceleration = DEFAULT_MOVEMENT_ACCELERATION
212 explicit Move2DComponent(
213 float movementSpeed,
214 bool useInstantAcceleration
224 Move2DComponent(const Move2DComponent& other) :
225 useInstantAcceleration_(other.useInstantAcceleration_),
226 movementSpeed_(other.movementSpeed_),
227 movementSpeedThreshold_(other.movementSpeedThreshold_),
228 movementAcceleration_ (other.movementAcceleration_),
229 movementDampening_ (other.movementDampening_)
232 Move2DComponent& operator=(const Move2DComponent&) = default;
233 Move2DComponent(Move2DComponent&&) noexcept = default;
234 Move2DComponent& operator=(Move2DComponent&&) noexcept = default;
246 setMoveIntent(direction, throttle);
255 void setMoveIntent(helios::math::vec3f direction, float throttle) {
257 if (throttle <= helios::math::EPSILON_LENGTH) {
258 direction_ = helios::math::vec2f{0.0f, 0.0f};
259 throttle_ = 0.0f;
260 stateChanged_ = false;
264 direction_ = direction.toVec2();
267 assert(direction_.isNormalized() && "Unexpected direction vector - not normalized");
269 stateChanged_ = true;
271 currentMovementSpeed_ = movementSpeed_ * throttle_;
280 reset();
289 reset();
297 [[nodiscard]] bool useInstantAcceleration() const noexcept {
298 return useInstantAcceleration_;
306 void setUseInstantAcceleration(const bool useInstantAcceleration) noexcept {
324 [[nodiscard]] helios::math::vec3f inheritedVelocity() const noexcept {
325 return inheritedVelocity_;
333 void setVelocity(helios::math::vec3f velocity) noexcept {
342 [[nodiscard]] float currentMovementSpeed() const noexcept {
343 return currentMovementSpeed_;
351 void setCurrentMovementSpeed(float speed) noexcept {
352 currentMovementSpeed_ = speed;
360 [[nodiscard]] bool stateChanged() const noexcept {
361 return stateChanged_;
369 [[nodiscard]] const helios::math::vec2f& direction() const noexcept {
370 return direction_;
379 return throttle_;
387 [[nodiscard]] const helios::math::vec3f& velocity() const noexcept {
388 return velocity_;
396 [[nodiscard]] float speedRatio() const noexcept {
398 if (std::abs(movementSpeed_) < helios::math::EPSILON_LENGTH) {
401 return velocity_.length() / movementSpeed_;
413 [[nodiscard]] float movementSpeedThreshold() const noexcept { return movementSpeedThreshold_; }
420 [[nodiscard]] float movementAcceleration() const noexcept { return movementAcceleration_; }
427 [[nodiscard]] float movementSpeed() const noexcept { return movementSpeed_; }
434 [[nodiscard]] float movementDampening() const noexcept { return movementDampening_; }
446 void setMovementSpeedThreshold(float value) noexcept { movementSpeedThreshold_ = value; }
454 void setMovementAcceleration(float value) noexcept { movementAcceleration_ = value; }
461 void setMovementSpeed(float value) noexcept { movementSpeed_ = value; }
468 void setMovementDampening(float value) noexcept { movementDampening_ = value; }
477 void resetToDefaults() noexcept {
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.