Coin: SbRotation.h Source File

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/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
41class SbMatrix;
42class SbVec3f;
43
44 class COIN_DLL_API SbRotation {
45public:
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
84private:
85 SbVec4f quat;
86};
87
88COIN_DLL_API int operator ==(const SbRotation & q1, const SbRotation & q2);
89COIN_DLL_API int operator !=(const SbRotation & q1, const SbRotation & q2);
90COIN_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
SbMatrix
The SbMatrix class is a 4x4 dimensional representation of a matrix.
Definition SbMatrix.h:47
SbRotation
The SbRotation class represents a rotation in 3D space.
Definition SbRotation.h:44
SbRotation::slerp
static SbRotation slerp(const SbRotation &rot0, const SbRotation &rot1, float t)
Definition SbRotation.cpp:658
SbRotation::operator==
friend int operator==(const SbRotation &q1, const SbRotation &q2)
Definition SbRotation.cpp:571
SbRotation::identity
static SbRotation identity(void)
Definition SbRotation.cpp:703
SbRotation::inverse
SbRotation inverse(void) const
Definition SbRotation.cpp:345
SbRotation::setValue
SbRotation & setValue(const float q0, const float q1, const float q2, const float q3)
Definition SbRotation.cpp:222
SbRotation::operator*=
SbRotation & operator*=(const SbRotation &q)
Definition SbRotation.cpp:536
SbRotation::operator!=
friend int operator!=(const SbRotation &q1, const SbRotation &q2)
Definition SbRotation.cpp:584
SbRotation::invert
SbRotation & invert(void)
Definition SbRotation.cpp:319
SbRotation::toString
SbString toString() const
Definition SbRotation.cpp:712
SbRotation::operator[]
float operator[](int n) const
returns the n'th quaternion of this rotation
Definition SbRotation.h:92
SbRotation::multVec
void multVec(const SbVec3f &src, SbVec3f &dst) const
Definition SbRotation.cpp:621
SbRotation::equals
SbBool equals(const SbRotation &r, float tolerance) const
Definition SbRotation.cpp:594
SbRotation::print
void print(FILE *fp) const
Definition SbRotation.cpp:733
SbRotation::fromString
SbBool fromString(const SbString &str)
Definition SbRotation.cpp:721
SbRotation::scaleAngle
void scaleAngle(const float scaleFactor)
Definition SbRotation.cpp:636
SbRotation::SbRotation
SbRotation(void)
Definition SbRotation.cpp:100
SbRotation::getValue
const float * getValue(void) const
Definition SbRotation.cpp:197
SbString
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:52
SbVec3f
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition SbVec3f.h:51
SbVec4f
The SbVec4f class is a 4 dimensional vector with floating point coordinates.
Definition SbVec4f.h:49