Debian Codegraph @

apps/examples/Mentor/CXX/13.8.Blinker.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 9.
40 *
41 * Blinker node.
42 * Use a blinker node to flash a neon ad sign on and off
43 *------------------------------------------------------------*/
44
45 #include <cstdlib>
46 #include <Inventor/SoDB.h>
47 #include <Inventor/SoInput.h>
48 #include <Inventor/Xt/SoXt.h>
49 #include <Inventor/Xt/SoXtRenderArea.h>
50 #include <Inventor/nodes/SoBlinker.h>
51 #include <Inventor/nodes/SoDirectionalLight.h>
52 #include <Inventor/nodes/SoMaterial.h>
53 #include <Inventor/nodes/SoPerspectiveCamera.h>
54 #include <Inventor/nodes/SoSeparator.h>
55 #include <Inventor/nodes/SoText3.h>
56
57 int
58 main(int , char **argv)
59 {
60 // Initialize Inventor and Xt
61 Widget myWindow = SoXt::init(argv[0]);
62 if (myWindow == NULL) exit(1);
63
64 // Set up camera and light
65 SoSeparator *root = new SoSeparator;
66 root->ref();
67 SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
68 root->addChild(myCamera);
69 root->addChild(new SoDirectionalLight);
70
71 // Read in the parts of the sign from a file
72 SoInput myInput;
73 if (!myInput.openFile("/usr/share/src/Inventor/examples/data/eatAtJosies.iv"))
74 exit (1);
75 SoSeparator *fileContents = SoDB::readAll(&myInput);
76 if (fileContents == NULL)
77 exit (1);
78
79 SoSeparator *eatAt;
80 eatAt = (SoSeparator *)SoNode::getByName("EatAt");
81 SoSeparator *josie;
82 josie = (SoSeparator *)SoNode::getByName("Josies");
83 SoSeparator *frame;
84 frame = (SoSeparator *)SoNode::getByName("Frame");
85
86 //////////////////////////////////////////////////////////////
87 // CODE FOR The Inventor Mentor STARTS HERE
88
89 // Add the non-blinking part of the sign to the root
90 root->addChild(eatAt);
91
92 // Add the fast-blinking part to a blinker node
93 SoBlinker *fastBlinker = new SoBlinker;
94 root->addChild(fastBlinker);
95 fastBlinker->speed = 2; // blinks 2 times a second
96 fastBlinker->addChild(josie);
97
98 // Add the slow-blinking part to another blinker node
99 SoBlinker *slowBlinker = new SoBlinker;
100 root->addChild(slowBlinker);
101 slowBlinker->speed = 0.5; // 2 secs per cycle; 1 on, 1 off
102 slowBlinker->addChild(frame);
103
104 // CODE FOR The Inventor Mentor ENDS HERE
105 //////////////////////////////////////////////////////////////
106
107 // Set up and display render area
108 SoXtRenderArea *myRenderArea = new SoXtRenderArea(myWindow);
109 SbViewportRegion myRegion(myRenderArea->getSize());
110 myCamera->viewAll(root, myRegion);
111
112 myRenderArea->setSceneGraph(root);
113 myRenderArea->setTitle("Neon");
114 myRenderArea->show();
115 SoXt::show(myWindow);
116 SoXt::mainLoop();
117 }
118
119