| 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 2. |
| 40 |
* |
| 41 |
* Uses 3 translate1Draggers to change the x, y, and z |
| 42 |
* components of a translation. A calculator engine assembles |
| 43 |
* the components. |
| 44 |
* Arranges these draggers along edges of a box containing the |
| 45 |
* 3D text to be moved. |
| 46 |
* The 3D text and the box are made with SoShapeKits |
| 47 |
*----------------------------------------------------------------*/ |
| 48 |
|
| 49 |
#include <cstdlib> |
| 50 |
#include <Inventor/Xt/SoXt.h> |
| 51 |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
| 52 |
#include <Inventor/draggers/SoTranslate1Dragger.h> |
| 53 |
#include <Inventor/engines/SoCalculator.h> |
| 54 |
#include <Inventor/nodekits/SoShapeKit.h> |
| 55 |
#include <Inventor/nodes/SoCube.h> |
| 56 |
#include <Inventor/nodes/SoSeparator.h> |
| 57 |
#include <Inventor/nodes/SoText3.h> |
| 58 |
#include <Inventor/nodes/SoTransform.h> |
| 59 |
|
| 60 |
int |
| 61 |
main(int , char **argv) |
| 62 |
{ |
| 63 |
Widget myWindow = SoXt::init(argv[0]); |
| 64 |
if (myWindow == NULL) exit(1); |
| 65 |
|
| 66 |
SoSeparator *root = new SoSeparator; |
| 67 |
root->ref(); |
| 68 |
|
| 69 |
// Create 3 translate1Draggers and place them in space. |
| 70 |
SoSeparator *xDragSep = new SoSeparator; |
| 71 |
SoSeparator *yDragSep = new SoSeparator; |
| 72 |
SoSeparator *zDragSep = new SoSeparator; |
| 73 |
root->addChild(xDragSep); |
| 74 |
root->addChild(yDragSep); |
| 75 |
root->addChild(zDragSep); |
| 76 |
// Separators will each hold a different transform |
| 77 |
SoTransform *xDragXf = new SoTransform; |
| 78 |
SoTransform *yDragXf = new SoTransform; |
| 79 |
SoTransform *zDragXf = new SoTransform; |
| 80 |
xDragXf->set("translation 0 -4 8"); |
| 81 |
yDragXf->set("translation -8 0 8 rotation 0 0 1 1.57"); |
| 82 |
zDragXf->set("translation -8 -4 0 rotation 0 1 0 -1.57"); |
| 83 |
xDragSep->addChild(xDragXf); |
| 84 |
yDragSep->addChild(yDragXf); |
| 85 |
zDragSep->addChild(zDragXf); |
| 86 |
|
| 87 |
// Add the draggers under the separators, after transforms |
| 88 |
SoTranslate1Dragger *xDragger = new SoTranslate1Dragger; |
| 89 |
SoTranslate1Dragger *yDragger = new SoTranslate1Dragger; |
| 90 |
SoTranslate1Dragger *zDragger = new SoTranslate1Dragger; |
| 91 |
xDragSep->addChild(xDragger); |
| 92 |
yDragSep->addChild(yDragger); |
| 93 |
zDragSep->addChild(zDragger); |
| 94 |
|
| 95 |
// Create shape kit for the 3D text |
| 96 |
// The text says 'Slide Cubes To Move Me' |
| 97 |
SoShapeKit *textKit = new SoShapeKit; |
| 98 |
root->addChild(textKit); |
| 99 |
SoText3 *myText3 = new SoText3; |
| 100 |
textKit->setPart("shape", myText3); |
| 101 |
myText3->justification = SoText3::CENTER; |
| 102 |
myText3->string.set1Value(0,"Slide Arrows"); |
| 103 |
myText3->string.set1Value(1,"To"); |
| 104 |
myText3->string.set1Value(2,"Move Me"); |
| 105 |
textKit->set("font { size 2}"); |
| 106 |
textKit->set("material { diffuseColor 1 1 0}"); |
| 107 |
|
| 108 |
// Create shape kit for surrounding box. |
| 109 |
// It's an unpickable cube, sized as (16,8,16) |
| 110 |
SoShapeKit *boxKit = new SoShapeKit; |
| 111 |
root->addChild(boxKit); |
| 112 |
boxKit->setPart("shape", new SoCube); |
| 113 |
boxKit->set("drawStyle { style LINES }"); |
| 114 |
boxKit->set("pickStyle { style UNPICKABLE }"); |
| 115 |
boxKit->set("material { emissiveColor 1 0 1 }"); |
| 116 |
boxKit->set("shape { width 16 height 8 depth 16 }"); |
| 117 |
|
| 118 |
// Create the calculator to make a translation |
| 119 |
// for the text. The x component of a translate1Dragger's |
| 120 |
// translation field shows how far it moved in that |
| 121 |
// direction. So our text's translation is: |
| 122 |
// (xDragTranslate[0],yDragTranslate[0],zDragTranslate[0]) |
| 123 |
SoCalculator *myCalc = new SoCalculator; |
| 124 |
myCalc->ref(); |
| 125 |
myCalc->A.connectFrom(&xDragger->translation); |
| 126 |
myCalc->B.connectFrom(&yDragger->translation); |
| 127 |
myCalc->C.connectFrom(&zDragger->translation); |
| 128 |
myCalc->expression = "oA = vec3f(A[0],B[0],C[0])"; |
| 129 |
|
| 130 |
// Connect the the translation in textKit from myCalc |
| 131 |
SoTransform *textXf |
| 132 |
= (SoTransform *) textKit->getPart("transform",TRUE); |
| 133 |
textXf->translation.connectFrom(&myCalc->oA); |
| 134 |
|
| 135 |
SoXtExaminerViewer *myViewer = |
| 136 |
new SoXtExaminerViewer(myWindow); |
| 137 |
myViewer->setSceneGraph(root); |
| 138 |
myViewer->setTitle("Slider Box"); |
| 139 |
myViewer->viewAll(); |
| 140 |
myViewer->show(); |
| 141 |
|
| 142 |
SoXt::show(myWindow); |
| 143 |
SoXt::mainLoop(); |
| 144 |
} |