Debian Codegraph @

apps/examples/Mentor/CXX/12.3.AlarmSensor.c++

raw
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 * This is an example from the Inventor Mentor,
39 * chapter 12, example 3.
40 *
41 * Alarm sensor that raises a flag after 10 minutes
42 *------------------------------------------------------------*/
43
44 #include <cstdlib>
45 #include <Inventor/Xt/SoXt.h>
46 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
47 #include <Inventor/nodes/SoCone.h>
48 #include <Inventor/nodes/SoSeparator.h>
49 #include <Inventor/nodes/SoTransform.h>
50 #include <Inventor/sensors/SoAlarmSensor.h>
51
52 ///////////////////////////////////////////////////////////
53 // CODE FOR The Inventor Mentor STARTS HERE
54
55 static void
56 raiseFlagCallback(void *data, SoSensor *)
57 {
58 // We know data is really a SoTransform node:
59 SoTransform *flagAngleXform = (SoTransform *)data;
60
61 // Rotate flag by 90 degrees about the Z axis:
62 flagAngleXform->rotation.setValue(SbVec3f(0,0,1), M_PI/2);
63 }
64
65 // CODE FOR The Inventor Mentor ENDS HERE
66 ///////////////////////////////////////////////////////////
67
68 int
69 main(int , char **argv)
70 {
71 Widget myWindow = SoXt::init(argv[0]); // pass the app name
72 if (myWindow == NULL) exit(1);
73
74 ///////////////////////////////////////////////////////////
75 // CODE FOR The Inventor Mentor STARTS HERE
76
77 SoTransform *flagXform = new SoTransform;
78
79 // Create an alarm that will call the flag-raising callback:
80 SoAlarmSensor *myAlarm =
81 new SoAlarmSensor(raiseFlagCallback, flagXform);
82 myAlarm->setTimeFromNow(12.0); // 12 seconds
83 myAlarm->schedule();
84
85 // CODE FOR The Inventor Mentor ENDS HERE
86 ///////////////////////////////////////////////////////////
87
88 SoSeparator *root = new SoSeparator;
89 root->ref();
90 root->addChild(flagXform);
91 SoCone *myCone = new SoCone;
92 myCone->bottomRadius = 0.1;
93 root->addChild(myCone);
94
95 SoXtExaminerViewer *myViewer = new
96 SoXtExaminerViewer(myWindow);
97
98 // Put our scene in myViewer, change the title
99 myViewer->setSceneGraph(root);
100 myViewer->setTitle("Raise The Cone");
101 myViewer->show();
102
103 SoXt::show(myWindow); // Display main window
104 SoXt::mainLoop(); // Main Inventor event loop
105 }
106