Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
StaticRigidTransform.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <Common/assertion.h>
8#include <Common/logging.h>
9
10namespace ph::math
11{
12
14
19{
20public:
21 static const StaticRigidTransform& IDENTITY();
22
23 template<typename U>
25
26 template<typename U>
28
29 template<typename U>
30 static StaticRigidTransform makeParentedForward(const std::vector<TDecomposedTransform<U>>& fromRootToLocal);
31
32 template<typename U>
33 static StaticRigidTransform makeParentedInverse(const std::vector<TDecomposedTransform<U>>& fromRootToLocal);
34
35public:
39
40private:
41 void transformVector(
42 const Vector3R& vector,
43 const Time& time,
44 Vector3R* out_vector) const override;
45
46 void transformOrientation(
47 const Vector3R& orientation,
48 const Time& time,
49 Vector3R* out_orientation) const override;
50
51 void transformPoint(
52 const Vector3R& point,
53 const Time& time,
54 Vector3R* out_point) const override;
55
56 void transformLineSegment(
57 const Vector3R& lineStartPos,
58 const Vector3R& lineDir,
59 real lineMinT,
60 real lineMaxT,
61 const Time& time,
62 Vector3R* out_lineStartPos,
63 Vector3R* out_lineDir,
64 real* out_lineMinT,
65 real* out_lineMaxT) const override;
66
67private:
68 StaticAffineTransform m_staticTransform;
69
71
72 template<typename U>
73 static inline std::vector<TDecomposedTransform<U>> getScaleFreeTransforms(
74 const std::vector<TDecomposedTransform<U>>& transforms);
75};
76
77template<typename U>
80{
81 return StaticRigidTransform(StaticAffineTransform::makeForward(getScaleFreeTransforms<U>({transform})[0]));
82}
83
84template<typename U>
87{
88 return StaticRigidTransform(StaticAffineTransform::makeInverse(getScaleFreeTransforms<U>({transform})[0]));
89}
90
91template<typename U>
92inline auto StaticRigidTransform::makeParentedForward(const std::vector<TDecomposedTransform<U>>& fromRootToLocal)
94{
95 return StaticRigidTransform(StaticAffineTransform::makeParentedForward(getScaleFreeTransforms<U>({fromRootToLocal})));
96}
97
98template<typename U>
99inline auto StaticRigidTransform::makeParentedInverse(const std::vector<TDecomposedTransform<U>>& fromRootToLocal)
101{
102 return StaticRigidTransform(StaticAffineTransform::makeParentedInverse(getScaleFreeTransforms<U>({fromRootToLocal})));
103}
104
105template<typename U>
106inline auto StaticRigidTransform::getScaleFreeTransforms(const std::vector<TDecomposedTransform<U>>& transforms)
107 -> std::vector<TDecomposedTransform<U>>
108{
109 std::vector<TDecomposedTransform<U>> scaleFreeTransforms;
110 for(const auto& transform : transforms)
111 {
112 // FIXME: better scale tolerance value, not hardcoded like this
113 if(!transform.hasScaleEffect(0.000001_r))
114 {
115 scaleFreeTransforms.push_back(transform);
116 }
117 else
118 {
119 PH_LOG(StaticRigidTransform, Warning,
120 "scale effect detected, which is {}, ignoring", transform.getScale().toString());
121
122 scaleFreeTransforms.push_back(TDecomposedTransform<U>(transform).setScale(1));
123 }
124 }
125
126 PH_ASSERT(scaleFreeTransforms.size() == transforms.size());
127
128 return scaleFreeTransforms;
129}
130
131}// end namespace ph::math
Definition Time.h:9
Definition RigidTransform.h:14
Definition StaticAffineTransform.h:14
static StaticAffineTransform makeParentedInverse(const std::vector< TDecomposedTransform< U > > &fromRootToLocal)
Definition StaticAffineTransform.h:138
static StaticAffineTransform makeInverse(const TDecomposedTransform< U > &transform)
Definition StaticAffineTransform.h:106
static StaticAffineTransform makeForward(const TDecomposedTransform< U > &transform)
Definition StaticAffineTransform.h:94
static StaticAffineTransform makeParentedForward(const std::vector< TDecomposedTransform< U > > &fromRootToLocal)
Definition StaticAffineTransform.h:118
Definition StaticRigidTransform.h:19
static StaticRigidTransform makeInverse(const TDecomposedTransform< U > &transform)
static StaticRigidTransform makeParentedForward(const std::vector< TDecomposedTransform< U > > &fromRootToLocal)
static StaticRigidTransform makeForward(const TDecomposedTransform< U > &transform)
StaticRigidTransform()
Creates an identity transform.
Definition StaticRigidTransform.cpp:12
static StaticRigidTransform makeParentedInverse(const std::vector< TDecomposedTransform< U > > &fromRootToLocal)
static const StaticRigidTransform & IDENTITY()
Definition StaticRigidTransform.cpp:6
Perform affine transformations in decomposed form.
Definition TDecomposedTransform.h:24
void transform(const Ray &ray, Ray *out_ray) const
Definition Transform.cpp:50
Math functions and utilities.
Definition TransformInfo.h:10
PH_DEFINE_EXTERNAL_LOG_GROUP(StaticRigidTransform, Math)