Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SbRotation.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2018 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23#ifndef _SB_ROTATION_
24#define _SB_ROTATION_
25
26#include <Inventor/SbVec.h>
27
28class SbRotationd;
29class SbMatrix;
30class SbMatrix3;
31class SbMatrixd;
32
34//
35// Class: SbRotation
36//
37// Rotation specfication. It is stored internally as a quaternion,
38// which has 4 floating-point components.
39//
41
42
43
127public:
128
133 { setValue(0.0f, 0.0f, 0.0f, 1.0f);}
134
140 SbRotation(const float v[4])
141 { setValue(v); }
142
148 SbRotation(float q0, float q1, float q2, float q3)
149 { setValue(q0, q1, q2, q3); }
150
156 { setValue(m); }
157
163 { setValue(m); }
164
169 SbRotation(const SbVec3f &axis, float radians)
170 { setValue(axis, radians); }
171
178 SbRotation(const SbVec3f &rotateFrom, const SbVec3f &rotateTo)
179 { setValue(rotateFrom, rotateTo); }
180
184 const float * getValue() const
185 { return (quat); }
186
191 void getValue(float &q0, float &q1,
192 float &q2, float &q3) const;
193
198 void getValue(SbVec3f &axis, float &radians) const;
199
204 void getValue(SbMatrix &matrix) const;
205
210 void getValue(SbMatrix3 &matrix) const;
211
216 void getValue(SbMatrixd &matrix) const;
217
222
227 { SbRotation q = *this; return q.invert(); }
228
232 SbRotation &setValue(const float q[4]);
233
237 SbRotation &setValue(float q0, float q1, float q2, float q3);
238
243
248
252 SbRotation &setValue(const SbVec3f &axis, float radians);
253
258 SbRotation &setValue(const SbVec3f &rotateFrom,
259 const SbVec3f &rotateTo);
260
264 SbRotation &setValue(const SbRotationd &rotated) ;
265
270
275
279 friend int operator ==(const SbRotation &q1, const SbRotation &q2);
283 friend int operator !=(const SbRotation &q1, const SbRotation &q2)
284 { return !(q1 == q2); }
285
290 SbBool equals(const SbRotation &r, float tolerance) const;
291
295 friend SbRotation operator *(const SbRotation &q1, const SbRotation &q2);
296
300 void multVec(const SbVec3f &src, SbVec3f &dst) const;
301
306 void scaleAngle( float scaleFactor );
307
312 static SbRotation slerp(const SbRotation &rot0,
313 const SbRotation &rot1, float t);
314
319 { return SbRotation(0.0f, 0.0f, 0.0f, 1.0f); }
320
321private:
322 mutable float quat[4]; // Storage for quaternion components
323
324 // Returns the norm (square of the 4D length) of a rotation's quaterion
325 float norm() const;
326
327 // Normalizes a rotation quaternion to unit 4D length
328 void normalize() const;
329
330};
331
333//
334// Class: SbRotationd
335//
336// Rotation specfication. It is stored internally as a quaternion,
337// which has 4 double precision floating-point components.
338//
340
426public:
427
432 { setValue(0.0, 0.0, 0.0, 1.0); }
433
439 SbRotationd(const double v[4])
440 { setValue(v); }
441
447 SbRotationd(double q0, double q1, double q2, double q3)
448 { setValue(q0, q1, q2, q3); }
449
455 { setValue(m); }
456
462 { setValue(m); }
463
468 SbRotationd(const SbVec3d &axis, double radians)
469 { setValue(axis, radians); }
470
477 SbRotationd(const SbVec3d &rotateFrom, const SbVec3d &rotateTo)
478 { setValue(rotateFrom, rotateTo); }
479
483 const double *getValue() const
484 { return (quat); }
485
490 void getValue(double &q0, double &q1,
491 double &q2, double &q3) const;
492
497 void getValue(SbVec3d &axis, double &radians) const;
498
503 void getValue(SbMatrixd &matrix) const;
504
509 void getValue(SbMatrix &matrix) const;
510
515 void getValue(SbMatrix3 &matrix) const;
516
521
526 { SbRotationd q = *this; return q.invert(); }
527
531 SbRotationd &setValue(const double q[4]);
532
536 SbRotationd &setValue(double q0, double q1, double q2, double q3);
537
542
546 SbRotationd &setValue(const SbVec3d &axis, double radians);
547
552 SbRotationd &setValue(const SbVec3d &rotateFrom,
553 const SbVec3d &rotateTo);
554
559
564
569
574
578 friend int operator ==(const SbRotationd &q1, const SbRotationd &q2);
582 friend int operator !=(const SbRotationd &q1, const SbRotationd &q2)
583 { return !(q1 == q2); }
584
589 SbBool equals(const SbRotationd &r, double tolerance) const;
590
594 friend SbRotationd operator *(const SbRotationd &q1, const SbRotationd &q2);
595
599 void multVec(const SbVec3d &src, SbVec3d &dst) const;
600
605 void scaleAngle( double scaleFactor );
606
611 static SbRotationd slerp(const SbRotationd &rot0,
612 const SbRotationd &rot1, double t);
613
618 { return SbRotationd(0.0, 0.0, 0.0, 1.0); }
619
620private:
621 double quat[4]; // Storage for quaternion components
622
623 // Returns the norm (square of the 4D length) of a rotation's quaterion
624 double norm() const;
625
626 // Normalizes a rotation quaternion to unit 4D length
627 void normalize();
628
629};
630
631#endif /* _SB_ROTATION_ */
632
633
3x3 matrix class.
Definition SbMatrix.h:1186
4x4 matrix class.
Definition SbMatrix.h:309
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 4x4 matrix class...
Definition SbMatrix.h:756
Class for representing a rotation.
Definition SbRotation.h:126
SbRotation & setValue(const SbRotationd &rotated)
Sets rotation from a double precision rotation.
friend int operator==(const SbRotation &q1, const SbRotation &q2)
Equality comparison operator.
SbRotation & setValue(const SbVec3f &rotateFrom, const SbVec3f &rotateTo)
Sets rotation to rotate one direction vector to another.
SbRotation()
Default constructor.
Definition SbRotation.h:132
static SbRotation slerp(const SbRotation &rot0, const SbRotation &rot1, float t)
Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1.
void getValue(SbMatrix &matrix) const
Returns corresponding 4x4 rotation matrix.
SbRotation(const SbMatrix3 &m)
Constructor.
Definition SbRotation.h:162
SbRotation & setValue(const SbMatrix &m)
Sets value of rotation from a rotation matrix.
SbRotation & setValue(const float q[4])
Sets value of rotation from array of 4 components of a quaternion.
void getValue(SbMatrix3 &matrix) const
Returns corresponding 3x3 rotation matrix.
void getValue(SbVec3f &axis, float &radians) const
Returns corresponding 3D rotation axis vector and angle in radians.
SbRotation & operator*=(const SbRotation &q)
Multiplies by another rotation; results in product of rotations.
SbRotation(const SbVec3f &rotateFrom, const SbVec3f &rotateTo)
Constructor.
Definition SbRotation.h:178
friend int operator!=(const SbRotation &q1, const SbRotation &q2)
Inequality comparison operator.
Definition SbRotation.h:283
SbRotation(float q0, float q1, float q2, float q3)
Constructor.
Definition SbRotation.h:148
SbRotation & setValue(float q0, float q1, float q2, float q3)
Sets value of rotation from 4 individual components of a quaternion.
SbRotation & setValue(const SbMatrixd &md)
Sets rotation from a double precision rotation matrix.
SbRotation & setValue(const SbVec3f &axis, float radians)
Sets value of vector from 3D rotation axis vector and angle in radians.
friend SbRotation operator*(const SbRotation &q1, const SbRotation &q2)
Multiplication of two rotations; results in product of rotations.
void scaleAngle(float scaleFactor)
Keep the axis the same.
void multVec(const SbVec3f &src, SbVec3f &dst) const
Multiplies the given vector by the matrix of this rotation.
SbBool equals(const SbRotation &r, float tolerance) const
Equality comparison within given tolerance - the square of the length of the maximum distance between...
SbRotation(const SbVec3f &axis, float radians)
Constructor.
Definition SbRotation.h:169
SbRotation(const SbMatrix &m)
Constructor.
Definition SbRotation.h:155
void getValue(float &q0, float &q1, float &q2, float &q3) const
Returns 4 individual components of rotation quaternion.
SbRotation(const float v[4])
Constructor.
Definition SbRotation.h:140
SbRotation & invert()
Changes a rotation to be its inverse.
void getValue(SbMatrixd &matrix) const
Returns corresponding 4x4 rotation matrix.
const float * getValue() const
Returns pointer to array of 4 components defining quaternion.
Definition SbRotation.h:184
SbRotation inverse() const
Returns the inverse of a rotation.
Definition SbRotation.h:226
static SbRotation identity()
Returns a null rotation.
Definition SbRotation.h:318
SbRotation & setValue(const SbMatrix3 &m)
Sets rotation from a 3x3 rotation matrix.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Class for repres...
Definition SbRotation.h:425
SbRotationd & operator*=(const SbRotationd &q)
Multiplies by another rotation; results in product of rotations.
SbRotationd(const SbVec3d &axis, double radians)
Constructor.
Definition SbRotation.h:468
SbRotationd & setValue(const SbRotation &rotate)
Sets rotation from a single precision rotation.
SbRotationd()
Constructor for rotation.
Definition SbRotation.h:431
void multVec(const SbVec3d &src, SbVec3d &dst) const
Multiplies the given vector by the matrix of this rotation.
static SbRotationd slerp(const SbRotationd &rot0, const SbRotationd &rot1, double t)
Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1.
void getValue(SbMatrix &matrix) const
Returns corresponding 4x4 rotation matrix.
SbRotationd & setValue(const SbMatrix &m)
Sets rotation from a single precision rotation matrix.
friend int operator==(const SbRotationd &q1, const SbRotationd &q2)
Equality comparison operator.
SbRotationd(double q0, double q1, double q2, double q3)
Constructor.
Definition SbRotation.h:447
void getValue(SbMatrix3 &matrix) const
Returns corresponding 3x3 rotation matrix.
SbRotationd & setValue(const SbVec3d &rotateFrom, const SbVec3d &rotateTo)
Sets rotation to rotate one direction vector to another.
SbRotationd(const SbVec3d &rotateFrom, const SbVec3d &rotateTo)
Constructor.
Definition SbRotation.h:477
void scaleAngle(double scaleFactor)
Keep the axis the same.
friend int operator!=(const SbRotationd &q1, const SbRotationd &q2)
Inequality comparison operator.
Definition SbRotation.h:582
SbRotationd(const double v[4])
Constructor.
Definition SbRotation.h:439
SbRotationd & setValue(const SbVec3d &axis, double radians)
Sets value of vector from 3D rotation axis vector and angle in radians.
SbRotationd & setValue(const SbMatrix3 &m)
Sets rotation from a 3x3 rotation matrix.
SbRotationd & setValue(const SbMatrixd &m)
Sets value of rotation from a rotation matrix.
SbRotationd & setValue(double q0, double q1, double q2, double q3)
Sets value of rotation from 4 individual components of a quaternion.
SbRotationd(const SbMatrix3 &m)
Constructor.
Definition SbRotation.h:461
SbRotationd(const SbMatrixd &m)
Constructor.
Definition SbRotation.h:454
friend SbRotationd operator*(const SbRotationd &q1, const SbRotationd &q2)
Multiplication of two rotations; results in product of rotations.
void getValue(double &q0, double &q1, double &q2, double &q3) const
Returns 4 individual components of rotation quaternion.
SbBool equals(const SbRotationd &r, double tolerance) const
Equality comparison within given tolerance - the square of the length of the maximum distance between...
static SbRotationd identity()
Returns a null rotation.
Definition SbRotation.h:617
void getValue(SbMatrixd &matrix) const
Returns corresponding 4x4 rotation matrix.
void getValue(SbVec3d &axis, double &radians) const
Returns corresponding 3D rotation axis vector and angle in radians.
SbRotationd inverse() const
Returns the inverse of a rotation.
Definition SbRotation.h:525
SbRotationd & invert()
Changes a rotation to be its inverse.
const double * getValue() const
Returns pointer to array of 4 components defining quaternion.
Definition SbRotation.h:483
SbRotationd & setValue(const double q[4])
Sets value of rotation from array of 4 components of a quaternion.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D vector class ...
Definition SbVec.h:1214
3D vector class.
Definition SbVec.h:932
int SbBool
Boolean type.
Definition SbBase.h:87