| 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 16, example 4. |
| 40 |
* |
| 41 |
* This example builds a render area and Material Editor within |
| 42 |
* a window supplied by the application. It uses a Motif form |
| 43 |
* widget to lay both components inside the same window. |
| 44 |
* It attaches the editor to the material of an object. |
| 45 |
*-----------------------------------------------------------*/ |
| 46 |
|
| 47 |
#include <cstdlib> |
| 48 |
#include <Xm/Form.h> |
| 49 |
#include <Inventor/SoDB.h> |
| 50 |
#include <Inventor/Xt/SoXt.h> |
| 51 |
#include <Inventor/Xt/SoXtMaterialEditor.h> |
| 52 |
#include <Inventor/Xt/SoXtRenderArea.h> |
| 53 |
#include <Inventor/nodes/SoDirectionalLight.h> |
| 54 |
#include <Inventor/nodes/SoMaterial.h> |
| 55 |
#include <Inventor/nodes/SoPerspectiveCamera.h> |
| 56 |
#include <Inventor/nodes/SoSeparator.h> |
| 57 |
|
| 58 |
int |
| 59 |
main(int , char **argv) |
| 60 |
{ |
| 61 |
// Initialize Inventor and Xt |
| 62 |
Widget myWindow = SoXt::init(argv[0]); |
| 63 |
|
| 64 |
// Build the form to hold both components |
| 65 |
Widget myForm = XtCreateWidget("Form", |
| 66 |
xmFormWidgetClass, myWindow, NULL, 0); |
| 67 |
|
| 68 |
// Build the render area and Material Editor |
| 69 |
SoXtRenderArea *myRenderArea = new SoXtRenderArea(myForm); |
| 70 |
myRenderArea->setSize(SbVec2s(200, 200)); |
| 71 |
SoXtMaterialEditor *myEditor = |
| 72 |
new SoXtMaterialEditor(myForm); |
| 73 |
|
| 74 |
// Layout the components within the form |
| 75 |
Arg args[8]; |
| 76 |
XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM); |
| 77 |
XtSetArg(args[1], XmNbottomAttachment, XmATTACH_FORM); |
| 78 |
XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM); |
| 79 |
XtSetArg(args[3], XmNrightAttachment, XmATTACH_POSITION); |
| 80 |
XtSetArg(args[4], XmNrightPosition, 40); |
| 81 |
XtSetValues(myRenderArea->getWidget(), args, 5); |
| 82 |
XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM); |
| 83 |
XtSetArg(args[3], XmNleftAttachment, XmATTACH_POSITION); |
| 84 |
XtSetArg(args[4], XmNleftPosition, 41); |
| 85 |
XtSetValues(myEditor->getWidget(), args, 5); |
| 86 |
|
| 87 |
// Create a scene graph |
| 88 |
SoSeparator *root = new SoSeparator; |
| 89 |
SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; |
| 90 |
SoMaterial *myMaterial = new SoMaterial; |
| 91 |
|
| 92 |
root->ref(); |
| 93 |
myCamera->position.setValue(0.212482, -0.881014, 2.5); |
| 94 |
myCamera->heightAngle = M_PI/4; |
| 95 |
root->addChild(myCamera); |
| 96 |
root->addChild(new SoDirectionalLight); |
| 97 |
root->addChild(myMaterial); |
| 98 |
|
| 99 |
// Read the geometry from a file and add to the scene |
| 100 |
SoInput myInput; |
| 101 |
if (!myInput.openFile("/usr/share/src/Inventor/examples/data/dogDish.iv")) |
| 102 |
exit (1); |
| 103 |
SoSeparator *geomObject = SoDB::readAll(&myInput); |
| 104 |
if (geomObject == NULL) |
| 105 |
exit (1); |
| 106 |
root->addChild(geomObject); |
| 107 |
|
| 108 |
// Make the scene graph visible |
| 109 |
myRenderArea->setSceneGraph(root); |
| 110 |
|
| 111 |
// Attach the material editor to the material in the scene |
| 112 |
myEditor->attach(myMaterial); |
| 113 |
|
| 114 |
// Show the main window |
| 115 |
myRenderArea->show(); |
| 116 |
myEditor->show(); |
| 117 |
SoXt::show(myForm); // this calls XtManageChild |
| 118 |
SoXt::show(myWindow); // this calls XtRealizeWidget |
| 119 |
|
| 120 |
// Loop forever |
| 121 |
SoXt::mainLoop(); |
| 122 |
} |