Skip to main content

DirectionComponent.ixx File

Component for storing a normalized direction vector. More...

Included Headers

#include <cassert> #include <cmath> #include <helios.math>

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemodules

Domain-specific components and systems. More...

namespacephysics

Physics simulation and collision detection subsystem for the game engine. More...

namespacemotion

Motion physics components and systems. More...

namespacecomponents

Physics and movement components for game entities. More...

Classes Index

classDirectionComponent

Component that holds a normalized direction vector. More...

Description

Component for storing a normalized direction vector.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file DirectionComponent.ixx
3 * @brief Component for storing a normalized direction vector.
4 */
5module;
6
7#include <cassert>
8#include <cmath>
9
10export module helios.engine.modules.physics.motion.components.DirectionComponent;
11
12
13
14import helios.math;
15
17
18 /**
19 * @brief Component that holds a normalized direction vector.
20 *
21 * @details
22 * This component is used to store a direction for various purposes, such as
23 * movement direction, facing direction, or other vector-based properties.
24 * It enforces normalization of the stored vector.
25 */
27
28 /**
29 * @brief The stored normalized direction vector.
30 */
31 helios::math::vec3f direction_{};
32
33 /**
34 * @brief Whether this component is enabled.
35 */
36 bool isEnabled_ = true;
37
38 public:
39
40 /**
41 * @brief Checks whether this component is enabled.
42 *
43 * @return True if enabled, false otherwise.
44 */
45 [[nodiscard]] bool isEnabled() const noexcept {
46 return isEnabled_;
47 }
48
49 /**
50 * @brief Enables this component.
51 */
52 void enable() noexcept {
53 isEnabled_ = true;
54 }
55
56 /**
57 * @brief Disables this component.
58 */
59 void disable() noexcept {
60 isEnabled_ = false;
61 }
62
63 /**
64 * @brief Default constructor.
65 */
66 DirectionComponent() = default;
67
68 /**
69 * @brief Copy constructor.
70 *
71 * @param other The component to copy from.
72 */
73 DirectionComponent(const DirectionComponent& other) : direction_(other.direction()) {}
74
77 DirectionComponent& operator=(DirectionComponent&&) noexcept = default;
78
79 /**
80 * @brief Sets the direction vector.
81 *
82 * @details
83 * The provided vector must be normalized. An assertion checks this in debug builds.
84 *
85 * @param direction The new normalized direction vector.
86 */
87 void setDirection(const helios::math::vec3f direction) noexcept {
88 assert(direction.length() - 1.0f <= helios::math::EPSILON_LENGTH
89 && "direction must be normalized");
90 direction_ = direction;
91 }
92
93 /**
94 * @brief Retrieves the stored direction vector.
95 *
96 * @return The current normalized direction vector.
97 */
98 [[nodiscard]] helios::math::vec3f direction() const noexcept {
99 return direction_;
100 }
101
102 };
103}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.