| 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 14, example 1. |
| 40 |
* |
| 41 |
* Use SoShapeKits to create two 3-D words, "NICE" and "HAPPY" |
| 42 |
* Use nodekit methods to access the fields of the "material" |
| 43 |
* and "transform" parts. |
| 44 |
* Use a calculator engine and an elapsed time engine to make |
| 45 |
* the words change color and fly about the screen. |
| 46 |
*----------------------------------------------------------------*/ |
| 47 |
|
| 48 |
#include <cstdlib> |
| 49 |
#include <Inventor/Xt/SoXt.h> |
| 50 |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
| 51 |
#include <Inventor/engines/SoCalculator.h> |
| 52 |
#include <Inventor/engines/SoElapsedTime.h> |
| 53 |
#include <Inventor/nodekits/SoShapeKit.h> |
| 54 |
#include <Inventor/nodes/SoMaterial.h> |
| 55 |
#include <Inventor/nodes/SoSeparator.h> |
| 56 |
#include <Inventor/nodes/SoText3.h> |
| 57 |
#include <Inventor/nodes/SoTransform.h> |
| 58 |
|
| 59 |
int |
| 60 |
main(int , char **argv) |
| 61 |
{ |
| 62 |
Widget myWindow = SoXt::init(argv[0]); |
| 63 |
if (myWindow == NULL) exit(1); |
| 64 |
|
| 65 |
SoSeparator *root = new SoSeparator; |
| 66 |
root->ref(); |
| 67 |
|
| 68 |
// Create shape kits with the words "HAPPY" and "NICE" |
| 69 |
SoShapeKit *happyKit = new SoShapeKit; |
| 70 |
root->addChild(happyKit); |
| 71 |
happyKit->setPart("shape", new SoText3); |
| 72 |
happyKit->set("shape { parts ALL string \"HAPPY\"}"); |
| 73 |
happyKit->set("font { size 2}"); |
| 74 |
|
| 75 |
SoShapeKit *niceKit = new SoShapeKit; |
| 76 |
root->addChild(niceKit); |
| 77 |
niceKit->setPart("shape", new SoText3); |
| 78 |
niceKit->set("shape { parts ALL string \"NICE\"}"); |
| 79 |
niceKit->set("font { size 2}"); |
| 80 |
|
| 81 |
// Create the Elapsed Time engine |
| 82 |
SoElapsedTime *myTimer = new SoElapsedTime; |
| 83 |
myTimer->ref(); |
| 84 |
|
| 85 |
// Create two calculator - one for HAPPY, one for NICE. |
| 86 |
SoCalculator *happyCalc = new SoCalculator; |
| 87 |
happyCalc->ref(); |
| 88 |
happyCalc->a.connectFrom(&myTimer->timeOut); |
| 89 |
happyCalc->expression = "ta=cos(2*a); tb=sin(2*a);\ |
| 90 |
oA = vec3f(3*pow(ta,3),3*pow(tb,3),1); \ |
| 91 |
oB = vec3f(fabs(ta)+.1,fabs(.5*fabs(tb))+.1,1);\ |
| 92 |
oC = vec3f(fabs(ta),fabs(tb),.5)"; |
| 93 |
|
| 94 |
// The second calculator uses different arguments to |
| 95 |
// sin() and cos(), so it moves out of phase. |
| 96 |
SoCalculator *niceCalc = new SoCalculator; |
| 97 |
niceCalc->ref(); |
| 98 |
niceCalc->a.connectFrom(&myTimer->timeOut); |
| 99 |
niceCalc->expression = "ta=cos(2*a+2); tb=sin(2*a+2);\ |
| 100 |
oA = vec3f(3*pow(ta,3),3*pow(tb,3),1); \ |
| 101 |
oB = vec3f(fabs(ta)+.1,fabs(.5*fabs(tb))+.1,1); \ |
| 102 |
oC = vec3f(fabs(ta),fabs(tb),.5)"; |
| 103 |
|
| 104 |
// Connect the transforms from the calculators... |
| 105 |
SoTransform *happyXf |
| 106 |
= (SoTransform *) happyKit->getPart("transform",TRUE); |
| 107 |
happyXf->translation.connectFrom(&happyCalc->oA); |
| 108 |
happyXf->scaleFactor.connectFrom(&happyCalc->oB); |
| 109 |
SoTransform *niceXf |
| 110 |
= (SoTransform *) niceKit->getPart("transform",TRUE); |
| 111 |
niceXf->translation.connectFrom(&niceCalc->oA); |
| 112 |
niceXf->scaleFactor.connectFrom(&niceCalc->oB); |
| 113 |
|
| 114 |
// Connect the materials from the calculators... |
| 115 |
SoMaterial *happyMtl |
| 116 |
= (SoMaterial *) happyKit->getPart("material",TRUE); |
| 117 |
happyMtl->diffuseColor.connectFrom(&happyCalc->oC); |
| 118 |
SoMaterial *niceMtl |
| 119 |
= (SoMaterial *) niceKit->getPart("material",TRUE); |
| 120 |
niceMtl->diffuseColor.connectFrom(&niceCalc->oC); |
| 121 |
|
| 122 |
SoXtExaminerViewer *myViewer = |
| 123 |
new SoXtExaminerViewer(myWindow); |
| 124 |
myViewer->setSceneGraph(root); |
| 125 |
myViewer->setTitle("Frolicking Words"); |
| 126 |
myViewer->viewAll(); |
| 127 |
myViewer->show(); |
| 128 |
|
| 129 |
SoXt::show(myWindow); |
| 130 |
SoXt::mainLoop(); |
| 131 |
} |