Debian Codegraph @

apps/examples/Mentor/CXX/13.3.TimeCounter.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 4.
40 *
41 * Time counter engine.
42 * The output from an time counter engine is used to control
43 * horizontal and vertical motion of a figure object.
44 * The resulting effect is that the figure jumps across
45 * the screen.
46 *------------------------------------------------------------*/
47
48 #include <cstdlib>
49 #include <Inventor/SoDB.h>
50 #include <Inventor/Xt/SoXt.h>
51 #include <Inventor/Xt/SoXtRenderArea.h>
52 #include <Inventor/engines/SoCompose.h>
53 #include <Inventor/engines/SoElapsedTime.h>
54 #include <Inventor/engines/SoTimeCounter.h>
55 #include <Inventor/nodes/SoDirectionalLight.h>
56 #include <Inventor/nodes/SoMaterial.h>
57 #include <Inventor/nodes/SoPerspectiveCamera.h>
58 #include <Inventor/nodes/SoRotationXYZ.h>
59 #include <Inventor/nodes/SoSeparator.h>
60 #include <Inventor/nodes/SoTransform.h>
61 #include <Inventor/nodes/SoTranslation.h>
62
63 int
64 main(int , char **argv)
65 {
66 // Initialize Inventor and Xt
67 Widget myWindow = SoXt::init(argv[0]);
68 if (myWindow == NULL) exit(1);
69
70 SoSeparator *root = new SoSeparator;
71 root->ref();
72
73 // Add a camera and light
74 SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
75 myCamera->position.setValue(-8.0, -7.0, 20.0);
76 myCamera->heightAngle = M_PI/2.5;
77 myCamera->nearDistance = 15.0;
78 myCamera->farDistance = 25.0;
79 root->addChild(myCamera);
80 root->addChild(new SoDirectionalLight);
81
82 //////////////////////////////////////////////////////////////
83 // CODE FOR The Inventor Mentor STARTS HERE
84
85 // Set up transformations
86 SoTranslation *jumpTranslation = new SoTranslation;
87 root->addChild(jumpTranslation);
88 SoTransform *initialTransform = new SoTransform;
89 initialTransform->translation.setValue(-20., 0., 0.);
90 initialTransform->scaleFactor.setValue(40., 40., 40.);
91 initialTransform->rotation.setValue(SbVec3f(1,0,0), M_PI/2.);
92 root->addChild(initialTransform);
93
94 // Read the man object from a file and add to the scene
95 SoInput myInput;
96 if (!myInput.openFile("/usr/share/src/Inventor/examples/data/jumpyMan.iv"))
97 exit (1);
98 SoSeparator *manObject = SoDB::readAll(&myInput);
99 if (manObject == NULL)
100 exit (1);
101 root->addChild(manObject);
102
103 // Create two counters, and connect to X and Y translations.
104 // The Y counter is small and high frequency.
105 // The X counter is large and low frequency.
106 // This results in small jumps across the screen,
107 // left to right, again and again and again and ....
108 SoTimeCounter *jumpHeightCounter = new SoTimeCounter;
109 SoTimeCounter *jumpWidthCounter = new SoTimeCounter;
110 SoComposeVec3f *jump = new SoComposeVec3f;
111
112 jumpHeightCounter->max = 4;
113 jumpHeightCounter->frequency = 1.5;
114 jumpWidthCounter->max = 40;
115 jumpWidthCounter->frequency = 0.15;
116
117 jump->x.connectFrom(&jumpWidthCounter->output);
118 jump->y.connectFrom(&jumpHeightCounter->output);
119 jumpTranslation->translation.connectFrom(&jump->vector);
120
121 // CODE FOR The Inventor Mentor ENDS HERE
122 //////////////////////////////////////////////////////////////
123
124 SoXtRenderArea *myRenderArea = new SoXtRenderArea(myWindow);
125 SbViewportRegion myRegion(myRenderArea->getSize());
126 myRenderArea->setSceneGraph(root);
127 myRenderArea->setTitle("Jumping Man");
128 myRenderArea->show();
129
130 SoXt::show(myWindow);
131 SoXt::mainLoop();
132 }