28#include "utility/math/matrix.hpp"
29#include "utility/math/quaternion.hpp"
30#include "utility/math/vector.hpp"
32namespace utility::graphic
39 template<
typename Type>
52 template<CanBeOrientationComponent OrientationComponentType>
64 OrientationComponentType(0), OrientationComponentType(0),
65 OrientationComponentType(0), OrientationComponentType(1))
99 Orientation(OrientationComponentType x, OrientationComponentType y,
100 OrientationComponentType z, OrientationComponentType w)
111 Orientation(std::initializer_list<OrientationComponentType> values)
113 OrientationComponentType(0), OrientationComponentType(0),
114 OrientationComponentType(0), OrientationComponentType(1))
116 if (values.size() != 4) {
117 throw std::invalid_argument(
118 "Orientation requires exactly four components");
120 const auto it = values.begin();
133 const std::initializer_list<OrientationComponentType> &value)
178 this->x, this->y, this->z, this->w)
180 OrientationComponentType(0), OrientationComponentType(0),
181 OrientationComponentType(-1) });
193 this->x, this->y, this->z, this->w)
195 OrientationComponentType(0), OrientationComponentType(1),
196 OrientationComponentType(0) });
208 this->x, this->y, this->z, this->w)
210 OrientationComponentType(1), OrientationComponentType(0),
211 OrientationComponentType(0) });
225 this->x, this->y, this->z, this->w)
250 parent.x, parent.y, parent.z, parent.w)
252 this->x, this->y, this->z, this->w));
268 this->x, this->y, this->z, this->w)));
279 utility::math::normalize(
281 OrientationComponentType
> &>(*
this))));
292 utility::math::inverse(
294 OrientationComponentType
> &>(*
this))));
303 OrientationComponentType { 1e-6 })
const noexcept
305 return std::abs(this->x) <= epsilon && std::abs(this->y) <= epsilon
306 && std::abs(this->z) <= epsilon
307 && std::abs(this->w - OrientationComponentType { 1 })
318 if (this->x != other.x) {
321 if (this->y != other.y) {
324 if (this->z != other.z) {
327 if (this->w != other.w) {
340 return !(*
this == other);
351 if (this->x != other.x) {
352 return this->x < other.x;
354 if (this->y != other.y) {
355 return this->y < other.y;
357 if (this->z != other.z) {
358 return this->z < other.z;
360 if (this->w != other.w) {
361 return this->w < other.w;
370 using OrientationF = Orientation<float>;
375 using OrientationD = Orientation<double>;
383 std::ostream &operator<<(std::ostream &stream,
384 const OrientationF &orientation);
392 std::ostream &operator<<(std::ostream &stream,
393 const OrientationD &orientation);
Represents the current 3D orientation (pose) of an object or view.
Orientation(Orientation &&other) noexcept=default
Move constructor.
Orientation inversed(void) const noexcept
Return inverse orientation.
Orientation(const std::initializer_list< OrientationComponentType > &value)
Construct from a const initializer list of three PositionComponentType values.
Orientation(OrientationComponentType value)
Construct by filling all components with the same OrientationComponentType value.
bool operator==(const Orientation &other) const noexcept
Equality operator for Orientation.
Orientation(OrientationComponentType x, OrientationComponentType y, OrientationComponentType z, OrientationComponentType w)
Construct from explicit quaternion components (xyzw order).
Orientation & operator=(Orientation &&other) noexcept=default
Move assignment operator.
Orientation(void)
Default constructor (identity orientation).
bool operator<(const Orientation &other) const noexcept
Less-than operator for Orientation.
Orientation(std::initializer_list< OrientationComponentType > values)
Construct from initializer list of three PositionComponentType values.
utility::math::Vector< OrientationComponentType, 3 > getForward(void) const noexcept
Get the forward (Z-) axis in world space.
bool operator!=(const Orientation &other) const noexcept
Inequality operator for Orientation.
~Orientation(void)=default
Default destructor for Orientation.
Orientation(const Orientation &other)=default
Copy constructor.
utility::math::Vector< OrientationComponentType, 3 > getRight(void) const noexcept
Get the right (X+) axis in world space.
math::Matrix4x4F toRotationMatrix(void) const noexcept
Convert the orientation to a 4x4 rotation matrix.
utility::math::Vector< OrientationComponentType, 3 > rotateVector(const utility::math::Vector< OrientationComponentType, 3 > &direction) const noexcept
Rotate a direction vector by this orientation.
Orientation normalized(void) const noexcept
Return a normalized orientation.
Orientation(const utility::math::Quaternion< OrientationComponentType > &quaternion)
Construct from a quaternion.
utility::math::Vector< OrientationComponentType, 3 > getUp(void) const noexcept
Get the up (Y+) axis in world space.
Orientation & operator=(const Orientation &other)=default
Copy assignment operator.
bool isIdentity(OrientationComponentType epsilon=OrientationComponentType { 1e-6 }) const noexcept
Check whether this is approximately the identity orientation.
Orientation combined(const Orientation &parent) const noexcept
Combine with another orientation (parent * this).
utility::math::Vector< OrientationComponentType, 3 > transformPoint(const utility::math::Vector< OrientationComponentType, 3 > &local) const noexcept
Transform a point from local to world space.
M x N matrix class inheriting from glm::mat<Cols, Rows, Type>.
Quaternion class inheriting from glm::qua.
Quaternion()
Default constructor (identity quaternion).
3D vector class inheriting from glm::vec3.
Concept to constrain orientation component type.
The utility namespace contains classes and functions for the utility project.