| 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 4, example 2. |
| 40 |
* |
| 41 |
* Lights example. |
| 42 |
* Read in an object from a file. |
| 43 |
* Use the ExaminerViewer to view it with two light sources. |
| 44 |
* The red directional light doesn't move; the green point |
| 45 |
* light is moved back and forth using a shuttle node. |
| 46 |
*------------------------------------------------------------*/ |
| 47 |
|
| 48 |
#include <cstdlib> |
| 49 |
#include <Inventor/SoDB.h> |
| 50 |
#include <Inventor/Xt/SoXt.h> |
| 51 |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
| 52 |
#include <Inventor/nodes/SoCone.h> |
| 53 |
#include <Inventor/nodes/SoDirectionalLight.h> |
| 54 |
#include <Inventor/nodes/SoMaterial.h> |
| 55 |
#include <Inventor/nodes/SoPointLight.h> |
| 56 |
#include <Inventor/nodes/SoSeparator.h> |
| 57 |
#include <Inventor/nodes/SoShuttle.h> |
| 58 |
#include <Inventor/nodes/SoTransformSeparator.h> |
| 59 |
|
| 60 |
int |
| 61 |
main(int , char **argv) |
| 62 |
{ |
| 63 |
// Initialize Inventor and Xt |
| 64 |
Widget myWindow = SoXt::init(argv[0]); |
| 65 |
if (myWindow == NULL) exit(1); |
| 66 |
|
| 67 |
SoSeparator *root = new SoSeparator; |
| 68 |
root->ref(); |
| 69 |
|
| 70 |
// Add a directional light |
| 71 |
SoDirectionalLight *myDirLight = new SoDirectionalLight; |
| 72 |
myDirLight->direction.setValue(0, -1, -1); |
| 73 |
myDirLight->color.setValue(1, 0, 0); |
| 74 |
root->addChild(myDirLight); |
| 75 |
|
| 76 |
// Put the shuttle and the light below a transform separator. |
| 77 |
// A transform separator pushes and pops the transformation |
| 78 |
// just like a separator node, but other aspects of the state |
| 79 |
// are not pushed and popped. So the shuttle's translation |
| 80 |
// will affect only the light. But the light will shine on |
| 81 |
// the rest of the scene. |
| 82 |
SoTransformSeparator *myTransformSeparator = |
| 83 |
new SoTransformSeparator; |
| 84 |
root->addChild(myTransformSeparator); |
| 85 |
|
| 86 |
// A shuttle node translates back and forth between the two |
| 87 |
// fields translation0 and translation1. |
| 88 |
// This moves the light. |
| 89 |
SoShuttle *myShuttle = new SoShuttle; |
| 90 |
myTransformSeparator->addChild(myShuttle); |
| 91 |
myShuttle->translation0.setValue(-2, -1, 3); |
| 92 |
myShuttle->translation1.setValue( 1, 2, -3); |
| 93 |
|
| 94 |
// Add the point light below the transformSeparator |
| 95 |
SoPointLight *myPointLight = new SoPointLight; |
| 96 |
myTransformSeparator->addChild(myPointLight); |
| 97 |
myPointLight->color.setValue(0, 1, 0); |
| 98 |
|
| 99 |
root->addChild(new SoCone); |
| 100 |
|
| 101 |
SoXtExaminerViewer *myViewer = |
| 102 |
new SoXtExaminerViewer(myWindow); |
| 103 |
myViewer->setSceneGraph(root); |
| 104 |
myViewer->setTitle("Lights"); |
| 105 |
myViewer->setHeadlight(FALSE); |
| 106 |
myViewer->show(); |
| 107 |
|
| 108 |
SoXt::show(myWindow); |
| 109 |
SoXt::mainLoop(); |
| 110 |
} |