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 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif // HAVE_CONFIG_H
36
37 #ifdef HAVE_VRML97
38
39 /*!
40 \class SoVRMLPositionInterpolator SoVRMLPositionInterpolator.h Inventor/VRMLnodes/SoVRMLPositionInterpolator.h
41 \brief The SoVRMLPositionInterpolator class is used to interpolate 3D points.
42
43 \ingroup VRMLnodes
44
45 \WEB3DCOPYRIGHT
46
47 \verbatim
48 PositionInterpolator {
49 eventIn SFFloat set_fraction # (-,)
50 exposedField MFFloat key [] # (-,)
51 exposedField MFVec3f keyValue [] # (-,)
52 eventOut SFVec3f value_changed
53 }
54 \endverbatim
55
56 The PositionInterpolator node linearly interpolates among a list of
57 3D vectors. The keyValue field shall contain exactly as many values
58 as in the key field. 4.6.8, Interpolator nodes
59 (<http://www.web3d.org/documents/specifications/14772/V2.0/part1/concepts.html#4.6.8>),
60 contains a more detailed discussion of interpolators.
61
62 */
63
64 /*!
65 \var SoMFVec3f SoVRMLPositionInterpolator::keyValue
66 The keyValue vector.
67 */
68
69 /*!
70 \var SoEngineOutput SoVRMLPositionInterpolator::value_changed
71 The eventOut which is sent every time the interpolator has calculated a new value.
72 */
73
74 #include <Inventor/VRMLnodes/SoVRMLPositionInterpolator.h>
75
76 #include <Inventor/VRMLnodes/SoVRMLMacros.h>
77
78 #include "engines/SoSubNodeEngineP.h"
79
80 SO_NODEENGINE_SOURCE(SoVRMLPositionInterpolator);
81
82 // Doc in parent
83 void
initClass(void)84 SoVRMLPositionInterpolator::initClass(void) // static
85 {
86 SO_NODEENGINE_INTERNAL_INIT_CLASS(SoVRMLPositionInterpolator);
87 }
88
89 /*!
90 Constructor.
91 */
SoVRMLPositionInterpolator(void)92 SoVRMLPositionInterpolator::SoVRMLPositionInterpolator(void)
93 {
94 SO_NODEENGINE_INTERNAL_CONSTRUCTOR(SoVRMLPositionInterpolator);
95
96 SO_VRMLNODE_ADD_EMPTY_EXPOSED_MFIELD(keyValue);
97 SO_NODEENGINE_ADD_OUTPUT(value_changed, SoSFVec3f);
98 }
99
100 /*!
101 Destructor.
102 */
~SoVRMLPositionInterpolator()103 SoVRMLPositionInterpolator::~SoVRMLPositionInterpolator()
104 {
105 }
106
107 // Doc in parent
108 void
evaluate(void)109 SoVRMLPositionInterpolator::evaluate(void)
110 {
111 float interp;
112 int idx = this->getKeyValueIndex(interp, this->keyValue.getNum());
113 if (idx < 0) return;
114
115 const SbVec3f * v = this->keyValue.getValues(0);
116
117 SbVec3f v0 = v[idx];
118 if (interp > 0.0f) {
119 SbVec3f v1 = v[idx+1];
120 v0 = v0 + (v1-v0)*interp;
121 }
122 SO_ENGINE_OUTPUT(value_changed, SoSFVec3f, setValue(v0));
123 }
124
125 #endif // HAVE_VRML97
126