Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TQuaternion.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math_fwd.h"
5#include "Utility/utility.h"
6
7#include <array>
8#include <cmath>
9
10namespace ph::math
11{
12
15template<typename T>
16class TQuaternion final : public TArithmeticArrayBase<TQuaternion<T>, T, 4>
17{
18private:
20
21protected:
22 using Base::m;
23
24public:
26
27public:
29
30 using Base::Base;
31
32 TQuaternion(T vx, T vy, T vz, T vw);
33
34 template<typename U>
35 explicit TQuaternion(const TQuaternion<U>& other);
36
37 template<typename U>
38 explicit TQuaternion(const std::array<U, 4>& xyzwValues);
39
40 TQuaternion(const TVector3<T>& normalizedAxis, T radians);
41 explicit TQuaternion(const TMatrix4<T>& rotationMatrix);
42
43 T& x();
44 T& y();
45 T& z();
46 T& w();
47 const T& x() const;
48 const T& y() const;
49 const T& z() const;
50 const T& w() const;
51
54 TQuaternion mul(const TVector3<T>& xyz) const;
55
56 TQuaternion normalize() const;
58 T length() const;
59
60 TQuaternion conjugate() const;
61 void conjugate(TQuaternion* out_result) const;
63
64 TQuaternion mul(const TQuaternion& rhs) const;
65 TQuaternion& mulLocal(const TQuaternion& rhs);
66 TQuaternion mul(T rhs) const;
67
68 TQuaternion sub(const TQuaternion& rhs) const;
69 TQuaternion add(const TQuaternion& rhs) const;
70 T dot(const TQuaternion& rhs) const;
71
72 void setRot(const TVector3<T>& normalizedAxis, T radians);
73 void toRotationMatrix(TMatrix4<T>* out_result) const;
74
75 using Base::set;
76 using Base::begin;
77 using Base::end;
78
79 using Base::isEqual;
80
81 using Base::toString;
82 using Base::toVector;
83 using Base::toArray;
84 using Base::toSpan;
85 using Base::toView;
86
87 using Base::operator [];
88 using Base::operator ==;
89 using Base::operator !=;
90};
91
92}// end namespace ph::math
93
94#include "Math/TQuaternion.ipp"
Definition TArithmeticArrayBase.h:20
auto begin() noexcept -> typename std::array< T, N >::iterator
Definition TArithmeticArrayBase.ipp:797
std::array< T, N > m
Definition TArithmeticArrayBase.h:217
std::vector< T > toVector() const
Definition TArithmeticArrayBase.ipp:842
std::array< T, N > toArray() const
Definition TArithmeticArrayBase.ipp:855
TSpanView< T, N > toView() const
Definition TArithmeticArrayBase.ipp:869
TQuaternion< T > & set(T value)
Definition TArithmeticArrayBase.ipp:604
auto end() noexcept -> typename std::array< T, N >::iterator
Definition TArithmeticArrayBase.ipp:811
std::string toString() const
Definition TArithmeticArrayBase.ipp:825
TSpan< T, N > toSpan()
Definition TArithmeticArrayBase.ipp:862
bool isEqual(const TQuaternion< T > &other) const
Definition TArithmeticArrayBase.ipp:646
Represents a 4x4 matrix.
Definition TMatrix4.h:17
Represents a quaternion.
Definition TQuaternion.h:17
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TQuaternion)
void toRotationMatrix(TMatrix4< T > *out_result) const
Definition TQuaternion.ipp:256
TQuaternion conjugate() const
Definition TQuaternion.ipp:173
T & x()
Definition TQuaternion.ipp:95
TQuaternion add(const TQuaternion &rhs) const
Definition TQuaternion.ipp:232
TQuaternion & mulLocal(const TQuaternion &rhs)
Definition TQuaternion.ipp:204
T & z()
Definition TQuaternion.ipp:107
T & w()
Definition TQuaternion.ipp:113
T length() const
Definition TQuaternion.ipp:167
T dot(const TQuaternion &rhs) const
Definition TQuaternion.ipp:238
void setRot(const TVector3< T > &normalizedAxis, T radians)
Definition TQuaternion.ipp:244
TQuaternion sub(const TQuaternion &rhs) const
Definition TQuaternion.ipp:226
TQuaternion & conjugateLocal()
Definition TQuaternion.ipp:188
TQuaternion normalize() const
Definition TQuaternion.ipp:153
TQuaternion & normalizeLocal()
Definition TQuaternion.ipp:159
TQuaternion(T vx, T vy, T vz, T vw)
Definition TQuaternion.ipp:20
static TQuaternion makeNoRotation()
Definition TQuaternion.ipp:14
TQuaternion mul(const TVector3< T > &xyz) const
Quaternion multiplication (treating the input's w component as 0).
Definition TQuaternion.ipp:143
T & y()
Definition TQuaternion.ipp:101
Represents a 3-D vector.
Definition TVector3.h:17
Math functions and utilities.
Definition TransformInfo.h:10