Easy3D 2.6.1
Loading...
Searching...
No Matches
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
38
39#ifndef EASY3D_RENDERER_FRAME_H
40#define EASY3D_RENDERER_FRAME_H
41
42#include <easy3d/core/types.h>
43#include "easy3d/util/signal.h"
44#include <easy3d/renderer/constraint.h>
45
46
47namespace easy3d {
48
49
50
78 class Frame {
79 public:
86 virtual ~Frame();
87
93 Frame(const Frame &frame);
100 Frame &operator=(const Frame &frame);
101
102 public:
105
113
150 vec3 position() const;
156
158
159 public:
162
170 t_ = translation;
171 modified.send();
172 }
173
178
185 void setRotation(const quat &rotation) {
186 q_ = rotation;
187 modified.send();
188 }
189
206
213 vec3 translation() const { return t_; }
220 quat rotation() const { return q_; }
221
222 public:
225
241 const Frame *referenceFrame() const { return referenceFrame_; }
248 void setReferenceFrame(const Frame* refFrame);
254 bool settingAsReferenceFrameWillCreateALoop(const Frame* const frame) const;
256
259
264 void translate(vec3 &t);
269 void translate(const vec3 &t);
274 void rotate(quat &q);
279 void rotate(const quat &q);
285 void rotateAroundPoint(quat &rotation, const vec3 &point);
291 void rotateAroundPoint(const quat &rotation, const vec3 &point);
298 void alignWithFrame(const Frame *const frame, bool move = false, float threshold = 0.0f);
304 void projectOnLine(const vec3 &origin, const vec3 &direction);
306
309
315 vec3 coordinatesOf(const vec3 &src) const;
321 vec3 inverseCoordinatesOf(const vec3 &src) const;
327 vec3 localCoordinatesOf(const vec3 &src) const;
340 vec3 coordinatesOfIn(const vec3 &src, const Frame *const in) const;
347 vec3 coordinatesOfFrom(const vec3 &src, const Frame *const from) const;
349
351 // A frame is as a new coordinate system, defined with respect to a reference
352 // frame (the world coordinate system by default, see the "Composition of
353 // frame" section).
354
355 // The transformOf() (resp. inverseTransformOf()) functions transform a 3D
356 // vector from (resp. to) the world coordinate system. This section defines
357 // the 3D vector transformation functions. See the Coordinate system
358 // transformation of 3D points above for the transformation of 3D points. The
359 // difference between the two sets of functions is simple: for vectors, only
360 // the rotational part of the transformations is taken into account, while
361 // translation is also considered for 3D points.
362
363 // The length of the resulting transformed vector is identical to the one of
364 // the source vector for all the described functions.
365
366 // When local is prepended to the names of the functions, the functions simply
367 // transform from (and to) the reference frame.
368
369 // When In (resp. From) is appended to the names, the functions transform from
370 // (resp. To) the frame that is given as an argument. The frame does not need
371 // to be in the same branch or the hierarchical tree, and can be \c NULL (the
372 // world coordinates system).
373
374 // Combining any of these functions with its inverse (in any order) leads to
375 // the identity.
377
382 vec3 transformOf(const vec3 &src) const;
388 vec3 inverseTransformOf(const vec3 &src) const;
394 vec3 localTransformOf(const vec3 &src) const;
407 vec3 transformOfIn(const vec3 &src, const Frame *const in) const;
414 vec3 transformOfFrom(const vec3 &src, const Frame *const from) const;
416
419
424 Constraint *constraint() const { return constraint_; }
425
431 void setConstraint(Constraint *const constraint) { constraint_ = constraint; }
433
434
437 public:
442 mat4 matrix() const;
452 void setFromMatrix(const mat4 &m);
453
455
458
463 Frame inverse() const;
464
475 return Frame(-(orientation().inverse_rotate(position())), orientation().inverse());
476 }
477
478
479 private:
480 // Position and orientation
481 vec3 t_;
482 quat q_;
483
484 // Constraints
485 Constraint *constraint_;
486
487 // Frame composition
488 const Frame *referenceFrame_;
489
490 public:
492 };
493
494}
495
496#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:78
void translate(vec3 &t)
Translates the Frame.
void translate(const vec3 &t)
Translates the Frame.
void projectOnLine(const vec3 &origin, const vec3 &direction)
Projects the Frame on a line.
mat4 worldMatrix() const
Returns the world transformation matrix of the Frame.
Frame worldInverse() const
Returns the inverse of the Frame's world transformation.
Definition frame.h:474
void rotateAroundPoint(const quat &rotation, const vec3 &point)
Rotates the Frame around a point.
void rotate(quat &q)
Rotates the Frame.
quat orientation() const
Returns the orientation of the Frame.
vec3 inverseCoordinatesOf(const vec3 &src) const
Transforms a 3D point from the Frame's coordinate system to the world coordinate system.
void setPositionWithConstraint(vec3 &position)
Sets the position of the Frame with constraint.
void setTranslation(const vec3 &translation)
Sets the translation of the Frame.
Definition frame.h:169
vec3 localInverseCoordinatesOf(const vec3 &src) const
Transforms a 3D point from the Frame's local coordinate system to the world coordinate system.
const Frame * referenceFrame() const
Returns the reference Frame.
Definition frame.h:241
Frame(const vec3 &position, const quat &orientation)
Constructor with position and orientation.
void setTranslationAndRotation(const vec3 &translation, const quat &rotation)
Sets the translation and rotation of the Frame.
void setOrientationWithConstraint(quat &orientation)
Sets the orientation of the Frame with constraint.
void setPositionAndOrientationWithConstraint(vec3 &position, quat &orientation)
Sets the position and orientation of the Frame with constraint.
void setFromMatrix(const mat4 &m)
Sets the Frame from a transformation matrix.
Frame inverse() const
Returns the inverse of the Frame.
vec3 coordinatesOfFrom(const vec3 &src, const Frame *const from) const
Transforms a 3D point from another Frame's coordinate system to the Frame's coordinate system.
Constraint * constraint() const
Returns the current constraint applied to the Frame.
Definition frame.h:424
vec3 localCoordinatesOf(const vec3 &src) const
Transforms a 3D point to the Frame's local coordinate system.
Frame(const Frame &frame)
Copy constructor.
void alignWithFrame(const Frame *const frame, bool move=false, float threshold=0.0f)
Aligns the Frame with another Frame.
vec3 coordinatesOfIn(const vec3 &src, const Frame *const in) const
Transforms a 3D point to another Frame's coordinate system.
void setRotationWithConstraint(quat &rotation)
Sets the rotation of the Frame with constraint.
void setRotation(const quat &rotation)
Sets the rotation of the Frame.
Definition frame.h:185
void setPositionAndOrientation(const vec3 &position, const quat &orientation)
Sets the position and orientation of the Frame.
void setTranslationWithConstraint(vec3 &translation)
Sets the translation of the Frame with constraint.
vec3 coordinatesOf(const vec3 &src) const
Transforms a 3D point to the Frame's coordinate system.
Frame()
Default constructor.
vec3 localInverseTransformOf(const vec3 &src) const
Transforms a 3D vector from the Frame's local coordinate system to the world coordinate system.
vec3 position() const
Returns the position of the Frame.
vec3 translation() const
Returns the translation of the Frame.
Definition frame.h:213
vec3 transformOf(const vec3 &src) const
Transforms a 3D vector to the Frame's coordinate system.
void setOrientation(const quat &orientation)
Sets the orientation of the Frame.
void setTranslationAndRotationWithConstraint(vec3 &translation, quat &rotation)
Sets the translation and rotation of the Frame with constraint.
mat4 matrix() const
Returns the transformation matrix of the Frame.
void setReferenceFrame(const Frame *refFrame)
Sets the reference Frame.
vec3 inverseTransformOf(const vec3 &src) const
Transforms a 3D vector from the Frame's coordinate system to the world coordinate system.
vec3 transformOfFrom(const vec3 &src, const Frame *const from) const
Transforms a 3D vector from another Frame's coordinate system to the Frame's coordinate system.
void setPosition(const vec3 &position)
Sets the position of the Frame.
Signal modified
Signal emitted when the Frame is modified.
Definition frame.h:491
void setConstraint(Constraint *const constraint)
Sets the constraint attached to the Frame.
Definition frame.h:431
bool settingAsReferenceFrameWillCreateALoop(const Frame *const frame) const
Checks if setting the reference Frame will create a loop.
virtual ~Frame()
Frame & operator=(const Frame &frame)
Assignment operator.
void rotateAroundPoint(quat &rotation, const vec3 &point)
Rotates the Frame around a point.
quat rotation() const
Returns the rotation of the Frame.
Definition frame.h:220
vec3 transformOfIn(const vec3 &src, const Frame *const in) const
Transforms a 3D vector to another Frame's coordinate system.
void rotate(const quat &q)
Rotates the Frame.
vec3 localTransformOf(const vec3 &src) const
Transforms a 3D vector to the Frame's local coordinate system.
A light-weight implementation of the simple signal-slot mechanism.
Definition signal.h:54
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
Quat< float > quat
A quaternion of float type.
Definition types.h:85
Mat4< float > mat4
A 4 by 4 matrix of float type.
Definition types.h:67