Easy3D 2.5.3
frame.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
39#ifndef EASY3D_RENDERER_FRAME_H
40#define EASY3D_RENDERER_FRAME_H
41
42#include <easy3d/core/types.h>
43#include <easy3d/core/signal.h>
44#include <easy3d/renderer/constraint.h>
45
46
47namespace easy3d {
48
49
152 class Frame {
153 public:
154 Frame();
156 virtual ~Frame();
157
158 Frame(const Frame &frame);
159 Frame &operator=(const Frame &frame);
160
161 public:
164 Frame(const vec3 &position, const quat &orientation);
165
166 void setPosition(const vec3 &position);
167
169
170 void setOrientation(const quat &orientation);
171
173
175 const quat &orientation);
176
179
180 vec3 position() const;
181
182 quat orientation() const;
183
185
186 public:
196 t_ = translation;
197 modified.send();
198 }
199
201
212 void setRotation(const quat &rotation) {
213 q_ = rotation;
214 modified.send();
215 }
216
218
220
222
230 vec3 translation() const { return t_; }
239 quat rotation() const { return q_; }
240
241 public:
262 const Frame *referenceFrame() const { return referenceFrame_; }
263
264 void setReferenceFrame(const Frame *const refFrame);
265
266 bool settingAsReferenceFrameWillCreateALoop(const Frame *const frame);
268
271 void translate(vec3 &t);
272
273 void translate(const vec3 &t);
274
275 void rotate(quat &q);
276
277 void rotate(const quat &q);
278
279 void rotateAroundPoint(quat &rotation, const vec3 &point);
280
281 void rotateAroundPoint(const quat &rotation, const vec3 &point);
282
283 void alignWithFrame(const Frame *const frame, bool move = false,
284 float threshold = 0.0f);
285
286 void projectOnLine(const vec3 &origin, const vec3 &direction);
288
291 vec3 coordinatesOf(const vec3 &src) const;
292
293 vec3 inverseCoordinatesOf(const vec3 &src) const;
294
295 vec3 localCoordinatesOf(const vec3 &src) const;
296
297 vec3 localInverseCoordinatesOf(const vec3 &src) const;
298
299 vec3 coordinatesOfIn(const vec3 &src, const Frame *const in) const;
300
301 vec3 coordinatesOfFrom(const vec3 &src, const Frame *const from) const;
303
305 // A frame is as a new coordinate system, defined with respect to a reference
306 // frame (the world coordinate system by default, see the "Composition of
307 // frame" section).
308
309 // The transformOf() (resp. inverseTransformOf()) functions transform a 3D
310 // vector from (resp. to) the world coordinate system. This section defines
311 // the 3D vector transformation functions. See the Coordinate system
312 // transformation of 3D points above for the transformation of 3D points. The
313 // difference between the two sets of functions is simple: for vectors, only
314 // the rotational part of the transformations is taken into account, while
315 // translation is also considered for 3D points.
316
317 // The length of the resulting transformed vector is identical to the one of
318 // the source vector for all the described functions.
319
320 // When local is prepended to the names of the functions, the functions simply
321 // transform from (and to) the reference frame.
322
323 // When In (resp. From) is appended to the names, the functions transform from
324 // (resp. To) the frame that is given as an argument. The frame does not need
325 // to be in the same branch or the hierarchical tree, and can be \c NULL (the
326 // world coordinates system).
327
328 // Combining any of these functions with its inverse (in any order) leads to
329 // the identity.
331 vec3 transformOf(const vec3 &src) const;
332
333 vec3 inverseTransformOf(const vec3 &src) const;
334
335 vec3 localTransformOf(const vec3 &src) const;
336
337 vec3 localInverseTransformOf(const vec3 &src) const;
338
339 vec3 transformOfIn(const vec3 &src, const Frame *const in) const;
340
341 vec3 transformOfFrom(const vec3 &src, const Frame *const from) const;
343
353 Constraint *constraint() const { return constraint_; }
354
359 void setConstraint(Constraint *const constraint) { constraint_ = constraint; }
361
362
365 public:
366 mat4 matrix() const;
367
368 mat4 worldMatrix() const;
369
370 void setFromMatrix(const mat4 &m);
371
373
376 Frame inverse() const;
377
389 return Frame(-(orientation().inverse_rotate(position())), orientation().inverse());
390 }
392
393 private:
394 // P o s i t i o n a n d o r i e n t a t i o n
395 vec3 t_;
396 quat q_;
397
398 // C o n s t r a i n t s
399 Constraint *constraint_;
400
401 // F r a m e c o m p o s i t i o n
402 const Frame *referenceFrame_;
403
404 public:
405 Signal<> modified;
406 };
407
408}
409
410#endif // EASY3D_RENDERER_FRAME_H
An interface class for Frame constraints.
Definition: constraint.h:140
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:152
void translate(vec3 &t)
Definition: frame.cpp:281
void projectOnLine(const vec3 &origin, const vec3 &direction)
Definition: frame.cpp:830
mat4 worldMatrix() const
Definition: frame.cpp:201
Frame worldInverse() const
Definition: frame.h:388
virtual ~Frame()
void rotate(quat &q)
Definition: frame.cpp:305
quat orientation() const
Definition: frame.cpp:419
vec3 inverseCoordinatesOf(const vec3 &src) const
Definition: frame.cpp:583
void setPositionWithConstraint(vec3 &position)
Definition: frame.cpp:492
void setTranslation(const vec3 &translation)
Definition: frame.h:195
vec3 localInverseCoordinatesOf(const vec3 &src) const
Definition: frame.cpp:607
const Frame * referenceFrame() const
Definition: frame.h:262
void setTranslationAndRotation(const vec3 &translation, const quat &rotation)
Definition: frame.cpp:387
void setOrientationWithConstraint(quat &orientation)
Definition: frame.cpp:502
void setPositionAndOrientationWithConstraint(vec3 &position, quat &orientation)
Definition: frame.cpp:511
void setFromMatrix(const mat4 &m)
Definition: frame.cpp:241
Frame inverse() const
Definition: frame.cpp:167
vec3 coordinatesOfFrom(const vec3 &src, const Frame *const from) const
Definition: frame.cpp:615
Constraint * constraint() const
Definition: frame.h:353
vec3 localCoordinatesOf(const vec3 &src) const
Definition: frame.cpp:598
void alignWithFrame(const Frame *const frame, bool move=false, float threshold=0.0f)
Definition: frame.cpp:757
vec3 coordinatesOfIn(const vec3 &src, const Frame *const in) const
Definition: frame.cpp:628
void setRotationWithConstraint(quat &rotation)
Definition: frame.cpp:451
void setRotation(const quat &rotation)
Definition: frame.h:212
bool settingAsReferenceFrameWillCreateALoop(const Frame *const frame)
Definition: frame.cpp:550
void setPositionAndOrientation(const vec3 &position, const quat &orientation)
Definition: frame.cpp:369
void setTranslationWithConstraint(vec3 &translation)
Definition: frame.cpp:437
vec3 coordinatesOf(const vec3 &src) const
Definition: frame.cpp:571
Frame()
Definition: frame.cpp:51
vec3 localInverseTransformOf(const vec3 &src) const
Definition: frame.cpp:693
vec3 position() const
Definition: frame.cpp:410
void setReferenceFrame(const Frame *const refFrame)
Definition: frame.cpp:537
vec3 translation() const
Definition: frame.h:230
vec3 transformOf(const vec3 &src) const
Definition: frame.cpp:656
void setOrientation(const quat &orientation)
Definition: frame.cpp:400
void setTranslationAndRotationWithConstraint(vec3 &translation, quat &rotation)
Definition: frame.cpp:466
mat4 matrix() const
Definition: frame.cpp:141
vec3 inverseTransformOf(const vec3 &src) const
Definition: frame.cpp:668
vec3 transformOfFrom(const vec3 &src, const Frame *const from) const
Definition: frame.cpp:701
void setPosition(const vec3 &position)
Definition: frame.cpp:357
void setConstraint(Constraint *const constraint)
Definition: frame.h:359
Frame & operator=(const Frame &frame)
Definition: frame.cpp:68
void rotateAroundPoint(quat &rotation, const vec3 &point)
Definition: frame.cpp:325
quat rotation() const
Definition: frame.h:239
vec3 transformOfIn(const vec3 &src, const Frame *const in) const
Definition: frame.cpp:714
vec3 localTransformOf(const vec3 &src) const
Definition: frame.cpp:684
A light-weight implementation of the simple signal-slot mechanism.
Definition: signal.h:56
void send(Args... p)
Calls all connected functions.
Definition: signal.h:160
Definition: collider.cpp:182