| 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 15, example 4. |
| 40 |
* |
| 41 |
* Same as chapter 15, example 2, with one difference: |
| 42 |
* The draggers are customized to use different geometry. |
| 43 |
* We create our own scene graphs for the parts "translator" |
| 44 |
* and "translatorActive." |
| 45 |
* Then we call setPart() to replace these two parts with our |
| 46 |
* new scene graphs. (Remember, draggers are derived from |
| 47 |
* nodekits, so it's easy to change the parts). |
| 48 |
*----------------------------------------------------------------*/ |
| 49 |
|
| 50 |
#include <cstdlib> |
| 51 |
#include <Inventor/Xt/SoXt.h> |
| 52 |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
| 53 |
#include <Inventor/draggers/SoTranslate1Dragger.h> |
| 54 |
#include <Inventor/engines/SoCalculator.h> |
| 55 |
#include <Inventor/nodekits/SoShapeKit.h> |
| 56 |
#include <Inventor/nodes/SoCube.h> |
| 57 |
#include <Inventor/nodes/SoMaterial.h> |
| 58 |
#include <Inventor/nodes/SoSeparator.h> |
| 59 |
#include <Inventor/nodes/SoText3.h> |
| 60 |
#include <Inventor/nodes/SoTransform.h> |
| 61 |
|
| 62 |
int |
| 63 |
main(int , char **argv) |
| 64 |
{ |
| 65 |
Widget myWindow = SoXt::init(argv[0]); |
| 66 |
if (myWindow == NULL) exit(1); |
| 67 |
|
| 68 |
SoSeparator *root = new SoSeparator; |
| 69 |
root->ref(); |
| 70 |
|
| 71 |
// Create 3 translate1Draggers and place them in space. |
| 72 |
SoSeparator *xDragSep = new SoSeparator; |
| 73 |
SoSeparator *yDragSep = new SoSeparator; |
| 74 |
SoSeparator *zDragSep = new SoSeparator; |
| 75 |
root->addChild(xDragSep); |
| 76 |
root->addChild(yDragSep); |
| 77 |
root->addChild(zDragSep); |
| 78 |
// Separators will each hold a different transform |
| 79 |
SoTransform *xDragXf = new SoTransform; |
| 80 |
SoTransform *yDragXf = new SoTransform; |
| 81 |
SoTransform *zDragXf = new SoTransform; |
| 82 |
xDragXf->set("translation 0 -4 8"); |
| 83 |
yDragXf->set("translation -8 0 8 rotation 0 0 1 1.57"); |
| 84 |
zDragXf->set("translation -8 -4 0 rotation 0 1 0 -1.57"); |
| 85 |
xDragSep->addChild(xDragXf); |
| 86 |
yDragSep->addChild(yDragXf); |
| 87 |
zDragSep->addChild(zDragXf); |
| 88 |
|
| 89 |
// Add the draggers under the separators, after transforms |
| 90 |
SoTranslate1Dragger *xDragger = new SoTranslate1Dragger; |
| 91 |
SoTranslate1Dragger *yDragger = new SoTranslate1Dragger; |
| 92 |
SoTranslate1Dragger *zDragger = new SoTranslate1Dragger; |
| 93 |
xDragSep->addChild(xDragger); |
| 94 |
yDragSep->addChild(yDragger); |
| 95 |
zDragSep->addChild(zDragger); |
| 96 |
|
| 97 |
///////////////////////////////////////////////////////////// |
| 98 |
// CODE FOR The Inventor Mentor STARTS HERE |
| 99 |
|
| 100 |
// Create myTranslator and myTranslatorActive. |
| 101 |
// These are custom geometry for the draggers. |
| 102 |
SoSeparator *myTranslator = new SoSeparator; |
| 103 |
SoSeparator *myTranslatorActive = new SoSeparator; |
| 104 |
myTranslator->ref(); |
| 105 |
myTranslatorActive->ref(); |
| 106 |
// Materials for the dragger in regular and active states |
| 107 |
SoMaterial *myMtl = new SoMaterial; |
| 108 |
SoMaterial *myActiveMtl = new SoMaterial; |
| 109 |
myMtl->diffuseColor.setValue(1,1,1); |
| 110 |
myActiveMtl->diffuseColor.setValue(1,1,0); |
| 111 |
myTranslator->addChild(myMtl); |
| 112 |
myTranslatorActive->addChild(myActiveMtl); |
| 113 |
// Same shape for both versions. |
| 114 |
SoCube *myCube = new SoCube; |
| 115 |
myCube->set("width 3 height .4 depth .4"); |
| 116 |
myTranslator->addChild(myCube); |
| 117 |
myTranslatorActive->addChild(myCube); |
| 118 |
|
| 119 |
// Now, customize the draggers with the pieces we created. |
| 120 |
xDragger->setPart("translator",myTranslator); |
| 121 |
xDragger->setPart("translatorActive",myTranslatorActive); |
| 122 |
yDragger->setPart("translator",myTranslator); |
| 123 |
yDragger->setPart("translatorActive",myTranslatorActive); |
| 124 |
zDragger->setPart("translator",myTranslator); |
| 125 |
zDragger->setPart("translatorActive",myTranslatorActive); |
| 126 |
|
| 127 |
// CODE FOR The Inventor Mentor ENDS HERE |
| 128 |
///////////////////////////////////////////////////////////// |
| 129 |
|
| 130 |
// Create shape kit for the 3D text |
| 131 |
// The text says 'Slide Cubes To Move Me' |
| 132 |
SoShapeKit *textKit = new SoShapeKit; |
| 133 |
root->addChild(textKit); |
| 134 |
SoText3 *myText3 = new SoText3; |
| 135 |
textKit->setPart("shape", myText3); |
| 136 |
myText3->justification = SoText3::CENTER; |
| 137 |
myText3->string.set1Value(0,"Slide Cubes"); |
| 138 |
myText3->string.set1Value(1,"To"); |
| 139 |
myText3->string.set1Value(2,"Move Me"); |
| 140 |
textKit->set("font { size 2}"); |
| 141 |
textKit->set("material { diffuseColor 1 1 0}"); |
| 142 |
|
| 143 |
// Create shape kit for surrounding box. |
| 144 |
// It's an unpickable cube, sized as (16,8,16) |
| 145 |
SoShapeKit *boxKit = new SoShapeKit; |
| 146 |
root->addChild(boxKit); |
| 147 |
boxKit->setPart("shape", new SoCube); |
| 148 |
boxKit->set("drawStyle { style LINES }"); |
| 149 |
boxKit->set("pickStyle { style UNPICKABLE }"); |
| 150 |
boxKit->set("material { emissiveColor 1 0 1 }"); |
| 151 |
boxKit->set("shape { width 16 height 8 depth 16 }"); |
| 152 |
|
| 153 |
// Create the calculator to make a translation |
| 154 |
// for the text. The x component of a translate1Dragger's |
| 155 |
// translation field shows how far it moved in that |
| 156 |
// direction. So our text's translation is: |
| 157 |
// (xDragTranslate[0],yDragTranslate[0],zDragTranslate[0]) |
| 158 |
SoCalculator *myCalc = new SoCalculator; |
| 159 |
myCalc->ref(); |
| 160 |
myCalc->A.connectFrom(&xDragger->translation); |
| 161 |
myCalc->B.connectFrom(&yDragger->translation); |
| 162 |
myCalc->C.connectFrom(&zDragger->translation); |
| 163 |
myCalc->expression = "oA = vec3f(A[0],B[0],C[0])"; |
| 164 |
|
| 165 |
// Connect the the translation in textKit from myCalc |
| 166 |
SoTransform *textXf |
| 167 |
= (SoTransform *) textKit->getPart("transform",TRUE); |
| 168 |
textXf->translation.connectFrom(&myCalc->oA); |
| 169 |
|
| 170 |
SoXtExaminerViewer *myViewer = |
| 171 |
new SoXtExaminerViewer(myWindow); |
| 172 |
myViewer->setSceneGraph(root); |
| 173 |
myViewer->setTitle("Customized Sliders"); |
| 174 |
myViewer->viewAll(); |
| 175 |
myViewer->show(); |
| 176 |
|
| 177 |
SoXt::show(myWindow); |
| 178 |
SoXt::mainLoop(); |
| 179 |
} |