Ocean
rendering/Transform.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_RENDERING_TRANSFORM_H
9 #define META_OCEAN_RENDERING_TRANSFORM_H
10 
12 #include "ocean/rendering/Group.h"
13 
15 
16 namespace Ocean
17 {
18 
19 namespace Rendering
20 {
21 
22 // Forward declaration
23 class Transform;
24 
25 /**
26  * Definition of a smart object reference holding a transform node.
27  * @see SmartObjectRef, Transform.
28  * @ingroup rendering
29  */
31 
32 /**
33  * Definition of a vector of references holding transform nods
34  * @ingroup rendering
35  */
36 typedef std::vector<TransformRef> TransformRefs;
37 
38 /**
39  * This class is the base class for all transform nodes.
40  * @ingroup rendering
41  */
42 class OCEAN_RENDERING_EXPORT Transform : virtual public Group
43 {
44  public:
45 
46  /**
47  * Definition of a modifier for transform objects.
48  * Modifiers can be applies to modify the transformation of one (or several) transformations concurrently based on the identical transformation without changing the scene graph hierarchy.<br>
49  * When applied to a transform, the transform's transformation is adjusted as followed:<br>
50  * <pre>
51  * parent_T_transform = parent_T_transform * transform_T_modifiedTransform
52  * </pre>
53  */
55  {
56  friend class Transform;
57 
58  public:
59 
60  /**
61  * Returns the transformation of this modifier.
62  * @return The transformation between the modified transform and the original transform (transform_T_modifiedTransform)
63  */
64  inline HomogenousMatrix4 transformation() const;
65 
66  /**
67  * Sets the transformation of this modifier.
68  * @param transform_T_modifiedTransform The transformation between the modified transform and the original transform, must be valid
69  */
70  inline void setTransformation(const HomogenousMatrix4& transform_T_modifiedTransform);
71 
72  protected:
73 
74  /**
75  * Creates a new modifier with identity transformation.
76  */
77  TransformModifier() = default;
78 
79  protected:
80 
81  /// The transformation of this modifier.
82  HomogenousMatrix4 parent_T_transform_ = HomogenousMatrix4(true);
83  };
84 
85  /**
86  * Definition of a shared pointer holding a TransformModifier object.
87  * @see TransformModifier.
88  */
89  typedef std::shared_ptr<TransformModifier> SharedTransformModifier;
90 
91  public:
92 
93  /**
94  * Returns the transformation of this node relative to the parent node.
95  * @return The relative transformation (parent_T_transform)
96  */
97  virtual HomogenousMatrix4 transformation() const = 0;
98 
99  /**
100  * Returns the TransformModifier object of this transform.
101  * @return The transform's modifier, nullptr if no modifier is set
102  */
104 
105  /**
106  * Sets the transformation of this node relative to the parent node.
107  * @param parent_T_transform The transformation between this node and the parent node
108  */
109  virtual void setTransformation(const HomogenousMatrix4& parent_T_transform) = 0;
110 
111  /**
112  * Sets the TransformModifier object for this transformation.
113  * @param transformModifier The TransformModifier to be set, nullptr to remove a previously set modifier
114  */
115  virtual void setTransformModifier(SharedTransformModifier transformModifier) = 0;
116 
117  /**
118  * Returns the type of this object.
119  * @see Object::type().
120  */
121  ObjectType type() const override;
122 
123  /**
124  * Creates a TransformModifier object.
125  * @return The new transform modifier object
126  */
127  static inline SharedTransformModifier createTransformModifier();
128 
129  protected:
130 
131  /**
132  * Creates a new transform node.
133  */
135 
136  /**
137  * Destructs a transform node.
138  */
139  ~Transform() override;
140 };
141 
143 {
144  ocean_assert(parent_T_transform_.isValid());
145 
146  return parent_T_transform_;
147 }
148 
150 {
151  ocean_assert(parent_T_transform.isValid());
152 
153  parent_T_transform_ = parent_T_transform;
154 }
155 
157 {
159 }
160 
161 }
162 
163 }
164 
165 #endif // META_OCEAN_RENDERING_TRANSFORM_H
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition: HomogenousMatrix4.h:1806
This is the base class for all rendering groups.
Definition: rendering/Group.h:40
ObjectType
Definition of different object type.
Definition: Object.h:63
Definition of a modifier for transform objects.
Definition: rendering/Transform.h:55
void setTransformation(const HomogenousMatrix4 &transform_T_modifiedTransform)
Sets the transformation of this modifier.
Definition: rendering/Transform.h:149
TransformModifier()=default
Creates a new modifier with identity transformation.
HomogenousMatrix4 transformation() const
Returns the transformation of this modifier.
Definition: rendering/Transform.h:142
HomogenousMatrix4 parent_T_transform_
The transformation of this modifier.
Definition: rendering/Transform.h:82
This class is the base class for all transform nodes.
Definition: rendering/Transform.h:43
ObjectType type() const override
Returns the type of this object.
virtual SharedTransformModifier transformModifier() const =0
Returns the TransformModifier object of this transform.
static SharedTransformModifier createTransformModifier()
Creates a TransformModifier object.
Definition: rendering/Transform.h:156
virtual void setTransformModifier(SharedTransformModifier transformModifier)=0
Sets the TransformModifier object for this transformation.
Transform()
Creates a new transform node.
~Transform() override
Destructs a transform node.
virtual void setTransformation(const HomogenousMatrix4 &parent_T_transform)=0
Sets the transformation of this node relative to the parent node.
virtual HomogenousMatrix4 transformation() const =0
Returns the transformation of this node relative to the parent node.
std::shared_ptr< TransformModifier > SharedTransformModifier
Definition of a shared pointer holding a TransformModifier object.
Definition: rendering/Transform.h:89
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition: HomogenousMatrix4.h:37
SmartObjectRef< Transform > TransformRef
Definition of a smart object reference holding a transform node.
Definition: rendering/Transform.h:23
std::vector< TransformRef > TransformRefs
Definition of a vector of references holding transform nods.
Definition: rendering/Transform.h:36
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15