Debian Codegraph @

lib/database/src/so/nodes/SoPendulum.c++

raw symbols SCIP
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoPendulum
47 |
48 | Author(s) : Ronen Barzel
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/SoDB.h>cxx . . $ `<file>/lib/database/include/Inventor/SoDB.h`/
55 #include <Inventor/engines/SoElapsedTime.h>cxx . . $ `<file>/lib/database/include/Inventor/engines/SoElapsedTime.h`/
56 #include <Inventor/engines/SoCalculator.h>cxx . . $ `<file>/lib/database/include/Inventor/engines/SoCalculator.h`/
57 #include <Inventor/engines/SoInterpolate.h>cxx . . $ `<file>/lib/database/include/Inventor/engines/SoInterpolate.h`/
58 #include <Inventor/nodes/SoPendulum.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoPendulum.h`/
59 #include <Inventor/sensors/SoFieldSensor.h>cxx . . $ `<file>/lib/database/include/Inventor/sensors/SoFieldSensor.h`/
60 #include <Inventor/sensors/SoOneShotSensor.h>cxx . . $ `<file>/lib/database/include/Inventor/sensors/SoOneShotSensor.h`/
61
62 SO_NODE_SOURCEcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:241:9`!(SoPendulum);
63
64 ////////////////////////////////////////////////////////////////////////
65 //
66 // Description:
67 // Constructor
68 //
69 // Use: public
70
71 SoPendulumcxx . . $ SoPendulum#::SoPendulumcxx . . $ SoPendulum#SoPendulum(49f6e7a06ebc5aa8).()
72 //
73 ////////////////////////////////////////////////////////////////////////
74 {
75 SO_NODE_CONSTRUCTORcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:309:9`!(SoPendulum);
76 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(rotation0, (SbRotation(0,0,0,1)));
77 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(rotation1, (SbRotation(0,0,0,1)));
78 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(speed, (1));
79 SO_NODE_ADD_FIELDcxx . . $ `lib/database/include/Inventor/nodes/SoSubNode.h:346:9`!(on, (TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!));
80
81 timecxx . . $ SoPendulum#time. = new SoElapsedTimecxx . . $ SoElapsedTime#;
82 calccxx . . $ SoPendulum#calc. = new SoCalculatorcxx . . $ SoCalculator#;
83 interpcxx . . $ SoPendulum#interp. = new SoInterpolateRotationcxx . . $ SoInterpolateRotation#;
84 timecxx . . $ SoPendulum#time.->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
85 calccxx . . $ SoPendulum#calc.->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
86 interpcxx . . $ SoPendulum#interp.->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
87
88 // next make the sensors (when wiring the engines
89 // together the notify method will try to schedule
90 // the sensor, so make sure it exists).
91 rotationSensorcxx . . $ SoPendulum#rotationSensor. = new SoOneShotSensorcxx . . $ SoOneShotSensor#SoOneShotSensor(2e94453e53abe5a2).(rotationSensorCBcxx . . $ SoPendulum#rotationSensorCB(c8d298b3e215c027)., this);
92 rotationSensorcxx . . $ SoPendulum#rotationSensor.->setPrioritycxx . . $ SoDelayQueueSensor#setPriority(cb2f890c2fdad230).(0);
93 rotation0Sensorcxx . . $ SoPendulum#rotation0Sensor. = new SoFieldSensorcxx . . $ SoFieldSensor#SoFieldSensor(2e94453e53abe5a2).(rotationSensorCBcxx . . $ SoPendulum#rotationSensorCB(c8d298b3e215c027)., this);
94 rotation0Sensorcxx . . $ SoPendulum#rotation0Sensor.->setPrioritycxx . . $ SoDelayQueueSensor#setPriority(cb2f890c2fdad230).(0);
95 rotation0Sensorcxx . . $ SoPendulum#rotation0Sensor.->attachcxx . . $ SoFieldSensor#attach(6a35cc9f7090653f).(&rotation0cxx . . $ SoPendulum#rotation0.);
96 rotation1Sensorcxx . . $ SoPendulum#rotation1Sensor. = new SoFieldSensorcxx . . $ SoFieldSensor#SoFieldSensor(2e94453e53abe5a2).(rotationSensorCBcxx . . $ SoPendulum#rotationSensorCB(c8d298b3e215c027)., this);
97 rotation1Sensorcxx . . $ SoPendulum#rotation1Sensor.->setPrioritycxx . . $ SoDelayQueueSensor#setPriority(cb2f890c2fdad230).(0);
98 rotation1Sensorcxx . . $ SoPendulum#rotation1Sensor.->attachcxx . . $ SoFieldSensor#attach(6a35cc9f7090653f).(&rotation1cxx . . $ SoPendulum#rotation1.);
99 onSensorcxx . . $ SoPendulum#onSensor. = new SoFieldSensorcxx . . $ SoFieldSensor#SoFieldSensor(2e94453e53abe5a2).(onSensorCBcxx . . $ SoPendulum#onSensorCB(c8d298b3e215c027)., this);
100 onSensorcxx . . $ SoPendulum#onSensor.->setPrioritycxx . . $ SoDelayQueueSensor#setPriority(cb2f890c2fdad230).(0);
101 onSensorcxx . . $ SoPendulum#onSensor.->attachcxx . . $ SoFieldSensor#attach(6a35cc9f7090653f).(&oncxx . . $ SoPendulum#on.);
102
103 timecxx . . $ SoPendulum#time.->oncxx . . $ SoElapsedTime#on..connectFromcxx . . $ SoField#connectFrom(b5126a9b660c5c40).(&oncxx . . $ SoPendulum#on.);
104 calccxx . . $ SoPendulum#calc.->acxx . . $ SoCalculator#a..connectFromcxx . . $ SoField#connectFrom(b5126a9b660c5c40).(&speedcxx . . $ SoPendulum#speed.);
105 calccxx . . $ SoPendulum#calc.->bcxx . . $ SoCalculator#b..connectFromcxx . . $ SoField#connectFrom(8f75f3dee2b2cd82).(&timecxx . . $ SoPendulum#time.->timeOutcxx . . $ SoElapsedTime#timeOut.);
106 // input "c" to the calculation is a phase offset that is
107 // set by the rotation sensor callback.
108 calccxx . . $ SoPendulum#calc.->expressioncxx . . $ SoCalculator#expression..setValuecxx . . $ SoMFString#setValue(85c52e162fed56f9).("oa = 0.5 + 0.5 * sin(a*b*2*M_PI + c)");
109 rotationSensorCBcxx . . $ SoPendulum#rotationSensorCB(c8d298b3e215c027).(this, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!); // init the offset to the default rotation
110 interpcxx . . $ SoPendulum#interp.->input0cxx . . $ SoInterpolateRotation#input0..connectFromcxx . . $ SoField#connectFrom(b5126a9b660c5c40).(&rotation0cxx . . $ SoPendulum#rotation0.);
111 interpcxx . . $ SoPendulum#interp.->input1cxx . . $ SoInterpolateRotation#input1..connectFromcxx . . $ SoField#connectFrom(b5126a9b660c5c40).(&rotation1cxx . . $ SoPendulum#rotation1.);
112 interpcxx . . $ SoPendulum#interp.->alphacxx . . $ SoInterpolate#alpha..connectFromcxx . . $ SoField#connectFrom(8f75f3dee2b2cd82).(&calccxx . . $ SoPendulum#calc.->oacxx . . $ SoCalculator#oa.);
113 rotationcxx . . $ SoRotation#rotation..connectFromcxx . . $ SoField#connectFrom(8f75f3dee2b2cd82).(&interpcxx . . $ SoPendulum#interp.->outputcxx . . $ SoInterpolate#output.);
114
115 // keep the internal connection, so we can tell
116 // later if somebody overrode it.
117 rotationcxx . . $ SoRotation#rotation..getConnectedEnginecxx . . $ SoField#getConnectedEngine(d90a32d7bcd50feb).(internalConnectioncxx . . $ SoPendulum#internalConnection.);
118
119 isBuiltIncxx . . $ SoFieldContainer#isBuiltIn. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
120 }
121
122 ////////////////////////////////////////////////////////////////////////
123 //
124 // Description:
125 // Destructor (necessary since inline destructor is too complex)
126 //
127 // Use: private
128
129 SoPendulumcxx . . $ SoPendulum#::~cxx . . $ SoPendulum#`~SoPendulum`(49f6e7a06ebc5aa8).SoPendulumcxx . . $ SoPendulum#()
130 //
131 ////////////////////////////////////////////////////////////////////////
132 {
133 timecxx . . $ SoPendulum#time.->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
134 calccxx . . $ SoPendulum#calc.->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
135 interpcxx . . $ SoPendulum#interp.->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
136
137 delete rotationSensorcxx . . $ SoPendulum#rotationSensor.;
138 delete rotation0Sensorcxx . . $ SoPendulum#rotation0Sensor.;
139 delete rotation1Sensorcxx . . $ SoPendulum#rotation1Sensor.;
140 delete onSensorcxx . . $ SoPendulum#onSensor.;
141 }
142
143 ////////////////////////////////////////////////////////////////////////
144 //
145 // Description:
146 // Write action. Disables connections to internal engines
147 // during the write.
148 //
149 // Use: protected
150
151 void
152 SoPendulumcxx . . $ SoPendulum#::writecxx . . $ SoPendulum#write(a375a81bffae2638).(SoWriteActioncxx . . $ SoWriteAction# *action)
153 //
154 ////////////////////////////////////////////////////////////////////////
155 {
156 SbBoolcxx . . $ SbBool# save = rotationcxx . . $ SoRotation#rotation..isConnectionEnabledcxx . . $ SoField#isConnectionEnabled(455f465bc33b4cdf).();
157 SoEngineOutputcxx . . $ SoEngineOutput# *rotationSource;
158
159 // if the connection is to the internal engine, disable it
160 if (rotationcxx . . $ SoRotation#rotation..isConnectedcxx . . $ SoField#isConnected(455f465bc33b4cdf).() &&
161 rotationcxx . . $ SoRotation#rotation..getConnectedEnginecxx . . $ SoField#getConnectedEngine(d90a32d7bcd50feb).(rotationSource) &&
162 rotationSource == internalConnectioncxx . . $ SoPendulum#internalConnection.) {
163
164 rotationcxx . . $ SoRotation#rotation..enableConnectioncxx . . $ SoField#enableConnection(d4f767463ce0a6b3).(FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!);
165 }
166
167 SoRotationcxx . . $ SoRotation#::writecxx . . $ SoNode#write(a375a81bffae2638).(action);
168
169 rotationcxx . . $ SoRotation#rotation..enableConnectioncxx . . $ SoField#enableConnection(d4f767463ce0a6b3).(save);
170 }
171
172 ////////////////////////////////////////////////////////////////////////
173 //
174 // Description:
175 // Override notify to notice when the rotation field is touched.
176 // Can't use field sensor because we need to distinguish
177 // our own touching of the field from a setValue by the client.
178 //
179 // Use: protected
180
181 void
182 SoPendulumcxx . . $ SoPendulum#::notifycxx . . $ SoPendulum#notify(f43de791d8d2eb5a).(SoNotListcxx . . $ SoNotList# *list)
183 //
184 ////////////////////////////////////////////////////////////////////////
185 {
186 SoNotReccxx . . $ SoNotRec# *rec = list->getFirstReccxx . . $ SoNotList#getFirstRec(a39986cdb7d7aef6).();
187
188 // only interested in a field-to-container notification
189 if (rec->getTypecxx . . $ SoNotRec#getType(30fb18e4d3ac32aa).() == SoNotReccxx . . $ SoNotRec#::CONTAINERcxx . . $ SoNotRec#CONTAINER. &&
190 rec->getBasecxx . . $ SoNotRec#getBase(82e87c88e730ed63).() == this &&
191 list->getLastFieldcxx . . $ SoNotList#getLastField(c4a4d937024b6702).() == &rotationcxx . . $ SoRotation#rotation.) {
192
193 rotationSensorcxx . . $ SoPendulum#rotationSensor.->schedulecxx . . $ SoDelayQueueSensor#schedule(49f6e7a06ebc5aa8).();
194 }
195
196 SoRotationcxx . . $ SoRotation#::notifycxx . . $ SoNode#notify(f43de791d8d2eb5a).(list);
197 }
198
199 ////////////////////////////////////////////////////////////////////////
200 //
201 // Description:
202 // Callback is called when somebody sets the rotation field.
203 //
204 // Use: protected
205
206 void
207 SoPendulumcxx . . $ SoPendulum#::rotationSensorCBcxx . . $ SoPendulum#rotationSensorCB(c8d298b3e215c027).(void *data, SoSensorcxx . . $ SoSensor# *)
208 //
209 ////////////////////////////////////////////////////////////////////////
210 {
211 SoPendulumcxx . . $ SoPendulum# *pendulum = (SoPendulumcxx . . $ SoPendulum# *) data;
212 SbVec4fcxx . . $ SbVec4f# qcxx . . $ SbVec4f#SbVec4f(49f6e7a06ebc5aa8)., q1cxx . . $ SbVec4f#SbVec4f(49f6e7a06ebc5aa8)., q0cxx . . $ SbVec4f#SbVec4f(49f6e7a06ebc5aa8).;
213 pendulum->rotationcxx . . $ SoRotation#rotation..getValuecxx . . $ SoSFRotation#getValue(cd68af149be99fa7).().getValuecxx . . $ SbRotation#getValue(82a473bb42211169).(q[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).0],q[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).1],q[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).2],q[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).3]);
214 pendulum->rotation0cxx . . $ SoPendulum#rotation0..getValuecxx . . $ SoSFRotation#getValue(cd68af149be99fa7).().getValuecxx . . $ SbRotation#getValue(82a473bb42211169).(q0[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).0],q0[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).1],q0[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).2],q0[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).3]);
215 pendulum->rotation1cxx . . $ SoPendulum#rotation1..getValuecxx . . $ SoSFRotation#getValue(cd68af149be99fa7).().getValuecxx . . $ SbRotation#getValue(82a473bb42211169).(q1[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).0],q1[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).1],q1[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).2],q1[cxx . . $ SbVec4f#`operator[]`(5dbdaf238659ae67).3]);
216
217 // find the value of the interpolant that would
218 // line up with q. See where q projects onto the line
219 // from q0 to q1
220 SbVec4fcxx . . $ SbVec4f# diff = q1 -cxx . . $ operator-(a6413eb44dc5dc97). q0;
221 float len = diff.lengthcxx . . $ SbVec4f#length(5036dfe8d4170af2).(), alpha;
222 if (len == 0)
223 alpha = 0;
224 else {
225 alpha = (q -cxx . . $ operator-(a6413eb44dc5dc97). q0).dotcxx . . $ SbVec4f#dot(8809bb871cf8ca0d).(diff)/(len*len);
226 if (alpha > 1)
227 alpha = 1;
228 if (alpha < 0)
229 alpha = 0;
230 }
231
232 float a = pendulum->calccxx . . $ SoPendulum#calc.->acxx . . $ SoCalculator#a.[cxx . . $ SoMFFloat#`operator[]`(e737fe38c3e79314).0];
233 float b = pendulum->calccxx . . $ SoPendulum#calc.->bcxx . . $ SoCalculator#b.[cxx . . $ SoMFFloat#`operator[]`(e737fe38c3e79314).0];
234 // invert the expression: alpha = .5 + .5 sin(a*b*2*PI + c)
235 pendulum->calccxx . . $ SoPendulum#calc.->ccxx . . $ SoCalculator#c..setValuecxx . . $ SoMFFloat#setValue(9364e6e7bff7660).(asin(2*alpha-1) - a*b*2*M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`!);
236 }
237
238 ////////////////////////////////////////////////////////////////////////
239 //
240 // Description:
241 // Callback is called when somebody sets the on field
242 //
243 // Use: protected
244
245 void
246 SoPendulumcxx . . $ SoPendulum#::onSensorCBcxx . . $ SoPendulum#onSensorCB(c8d298b3e215c027).(void *data, SoSensorcxx . . $ SoSensor# *)
247 //
248 ////////////////////////////////////////////////////////////////////////
249 {
250 SoPendulumcxx . . $ SoPendulum# *pendulum = (SoPendulumcxx . . $ SoPendulum# *) data;
251
252 if (pendulum->oncxx . . $ SoPendulum#on..getValuecxx . . $ SoSFBool#getValue(455f465bc33b4cdf).()) {
253 // if turned on, force the internal connection to be made and enabled,
254 // no matter what sort of mucking has happened to it.
255 pendulum->rotationcxx . . $ SoRotation#rotation..enableConnectioncxx . . $ SoField#enableConnection(d4f767463ce0a6b3).(TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!);
256 pendulum->rotationcxx . . $ SoRotation#rotation..connectFromcxx . . $ SoField#connectFrom(8f75f3dee2b2cd82).(&pendulum->interpcxx . . $ SoPendulum#interp.->outputcxx . . $ SoInterpolate#output.);
257 pendulum->rotationcxx . . $ SoRotation#rotation..getConnectedEnginecxx . . $ SoField#getConnectedEngine(d90a32d7bcd50feb).(pendulum->internalConnectioncxx . . $ SoPendulum#internalConnection.);
258 }
259 }