Debian Codegraph @

apps/examples/Mentor/CXX/05.6.TransformOrdering.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 5, example 6.
40 *
41 * This example shows the effect of different order of
42 * operation of transforms. The left object is first
43 * scaled, then rotated, and finally translated to the left.
44 * The right object is first rotated, then scaled, and finally
45 * translated to the right.
46 *------------------------------------------------------------*/
47
48 #include <cstdlib>
49 #include <Inventor/Xt/SoXt.h>
50 #include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
51 #include <Inventor/SoDB.h>
52 #include <Inventor/nodes/SoMaterial.h>
53 #include <Inventor/nodes/SoRotationXYZ.h>
54 #include <Inventor/nodes/SoScale.h>
55 #include <Inventor/nodes/SoSeparator.h>
56 #include <Inventor/nodes/SoTranslation.h>
57
58 int
59 main(int, char **argv)
60 {
61 // Initialize Inventor and Xt
62 Widget myWindow = SoXt::init(argv[0]);
63 if (myWindow == NULL) exit(1);
64
65 SoSeparator *root = new SoSeparator;
66 root->ref();
67
68 // Create two separators, for left and right objects.
69 SoSeparator *leftSep = new SoSeparator;
70 SoSeparator *rightSep = new SoSeparator;
71 root->addChild(leftSep);
72 root->addChild(rightSep);
73
74 // Create the transformation nodes
75 SoTranslation *leftTranslation = new SoTranslation;
76 SoTranslation *rightTranslation = new SoTranslation;
77 SoRotationXYZ *myRotation = new SoRotationXYZ;
78 SoScale *myScale = new SoScale;
79
80 // Fill in the values
81 leftTranslation->translation.setValue(-1.0, 0.0, 0.0);
82 rightTranslation->translation.setValue(1.0, 0.0, 0.0);
83 myRotation->angle = M_PI/2; // 90 degrees
84 myRotation->axis = SoRotationXYZ::X;
85 myScale->scaleFactor.setValue(2., 1., 3.);
86
87 // Add transforms to the scene.
88 leftSep->addChild(leftTranslation); // left graph
89 leftSep->addChild(myRotation); // then rotated
90 leftSep->addChild(myScale); // first scaled
91
92 rightSep->addChild(rightTranslation); // right graph
93 rightSep->addChild(myScale); // then scaled
94 rightSep->addChild(myRotation); // first rotated
95
96 // Read an object from file. (as in example 4.2.Lights)
97 SoInput myInput;
98 if (!myInput.openFile("/usr/share/src/Inventor/examples/data/temple.iv"))
99 exit (1);
100 SoSeparator *fileContents = SoDB::readAll(&myInput);
101 if (fileContents == NULL)
102 exit (1);
103
104 // Add an instance of the object under each separator.
105 leftSep->addChild(fileContents);
106 rightSep->addChild(fileContents);
107
108 // Construct a renderArea and display the scene.
109 SoXtExaminerViewer *myViewer =
110 new SoXtExaminerViewer(myWindow);
111 myViewer->setSceneGraph(root);
112 myViewer->setTitle("Transform Ordering");
113 myViewer->viewAll();
114 myViewer->show();
115
116 SoXt::show(myWindow);
117 SoXt::mainLoop();
118 }