Debian Codegraph @

apps/examples/Mentor/CXX/14.2.Editors.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 14, example 2.
40 *
41 * Use nodekits to create a scene with a desk into an
42 * SoWrapperKit. Then, add a material editor for the desk and
43 * a light editor on the light.
44 *
45 * The scene is organized using an SoSceneKit, which contains
46 * lists for grouping lights (lightList), cameras (cameraList),
47 * and objects (childList) in a scene.
48 *
49 * Once the scene is created, a material editor is attached to
50 * the wrapperKit's 'material' part, and a directional light editor
51 * is attached to the light's 'directionalLight' part.
52 *----------------------------------------------------------------*/
53
54 #include <cstdlib>
55 #include <Inventor/SoDB.h>
56 #include <Inventor/SoInput.h>
57 #include <Inventor/Xt/SoXt.h>
58 #include <Inventor/Xt/SoXtDirectionalLightEditor.h>
59 #include <Inventor/Xt/SoXtMaterialEditor.h>
60 #include <Inventor/Xt/SoXtRenderArea.h>
61 #include <Inventor/nodekits/SoCameraKit.h>
62 #include <Inventor/nodekits/SoLightKit.h>
63 #include <Inventor/nodekits/SoSceneKit.h>
64 #include <Inventor/nodekits/SoWrapperKit.h>
65 #include <Inventor/nodes/SoMaterial.h>
66 #include <Inventor/nodes/SoPerspectiveCamera.h>
67 #include <Inventor/nodes/SoSeparator.h>
68
69 int
70 main(int , char **argv)
71 {
72 // Initialize Inventor and Xt
73 Widget myWindow = SoXt::init(argv[0]);
74 if (myWindow == NULL) exit(1);
75
76 // SCENE!
77 SoSceneKit *myScene = new SoSceneKit;
78 myScene->ref();
79
80 // LIGHTS! Add an SoLightKit to the "lightList." The
81 // SoLightKit creates an SoDirectionalLight by default.
82 myScene->setPart("lightList[0]", new SoLightKit);
83
84 // CAMERA!! Add an SoCameraKit to the "cameraList." The
85 // SoCameraKit creates an SoPerspectiveCamera by default.
86 myScene->setPart("cameraList[0]", new SoCameraKit);
87 myScene->setCameraNumber(0);
88
89 // Read an object from file.
90 SoInput myInput;
91 if (!myInput.openFile("/usr/share/src/Inventor/examples/data/desk.iv"))
92 exit (1);
93 SoSeparator *fileContents = SoDB::readAll(&myInput);
94 if (fileContents == NULL)
95 exit (1);
96
97 // OBJECT!! Create an SoWrapperKit and set its contents to
98 // be what you read from file.
99 SoWrapperKit *myDesk = new SoWrapperKit();
100 myDesk->setPart("contents", fileContents);
101 myScene->setPart("childList[0]", myDesk);
102
103 // Give the desk a good starting color
104 myDesk->set("material { diffuseColor .8 .3 .1 }");
105
106 // MATERIAL EDITOR!! Attach it to myDesk's material node.
107 // Use the SO_GET_PART macro to get this part from myDesk.
108 SoXtMaterialEditor *mtlEditor = new SoXtMaterialEditor();
109 SoMaterial *mtl = SO_GET_PART(myDesk,"material",SoMaterial);
110 mtlEditor->attach(mtl);
111 mtlEditor->setTitle("Material of Desk");
112 mtlEditor->show();
113
114 // DIRECTIONAL LIGHT EDITOR!! Attach it to the
115 // SoDirectionalLight node within the SoLightKit we made.
116 SoXtDirectionalLightEditor *ltEditor =
117 new SoXtDirectionalLightEditor();
118 SoPath *ltPath = myScene->createPathToPart(
119 "lightList[0].light", TRUE);
120 ltEditor->attach(ltPath);
121 ltEditor->setTitle("Lighting of Desk");
122 ltEditor->show();
123
124 SoXtRenderArea *myRenderArea = new SoXtRenderArea(myWindow);
125
126 // Set up Camera with ViewAll...
127 // -- use the SO_GET_PART macro to get the camera node.
128 // -- viewall is a method on the 'camera' part of
129 // the cameraKit, not on the cameraKit itself. So the part
130 // we ask for is not 'cameraList[0]' (which is of type
131 // SoPerspectiveCameraKit), but
132 // 'cameraList[0].camera' (which is of type
133 // SoPerspectiveCamera).
134 SoPerspectiveCamera *myCamera = SO_GET_PART(myScene,
135 "cameraList[0].camera", SoPerspectiveCamera);
136 SbViewportRegion myRegion(myRenderArea->getSize());
137 myCamera->viewAll(myScene, myRegion);
138
139 myRenderArea->setSceneGraph(myScene);
140 myRenderArea->setTitle("Main Window: Desk In A Scene Kit");
141 myRenderArea->show();
142
143 SoXt::show(myWindow);
144 SoXt::mainLoop();
145 }
146