1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 #include <Inventor/Qt/SoQt.h>
34 #include <Inventor/Qt/SoQtRenderArea.h>
35
36 #include <Inventor/nodes/SoCube.h>
37 #include <Inventor/nodes/SoRotor.h>
38 #include <Inventor/nodes/SoArray.h>
39 #include <Inventor/nodes/SoDirectionalLight.h>
40 #include <Inventor/nodes/SoPerspectiveCamera.h>
41 #include <Inventor/nodes/SoSeparator.h>
42
43 /*
44 This is a simple example, demonstrating proper behaviour for a
45 SoQtRenderArea when built with the 'embed' flag set to TRUE.
46 */
47
get_scene_graph(void)48 static SoSeparator * get_scene_graph(void)
49 {
50 SoSeparator * root = new SoSeparator;
51
52 SoGroup * group = new SoGroup;
53
54 SoRotor * rotor = new SoRotor;
55 rotor->rotation = SbRotation(SbVec3f(0.2f, 0.5f, 0.9f), float(M_PI)/4.0f);
56 group->addChild(rotor);
57
58 SoCube * cube = new SoCube;
59 group->addChild(cube);
60
61 SoArray * array = new SoArray;
62 array->origin = SoArray::CENTER;
63 array->addChild(group);
64 array->numElements1 = 2;
65 array->numElements2 = 2;
66 array->separation1 = SbVec3f(4, 0, 0);
67 array->separation2 = SbVec3f(0, 4, 0);
68
69 root->addChild(array);
70 return root;
71 }
72
main(int argc,char ** argv)73 int main(int argc, char ** argv)
74 {
75 QWidget * window = SoQt::init(argv[0]);
76
77 SoSeparator * root = new SoSeparator;
78 root->ref();
79 SoPerspectiveCamera * camera;
80 root->addChild(camera = new SoPerspectiveCamera);
81 root->addChild(new SoDirectionalLight);
82 SoSeparator * userroot = get_scene_graph();
83 root->addChild(userroot);
84
85
86 SoQtRenderArea * renderarea =
87 new SoQtRenderArea(window, "Renderarea demonstration", FALSE);
88 camera->viewAll( userroot, renderarea->getViewportRegion() );
89 renderarea->setSceneGraph(root);
90 renderarea->setBackgroundColor(SbColor(0.0f, 0.2f, 0.3f));
91 renderarea->show();
92
93 SoQt::show(window);
94 SoQt::mainLoop();
95
96 delete renderarea;
97 root->unref();
98 return 0;
99 }
100