utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
pose.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21*/
22
23#pragma once
24
25#include <concepts>
26
27#include "utility/graphic/orientation.hpp"
28#include "utility/graphic/position.hpp"
30
31namespace utility::graphic
32{
37 template<typename Type>
40
50 template<CanBePoseComponent PoseComponentType> class Pose
51 {
52 private:
57
62
63 public:
67 Pose(void)
68 : _position()
69 , _orientation()
70 {
71 }
78 const Orientation<PoseComponentType> &orientation)
79 : _position(position)
80 , _orientation(orientation)
81 {
82 }
83
88 Pose(const Pose &other) = default;
89
94 Pose(Pose &&other) noexcept = default;
95
101 Pose &operator=(const Pose &other) = default;
102
108 Pose &operator=(Pose &&other) noexcept = default;
109
113 ~Pose(void) = default;
114
121 {
122 _position = position;
123 return *this;
124 }
125
132 {
133 _position = Position<PoseComponentType>(position);
134 return *this;
135 }
136
141 const Position<PoseComponentType> &getPosition(void) const noexcept
142 {
143 return _position;
144 }
145
152 const Orientation<PoseComponentType> &orientation) noexcept
153 {
154 _orientation = orientation;
155 return *this;
156 }
157
164 math::Quaternion<PoseComponentType> quaternion) noexcept
165 {
166 _orientation = Orientation<PoseComponentType>(quaternion);
167 return *this;
168 }
169
175 getOrientation(void) const noexcept
176 {
177 return _orientation;
178 }
179
186 {
187 _position.translate(offset);
188 return *this;
189 }
190
196 Pose
197 translated(const Position<PoseComponentType> &offset) const noexcept
198 {
199 Pose result(*this);
200 result.translate(offset);
201 return result;
202 }
203
209 {
210 return Ray<PoseComponentType>(_position, _orientation.getForward());
211 }
212
218 {
219 return Ray<PoseComponentType>(_position, _orientation.getUp());
220 }
221
227 {
228 return Ray<PoseComponentType>(_position, _orientation.getRight());
229 }
230
236 bool operator==(const Pose &other) const noexcept
237 {
238 return _position == other._position
239 && _orientation == other._orientation;
240 }
241
247 bool operator!=(const Pose &other) const noexcept
248 {
249 return !(*this == other);
250 }
251
257 bool operator<(const Pose &other) const noexcept
258 {
259 if (_position != other._position) {
260 return _position < other._position;
261 }
262 if (_orientation != other._orientation) {
263 return _orientation < other._orientation;
264 }
265 return false;
266 }
267 };
268
272 using PoseF = Pose<float>;
273
277 using PoseD = Pose<double>;
278
285 std::ostream &operator<<(std::ostream &stream, const PoseF &pose);
286
293 std::ostream &operator<<(std::ostream &stream, const PoseD &pose);
294
295} // namespace utility::graphic
Represents the current 3D orientation (pose) of an object or view.
utility::math::Vector< OrientationComponentType, 3 > getForward(void) const noexcept
Get the forward (Z-) axis in world space.
utility::math::Vector< OrientationComponentType, 3 > getRight(void) const noexcept
Get the right (X+) axis in world space.
utility::math::Vector< OrientationComponentType, 3 > getUp(void) const noexcept
Get the up (Y+) axis in world space.
Template class representing a pose (Position + Orientation).
Definition pose.hpp:51
Pose & setOrientation(math::Quaternion< PoseComponentType > quaternion) noexcept
Set the orientation component using a quaternion.
Definition pose.hpp:163
Ray< PoseComponentType > toForwardRay() const noexcept
Get a ray representing the forward direction of the pose.
Definition pose.hpp:208
Pose & setPosition(math::Vector< PoseComponentType, 3 > position) noexcept
Set the position component using a vector.
Definition pose.hpp:131
Ray< PoseComponentType > toUpRay() const noexcept
Get a ray representing the right direction of the pose.
Definition pose.hpp:217
Pose & setPosition(const Position< PoseComponentType > &position) noexcept
Set the position component.
Definition pose.hpp:120
Pose & setOrientation(const Orientation< PoseComponentType > &orientation) noexcept
Set the orientation component.
Definition pose.hpp:151
Pose & operator=(Pose &&other) noexcept=default
Move assignment operator.
Pose(const Pose &other)=default
Copy constructor.
Pose(Pose &&other) noexcept=default
Move constructor.
Pose(const Position< PoseComponentType > &position, const Orientation< PoseComponentType > &orientation)
Construct a pose from position and orientation.
Definition pose.hpp:77
const Orientation< PoseComponentType > & getOrientation(void) const noexcept
Get the orientation component.
Definition pose.hpp:175
Pose & operator=(const Pose &other)=default
Copy assignment operator.
bool operator<(const Pose &other) const noexcept
Less-than comparison for ordering.
Definition pose.hpp:257
~Pose(void)=default
Default destructor for Pose.
Pose translated(const Position< PoseComponentType > &offset) const noexcept
Return translated copy of this pose.
Definition pose.hpp:197
bool operator==(const Pose &other) const noexcept
Equality comparison.
Definition pose.hpp:236
Pose(void)
Default constructor (zero position, identity orientation).
Definition pose.hpp:67
const Position< PoseComponentType > & getPosition(void) const noexcept
Get the position component.
Definition pose.hpp:141
bool operator!=(const Pose &other) const noexcept
Inequality comparison.
Definition pose.hpp:247
Ray< PoseComponentType > toRightRay() const noexcept
Get a ray representing the up direction of the pose.
Definition pose.hpp:226
Pose & translate(const Position< PoseComponentType > &offset) noexcept
Translate pose position by an offset.
Definition pose.hpp:185
Position in 3D space represented as a vector of three PositionComponentType components (x,...
Definition position.hpp:53
Position & translate(const Position &offset) noexcept
Translate this position by an offset.
Definition position.hpp:223
Geometric ray with arithmetic component type and fixed dimension.
Definition ray.hpp:61
Quaternion class inheriting from glm::qua.
3D vector class inheriting from glm::vec3.
Definition vector.hpp:83
Concept to constrain orientation component type.
Concept to constrain pose component type.
Definition pose.hpp:38
Concept to constrain position component type.
Definition position.hpp:43
Geometric ray template declaration.