1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 /*!
34   \class SoDecomposeRotation SoDecomposeRotation.h Inventor/engines/SoDecomposeRotation.h
35   \brief The SoDecomposeRotation class is used to decompose a rotation into angle and axis.
36 
37   \ingroup engines
38 */
39 
40 #include <Inventor/engines/SoDecomposeRotation.h>
41 #include <Inventor/lists/SoEngineOutputList.h>
42 #include <Inventor/fields/SoMFVec3f.h>
43 #include <Inventor/fields/SoMFFloat.h>
44 
45 #include "engines/SoSubEngineP.h"
46 
47 SO_ENGINE_SOURCE(SoDecomposeRotation);
48 
49 /*!
50   \var SoMFRotation SoDecomposeRotation::rotation
51   Input rotations to decompose into axis + angle values.
52 */
53 /*!
54   \var SoEngineOutput SoDecomposeRotation::axis
55   (SoMFVec3f) The axis settings of the input rotations.
56 */
57 /*!
58   \var SoEngineOutput SoDecomposeRotation::angle
59   (SoMFFloat) The angle values of the input rotations.
60 */
61 
62 #ifndef DOXYGEN_SKIP_THIS // No need to document these.
63 
64 // Default constructor.
SoDecomposeRotation()65 SoDecomposeRotation::SoDecomposeRotation()
66 {
67   SO_ENGINE_INTERNAL_CONSTRUCTOR(SoDecomposeRotation);
68 
69   SO_ENGINE_ADD_INPUT(rotation, (0.0f, 0.0f, 0.0f, 1.0f));
70 
71   SO_ENGINE_ADD_OUTPUT(axis, SoMFVec3f);
72   SO_ENGINE_ADD_OUTPUT(angle, SoMFFloat);
73 }
74 
75 // Documented in superclass.
76 void
initClass()77 SoDecomposeRotation::initClass()
78 {
79   SO_ENGINE_INTERNAL_INIT_CLASS(SoDecomposeRotation);
80 }
81 
82 //
83 // private members
84 //
~SoDecomposeRotation()85 SoDecomposeRotation::~SoDecomposeRotation()
86 {
87 }
88 
89 // Documented in superclass.
90 void
evaluate()91 SoDecomposeRotation::evaluate()
92 {
93   int num = this->rotation.getNum();
94 
95   SO_ENGINE_OUTPUT(axis,SoMFVec3f,setNum(num));
96   SO_ENGINE_OUTPUT(angle,SoMFFloat,setNum(num));
97 
98   int i;
99   float angleVal;
100   SbVec3f axisVal;
101   for (i = 0; i < num; i++) {
102     this->rotation[i].getValue(axisVal,angleVal);
103     SO_ENGINE_OUTPUT(axis,SoMFVec3f,set1Value(i,axisVal));
104     SO_ENGINE_OUTPUT(angle,SoMFFloat,set1Value(i,angleVal));
105   }
106 }
107 
108 #endif // !DOXYGEN_SKIP_THIS
109