Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
StaticAffineTransform.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TMatrix4.h"
4#include "Math/TVector3.h"
7
8#include <vector>
9
10namespace ph::math
11{
12
14{
16
17public:
18 static const StaticAffineTransform& IDENTITY();
19
23 template<typename U>
25
29 template<typename U>
31
37 template<typename U>
38 static StaticAffineTransform makeParentedForward(const std::vector<TDecomposedTransform<U>>& fromRootToLocal);
39
45 template<typename U>
46 static StaticAffineTransform makeParentedInverse(const std::vector<TDecomposedTransform<U>>& fromRootToLocal);
47
48public:
52
53 StaticAffineTransform(const Matrix4R& transform, const Matrix4R& inverseTransform);
54
55 virtual std::unique_ptr<Transform> genInversed() const override;
56
59
60private:
61 void transformVector(
62 const Vector3R& vector,
63 const Time& time,
64 Vector3R* out_vector) const override;
65
66 void transformOrientation(
67 const Vector3R& orientation,
68 const Time& time,
69 Vector3R* out_orientation) const override;
70
71 void transformPoint(
72 const Vector3R& point,
73 const Time& time,
74 Vector3R* out_point) const override;
75
76 void transformLineSegment(
77 const Vector3R& lineStartPos,
78 const Vector3R& lineDir,
79 real lineMinT,
80 real lineMaxT,
81 const Time& time,
82 Vector3R* out_lineStartPos,
83 Vector3R* out_lineDir,
84 real* out_lineMinT,
85 real* out_lineMaxT) const override;
86
87private:
88 Matrix4R m_transformMatrix;
89 Matrix4R m_inverseTransformMatrix;
90};
91
92template<typename U>
93inline StaticAffineTransform StaticAffineTransform
94::makeForward(const TDecomposedTransform<U>& transform)
95{
96 TMatrix4<U> transformMatrix;
97 TMatrix4<U> invTransformMatrix;
98 transform.genTransformMatrix(&transformMatrix);
99 transform.genInverseTransformMatrix(&invTransformMatrix);
100
101 return StaticAffineTransform(Matrix4R(transformMatrix), Matrix4R(invTransformMatrix));
102}
103
104template<typename U>
105inline StaticAffineTransform StaticAffineTransform
106::makeInverse(const TDecomposedTransform<U>& transform)
107{
108 TMatrix4<U> transformMatrix;
109 TMatrix4<U> invTransformMatrix;
110 transform.genInverseTransformMatrix(&transformMatrix);
111 transform.genTransformMatrix(&invTransformMatrix);
112
113 return StaticAffineTransform(Matrix4R(transformMatrix), Matrix4R(invTransformMatrix));
114}
115
116template<typename U>
117inline StaticAffineTransform StaticAffineTransform
118::makeParentedForward(const std::vector<TDecomposedTransform<U>>& fromRootToLocal)
119{
120 TMatrix4<U> parentedMatrix(TMatrix4<U>::makeIdentity());
121 TMatrix4<U> invParentedMatrix(TMatrix4<U>::makeIdentity());
122 for(const auto& transform : fromRootToLocal)
123 {
124 TMatrix4<U> matrix;
125 TMatrix4<U> invMatrix;
126 transform.genTransformMatrix(&matrix);
127 transform.genInverseTransformMatrix(&invMatrix);
128
129 parentedMatrix = parentedMatrix.mul(matrix);
130 invParentedMatrix = invMatrix.mul(invParentedMatrix);
131 }
132
133 return StaticAffineTransform(Matrix4R(parentedMatrix), Matrix4R(invParentedMatrix));
134}
135
136template<typename U>
137inline StaticAffineTransform StaticAffineTransform
138::makeParentedInverse(const std::vector<TDecomposedTransform<U>>& fromRootToLocal)
139{
140 TMatrix4<U> parentedMatrix(TMatrix4<U>::makeIdentity());
141 TMatrix4<U> invParentedMatrix(TMatrix4<U>::makeIdentity());
142 for(const auto& transform : fromRootToLocal)
143 {
144 TMatrix4<U> matrix;
145 TMatrix4<U> invMatrix;
146 transform.genInverseTransformMatrix(&matrix);
147 transform.genTransformMatrix(&invMatrix);
148
149 parentedMatrix = matrix.mul(parentedMatrix);
150 invParentedMatrix = invParentedMatrix.mul(invMatrix);
151 }
152
153 return StaticAffineTransform(Matrix4R(parentedMatrix), Matrix4R(invParentedMatrix));
154}
155
156inline const math::Matrix4R& StaticAffineTransform
157::getTransformMatrix() const
158{
159 return m_transformMatrix;
160}
161
162inline const math::Matrix4R& StaticAffineTransform
163::getInversedTransformMatrix() const
164{
165 return m_inverseTransformMatrix;
166}
167
168// FIXME: precision loss in parent (it is using real number)
169//template<typename U>
170//StaticTransform::StaticTransform(const StaticTransform& parent, const TDecomposedTransform<U>& local) :
171// StaticTransform()
172//{
173// const StaticTransform localTransform(local);
174//
175// m_transformMatrix = parent.m_transformMatrix.mul(localTransform.m_transformMatrix);
176// m_inverseTransformMatrix = localTransform.m_inverseTransformMatrix(parent.m_inverseTransformMatrix);
177//}
178
179}// end namespace ph::math
Definition Time.h:9
Definition StaticAffineTransform.h:14
static StaticAffineTransform makeParentedInverse(const std::vector< TDecomposedTransform< U > > &fromRootToLocal)
Definition StaticAffineTransform.h:138
virtual std::unique_ptr< Transform > genInversed() const override
Definition StaticAffineTransform.cpp:26
StaticAffineTransform()
Creates an identity transform.
Definition StaticAffineTransform.cpp:16
static StaticAffineTransform makeInverse(const TDecomposedTransform< U > &transform)
Definition StaticAffineTransform.h:106
const math::Matrix4R & getTransformMatrix() const
Definition StaticAffineTransform.h:157
static StaticAffineTransform makeForward(const TDecomposedTransform< U > &transform)
Definition StaticAffineTransform.h:94
const math::Matrix4R & getInversedTransformMatrix() const
Definition StaticAffineTransform.h:163
static StaticAffineTransform makeParentedForward(const std::vector< TDecomposedTransform< U > > &fromRootToLocal)
Definition StaticAffineTransform.h:118
static const StaticAffineTransform & IDENTITY()
Definition StaticAffineTransform.cpp:10
Definition StaticRigidTransform.h:19
Perform affine transformations in decomposed form.
Definition TDecomposedTransform.h:24
void genTransformMatrix(TMatrix4< T > *out_result) const
Definition TDecomposedTransform.h:154
void genInverseTransformMatrix(TMatrix4< T > *out_result) const
Definition TDecomposedTransform.h:169
TMatrix4 mul(const TMatrix4 &rhs) const
Definition TMatrix4.ipp:150
Definition Transform.h:21
void transform(const Ray &ray, Ray *out_ray) const
Definition Transform.cpp:50
Math functions and utilities.
Definition TransformInfo.h:10
TMatrix4< real > Matrix4R
Definition math_fwd.h:74