Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.hpp
More file actions
Latest commit
238 lines (188 loc) · 8.02 KB
/
Copy pathtransform.hpp
File metadata and controls
238 lines (188 loc) · 8.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#ifndef TRANSFORM_HPP
#defineTRANSFORM_HPP
#include<glm/glm.hpp>
#include<glm/gtc/matrix_transform.hpp>
#include<glm/gtc/type_ptr.hpp>
#include<iostream>
#include<memory>
#include<optional>
#include"sbpt_generated_includes.hpp"
enum TransformApplicationOrder {
ScaleTranslationRotation,
ScaleRotationTranslation,
};
/**
* @brief a transform class for translation, rotation and scale
*
* @todo Every transform should hold an optional child transform so that we can stack transforms easily.
*
* @note since we use a unique_ptr for the child transform, the default copy constructor is deleted because unique_ptrs
* don't have a copy constructor, that is why we have defined our own here
*
* @note functions that have the the word full indicate that that function accounts for the entire transform hierarchy
* of child transforms when computing the value.
*
*/
structTransform {
Transform(glm::dvec3 translation = glm::dvec3(0), glm::dvec3 rotation = glm::dvec3(0),
glm::dvec3 scale = glm::dvec3(1),
const TransformApplicationOrder &transform_application_order =
TransformApplicationOrder::ScaleRotationTranslation)
: transform_application_order(transform_application_order), position(translation), rotation(rotation),
scale(scale) {};
/**
* @brief Deep copy constructor.
*
* Creates a new Transform as a deep copy of another Transform.
* The new instance duplicates all transform data and recursively
* copies any existing child hierarchy.
*
* @param other The Transform instance to copy.
*/
Transform(const Transform &other)
: position(other.position), rotation(other.rotation), scale(other.scale),
transform_application_order(other.transform_application_order) {
// NOTE: his is recursive because the = invokes the copy assignment operator, this function just kicks off the
// recursion
if (other.child)
child = std::make_unique<Transform>(*other.child);
}
/**
* @brief Deep copy assignment operator.
*
* Assigns the contents of another Transform to this one.
* Performs a deep copy of all member variables, including the
* recursively owned child hierarchy if present.
*
* @param other The Transform instance to copy from.
* @return Reference to this Transform.
*/
Transform &operator=(const Transform &other) {
if (this == &other)
return *this;
position = other.position;
rotation = other.rotation;
scale = other.scale;
transform_application_order = other.transform_application_order;
// NOTE: recursive
child = other.child ? std::make_unique<Transform>(*other.child) : nullptr;
return *this;
}
/**
* @brief Move constructor.
*
* Transfers ownership of resources from another Transform to this one.
* The source Transform is left in a valid but unspecified state.
*
* @param other The Transform instance to move from.
*/
Transform(Transform &&other) noexcept = default;
/**
* @brief Move assignment operator.
*
* Transfers ownership of resources from another Transform to this one.
* The source Transform is left in a valid but unspecified state.
*
* @param other The Transform instance to move from.
* @return Reference to this Transform.
*/
Transform &operator=(Transform &&other) noexcept = default;
TransformApplicationOrder transform_application_order;
// startfold setters
voidset_translation_x(constdouble &x);
voidset_translation_y(constdouble &y);
voidset_translation_z(constdouble &z);
voidset_translation(constdouble &x, constdouble &y, constdouble &z);
voidset_translation(const glm::dvec3 &new_position);
voidreset_translation();
voidadd_translation(constdouble &x, constdouble &y, constdouble &z);
voidadd_translation(const glm::dvec3 &add_position);
voidset_rotation(const glm::dvec3 &pitch_yaw_roll);
// TODO: shouldn't we also just have rotation about axes, because that would be good too, but then the application
// order matters right?
voidset_rotation_pitch(constdouble &new_pitch);
voidset_rotation_yaw(constdouble &new_yaw);
voidreset_yaw();
voidreset_pitch();
voidset_rotation_roll(constdouble &new_roll);
voidadd_rotation_pitch(constdouble &pitch);
voidadd_rotation_yaw(constdouble &yaw);
voidadd_rotation_roll(constdouble &roll);
voidreset_rotation();
voidset_scale(constdouble &scale);
voidset_scale(constdouble &x, constdouble &y, constdouble &z);
voidset_scale(const glm::dvec3 &new_scale);
voidset_scale_x(constdouble &new_scale);
voidset_scale_y(constdouble &new_scale);
voidset_scale_z(constdouble &new_scale);
voidset_transform_matrix(const glm::dmat4 &matrix);
/**
* @brief sets the transform matrix overide which will be used until you clear the override
*
* the matrix override is used instead of constructing the matrix from the internal translation, scale, and rotation
* properties until it is cleared
*/
voidset_transform_matrix_override(const glm::dmat4 &transform);
voidclear_transform_matrix_override();
voidreset();
voidreset_scale();
// endfold
// startfold getters
// NOTE: missing a few of the "full" getters for certain matrices here
Transform get_inverse_transform() const;
glm::dmat4 get_transform_matrix() const;
glm::dmat4 get_full_transform_matrix() const;
// rotation
glm::dvec3 get_rotation() const { return rotation; }
glm::dvec3 get_full_rotation() const;
doubleget_rotation_pitch() const { return rotation.x; }
doubleget_full_rotation_pitch() const;
doubleget_rotation_yaw() const { return rotation.y; }
doubleget_full_rotation_yaw() const;
glm::dmat4 get_rotation_transform_matrix() const;
// scale
glm::dvec3 get_scale() const { return scale; }
glm::dvec3 get_full_scale() const;
glm::dmat4 get_scale_transform_matrix() const;
// translation
glm::dvec3 get_translation() const { return position; }
glm::dvec3 get_full_translation() const;
glm::dmat4 get_translation_transform_matrix() const;
// endfold
// directional vectors
glm::dvec3 compute_forward_vector() const;
/// @brief gets the forward vector with y component set to 0
glm::dvec3 compute_xz_forward_vector() const;
glm::dvec2 compute_xz_forward_vector_R2() const;
glm::dvec3 compute_right_vector() const;
glm::dvec3 compute_up_vector() const;
std::string to_string() const;
friend std::ostream &operator<<(std::ostream &os, const Transform &transform) {
os << transform.to_string();
return os;
}
voidset_child(Transform new_child) {
// create a new transform on the heap by moving 'new_child' into it.
child = std::make_unique<Transform>(std::move(new_child));
}
std::optional<glm::dmat4> transform_matrix_override;
std::unique_ptr<Transform> child = nullptr;
// TODO: remove this
voidupdate_transform_matrix();
// NOTE: this is here because if it's not true, then we don't have to recompute it
bool modified_since_last_call_to_get_transform_matrix;
glm::dvec3 position;
glm::dvec3 rotation; // Euler angles in turns (pitch, yaw, roll)
glm::dvec3 scale; // Scale factors
};
// this is the start of the new data oriented design. all above member functions are eventually deprecated.
voidset_position(Transform *t, glm::dvec3 position);
voidset_position_x(Transform *t, double x);
voidset_position_y(Transform *t, double y);
voidset_position_z(Transform *t, double z);
voidset_rotation(Transform *t, glm::dvec3 new_rotation);
voidset_rotation_pitch(Transform *t, double new_pitch);
voidset_rotation_yaw(Transform *t, double new_yaw);
voidset_rotation_roll(Transform *t, double new_roll);
glm::dmat4 create_billboard_transform(const Transform &transform);
#endif// TRANSFORM_HPP