Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SbRotation.h
1 #ifndef COIN_SBROTATION_H
2 #define COIN_SBROTATION_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <cstdio>
37 #include <Inventor/SbVec4f.h>
38 #include <Inventor/SbByteBuffer.h>
39 #include <Inventor/SbString.h>
40 
41 class SbMatrix;
42 class SbVec3f;
43 
44 class COIN_DLL_API SbRotation {
45 public:
46  SbRotation(void);
47  SbRotation(const SbVec3f & axis, const float radians);
48  SbRotation(const float q[4]);
49  SbRotation(const float q0, const float q1, const float q2, const float q3);
50  SbRotation(const SbMatrix & m);
51  SbRotation(const SbVec3f & rotateFrom, const SbVec3f & rotateTo);
52  const float * getValue(void) const;
53  void getValue(float & q0, float & q1, float & q2, float & q3) const;
54  SbRotation & setValue(const float q0, const float q1,
55  const float q2, const float q3);
56  void getValue(SbVec3f & axis, float & radians) const;
57  void getValue(SbMatrix & matrix) const;
58  SbRotation & invert(void);
59  SbRotation inverse(void) const;
60  SbRotation & setValue(const float q[4]);
61  SbRotation & setValue(const SbMatrix & m);
62  SbRotation & setValue(const SbVec3f & axis, const float radians);
63  SbRotation & setValue(const SbVec3f & rotateFrom, const SbVec3f & rotateTo);
64  SbRotation & operator*=(const SbRotation & q);
65  SbRotation & operator*=(const float s);
66  friend COIN_DLL_API int operator==(const SbRotation & q1, const SbRotation & q2);
67  friend COIN_DLL_API int operator!=(const SbRotation & q1, const SbRotation & q2);
68  float operator[] (int n) const;
69 
70  SbBool equals(const SbRotation & r, float tolerance) const;
71  friend COIN_DLL_API SbRotation operator *(const SbRotation & q1, const SbRotation & q2);
72  void multVec(const SbVec3f & src, SbVec3f & dst) const;
73 
74  void scaleAngle(const float scaleFactor);
75  static SbRotation slerp(const SbRotation & rot0, const SbRotation & rot1,
76  float t);
77  static SbRotation identity(void);
78 
79  SbString toString() const;
80  SbBool fromString(const SbString & str);
81 
82  void print(FILE * fp) const;
83 
84 private:
85  SbVec4f quat;
86 };
87 
88 COIN_DLL_API int operator ==(const SbRotation & q1, const SbRotation & q2);
89 COIN_DLL_API int operator !=(const SbRotation & q1, const SbRotation & q2);
90 COIN_DLL_API SbRotation operator *(const SbRotation & q1, const SbRotation & q2);
91 
92 inline float SbRotation::operator[](int n) const
93 {
94  //Any limit checking is delegated to SbVec4f
95  return quat[n];
96 }
97 
98 #endif // !COIN_SBROTATION_H
The SbVec4f class is a 4 dimensional vector with floating point coordinates.
Definition: SbVec4f.h:49
float operator[](int n) const
returns the n&#39;th quaternion of this rotation
Definition: SbRotation.h:92
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:102
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:106
The SbRotation class represents a rotation in 3D space.
Definition: SbRotation.h:44
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition: SbVec3f.h:51
The SbMatrix class is a 4x4 dimensional representation of a matrix.
Definition: SbMatrix.h:47
SbVec2s operator*(const SbVec2s &v, int d)
The SbString class is a string class with convenience functions for string operations.
Definition: SbString.h:52