Debian Codegraph @

apps/examples/Mentor/CXX/13.7.Rotor.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 13, example 8.
40 *
41 * Rotor node example.
42 * Read in the tower and vanes of a windmill from a file.
43 * Use a rotor node to rotate the vanes.
44 *------------------------------------------------------------*/
45
46 #include <Inventor/SoDB.h>
47 #include <Inventor/SoInput.h>
48 #include <Inventor/Xt/SoXt.h>
49 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
50 #include <Inventor/nodes/SoSeparator.h>
51 #include <Inventor/nodes/SoRotor.h>
52
53 SoSeparator *
54 readFile(const char *filename)
55 {
56 // Open the input file
57 SoInput mySceneInput;
58 if (!mySceneInput.openFile(filename)) {
59 fprintf(stderr, "Cannot open file %s\n", filename);
60 return NULL;
61 }
62
63 // Read the whole file into the database
64 SoSeparator *myGraph = SoDB::readAll(&mySceneInput);
65 if (myGraph == NULL) {
66 fprintf(stderr, "Problem reading file\n");
67 return NULL;
68 }
69
70 mySceneInput.closeFile();
71 return myGraph;
72 }
73
74 int
75 main(int argc, char **argv)
76 {
77 // Initialize Inventor and Xt
78 Widget myWindow = SoXt::init(argv[0]);
79
80 SoSeparator *root = new SoSeparator;
81 root->ref();
82
83 // Read in the data for the windmill tower
84 SoSeparator *windmillTower =
85 readFile("/usr/share/src/Inventor/examples/data/windmillTower.iv");
86 root->addChild(windmillTower);
87
88 // Add a rotor node to spin the vanes
89 SoRotor *myRotor = new SoRotor;
90 myRotor->rotation.setValue(SbVec3f(0, 0, 1), 0); // z axis
91 myRotor->speed = 0.2;
92 root->addChild(myRotor);
93
94 // Read in the data for the windmill vanes
95 SoSeparator *windmillVanes =
96 readFile("/usr/share/src/Inventor/examples/data/windmillVanes.iv");
97 root->addChild(windmillVanes);
98
99 // Create a viewer
100 SoXtExaminerViewer *myViewer =
101 new SoXtExaminerViewer(myWindow);
102
103 // attach and show viewer
104 myViewer->setSceneGraph(root);
105 myViewer->setTitle("Windmill");
106 myViewer->show();
107
108 // Loop forever
109 SoXt::show(myWindow);
110 SoXt::mainLoop();
111 }
112