Skip to main content

YawPitchRollUpdateSystem.ixx File

System that converts yaw/pitch/roll angles to local rotation quaternions. More...

Included Headers

#include <cmath> #include <numbers> #include <helios.engine.core.types.ComponentTypeTags> #include <helios.math> #include <helios.engine.spatial.components> #include <helios.ecs.components> #include <helios.engine.runtime.world.UpdateContext> #include <helios.engine.runtime.world.tags.SystemRole>

Namespaces Index

namespacehelios
namespaceengine
namespacescene
namespacesystems

Classes Index

classYawPitchRollUpdateSystem<TMemberHandle>

Updates Rotation3DComponent<..., Local> from YawPitchRollComponent. More...

Description

System that converts yaw/pitch/roll angles to local rotation quaternions.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cmath>
8#include <numbers>
9
10export module helios.engine.spatial.systems.YawPitchRollUpdateSystem;
11
12import helios.engine.runtime.world.tags.SystemRole;
13
14import helios.engine.runtime.world.UpdateContext;
15
16import helios.ecs.components;
17import helios.engine.spatial.components;
18
19
20import helios.math;
21import helios.engine.core.types.ComponentTypeTags;
22
23using namespace helios::engine::core::types;
24using namespace helios::ecs::components;
28export namespace helios::engine::scene::systems {
29
35 template<typename TMemberHandle>
37
44 [[nodiscard]] float wrapRad(float a) const noexcept {
45 constexpr float pi = std::numbers::pi_v<float>;
46 constexpr float twoPi = 2.0f * pi;
47 return std::fmod(std::fmod(a + pi, twoPi) + twoPi, twoPi) - pi;
48 }
49
50 public:
51
56
66
67
68 for (auto [entity, yawPitchRoll, localRotation, active] : updateContext.view<
73 >().whereEnabled()) {
74 constexpr auto x = helios::math::X_AXISf;
75 constexpr auto y = helios::math::Y_AXISf;
76 constexpr auto z = helios::math::Z_AXISf;
77
78 const auto yaw = wrapRad(yawPitchRoll->yaw);
79 const auto pitch = wrapRad(yawPitchRoll->pitch);
80 const auto roll = wrapRad(yawPitchRoll->roll);
81
82 const auto qYaw = helios::math::quatf::fromAxisAngle(y, yaw);
83 const auto qPitch = helios::math::quatf::fromAxisAngle(x, pitch);
84 const auto qRoll = helios::math::quatf::fromAxisAngle(z, roll);
85
86 localRotation->setValue(qYaw * qPitch * qRoll);
87
88 }
89
90 }
91
92
93 };
94}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.