SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
TransformRotation.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Sapphire Development Team. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_MATHS_TRANSFORM_ROTATION_GUARD
6#define SAPPHIRE_MATHS_TRANSFORM_ROTATION_GUARD
7
9
11
12
23namespace SA
24{
30 template <typename T>
32 {
35
36
37 //{ Constructors
38
40 TrRotation() = default;
41
47 TrRotation(const Quat<T>& _rot) noexcept :
48 rotation{ _rot }
49 {
50 }
51
52 //}
53
54 //{ Cast
55
62 template <typename TOut>
63 operator TrRotation<TOut>() const noexcept
64 {
66 }
67
68 //}
69
70 protected:
71
72 //{ Equals
73
79 constexpr bool IsZero() const noexcept
80 {
81 return rotation.IsZero();
82 }
83
90 constexpr bool IsIdentity() const noexcept
91 {
92 return rotation.IsIdentity();
93 }
94
103 constexpr bool Equals(const TrRotation& _other,
104 T _epsilon = std::numeric_limits<T>::epsilon()) const noexcept
105 {
106 return rotation.Equals(_other.rotation, _epsilon);
107 }
108
109 //}
110
111
112 //{ Lerp
113
123 static TrRotation LerpUnclamped(const TrRotation& _start, const TrRotation& _end, float _alpha) noexcept
124 {
125 return TrRotation{ Quat<T>::SLerpUnclamped(_start.rotation, _end.rotation, _alpha) };
126 }
127
128 //}
129
130
131 //{ Operators
132
141 template <typename RhsT>
142 static TrRotation Multiply(const TrRotation& _lhs, const RhsT& _rhs) noexcept
143 {
144 if constexpr (TrTHasComponent(RhsT)<SA::TrRotation>())
145 {
146 // Rotation component found.
147
148 return TrRotation{ _lhs.rotation * _rhs.rotation };
149 }
150 else
151 {
152 // Default: forward component (lhs always has this component).
153
154 return _lhs;
155 }
156 }
157
166 template <typename RhsT>
167 static TrRotation Divide(const TrRotation& _lhs, const RhsT& _rhs) noexcept
168 {
169 if constexpr (TrTHasComponent(RhsT)<SA::TrRotation>())
170 {
171 // Rotation component found.
172
173 return TrRotation{ _lhs.rotation / _rhs.rotation };
174 }
175 else
176 {
177 // Default: forward component (lhs always has this component).
178
179 return _lhs;
180 }
181 }
182
183 //}
184
185 #if SA_LOGGER_IMPL
186
192 std::string ToString() const
193 {
194 return "Rot: " + SA::ToString(rotation);
195 }
196
197 #endif
198
199 };
200}
201
202
205#endif // GUARD
Quaternion type implementation.
Transform Component base helper definition.
#define TrTHasComponent(_trT)
Helper macro for transform HasComponent check in templated functions.
Definition TransformComponent.hpp:21
Quaternion Sapphire-Maths class.
Definition Quaternion.hpp:53
static Quat SLerpUnclamped(const Quat &_start, const Quat &_end, float _alpha)
Unclamped SLerp from _start to _end at _alpha.
Transform rotation component.
Definition TransformRotation.hpp:32
static TrRotation Divide(const TrRotation &_lhs, const RhsT &_rhs) noexcept
Transform division implementation for rotation component.
Definition TransformRotation.hpp:167
TrRotation(const Quat< T > &_rot) noexcept
Constructor from Quat.
Definition TransformRotation.hpp:47
constexpr bool IsZero() const noexcept
IsZero component implementation.
Definition TransformRotation.hpp:79
constexpr bool IsIdentity() const noexcept
IsIdentity component implementation. rotation must be at Quat::Identity for identity transform.
Definition TransformRotation.hpp:90
constexpr bool Equals(const TrRotation &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
Equals component implementation.
Definition TransformRotation.hpp:103
static TrRotation Multiply(const TrRotation &_lhs, const RhsT &_rhs) noexcept
Transform multiplication implementation for rotation component.
Definition TransformRotation.hpp:142
TrRotation()=default
Default constructor.
static TrRotation LerpUnclamped(const TrRotation &_start, const TrRotation &_end, float _alpha) noexcept
LerpUnclamped component implementation. Use SLerp implementation.
Definition TransformRotation.hpp:123
Quat< T > rotation
Handled rotation.
Definition TransformRotation.hpp:34