| 1 |
#include "createSphere.h" |
| 2 |
|
| 3 |
#include <Inventor/So.h> |
| 4 |
#include <Inventor/SbLinear.h> |
| 5 |
#include "gplaut04.h" |
| 6 |
|
| 7 |
extern const char *autoDir; |
| 8 |
extern float sphereTransparency; |
| 9 |
extern bool sphereFromFile; |
| 10 |
|
| 11 |
SoSeparator * |
| 12 |
createSphere(float where[], float scaler) |
| 13 |
{ |
| 14 |
// create SPHERE |
| 15 |
SoSeparator *sphereSep = new SoSeparator; |
| 16 |
static bool obj = sphereFromFile; |
| 17 |
SoInput mySceneInput; |
| 18 |
|
| 19 |
char *diskFileName = new char[strlen(autoDir) + 32]; |
| 20 |
strcpy(diskFileName, autoDir); |
| 21 |
strcat(diskFileName, "/plaut04/widgets/sphere.iv"); |
| 22 |
if (obj && mySceneInput.openFile(diskFileName)) |
| 23 |
{ |
| 24 |
SoSeparator *sphere = SoDB::readAll(&mySceneInput); |
| 25 |
if (sphere == NULL) |
| 26 |
{ |
| 27 |
obj=FALSE; |
| 28 |
} |
| 29 |
else |
| 30 |
{ |
| 31 |
mySceneInput.closeFile(); |
| 32 |
SoTransform *sphereXform = new SoTransform; |
| 33 |
sphereXform->translation.setValue(where[0],where[1],where[2]); |
| 34 |
sphereXform->scaleFactor.setValue(scaler, scaler, scaler); |
| 35 |
|
| 36 |
sphereSep->addChild(sphereXform); |
| 37 |
sphereSep->addChild(sphere); |
| 38 |
obj = TRUE; |
| 39 |
} |
| 40 |
} |
| 41 |
else |
| 42 |
{ |
| 43 |
obj = FALSE; |
| 44 |
} |
| 45 |
delete [] diskFileName; |
| 46 |
|
| 47 |
if(!obj) |
| 48 |
{ |
| 49 |
SoMaterial *sphereMtl = new SoMaterial; |
| 50 |
sphereMtl->diffuseColor.setValue(1.0,1.0,1.0); |
| 51 |
sphereMtl->transparency = sphereTransparency; |
| 52 |
|
| 53 |
SoComplexity *sphereComplx = new SoComplexity; |
| 54 |
sphereComplx->type = SoComplexity::OBJECT_SPACE; |
| 55 |
sphereComplx->value = 1.0; |
| 56 |
sphereComplx->textureQuality = 0.5; |
| 57 |
|
| 58 |
SoTransform *sphereXform = new SoTransform; |
| 59 |
sphereXform->translation.setValue(where[0],where[1],where[2]); |
| 60 |
|
| 61 |
SoSphere *sphere = new SoSphere; |
| 62 |
sphere->radius = 1.0 * scaler; |
| 63 |
|
| 64 |
sphereSep->addChild(sphereXform); |
| 65 |
sphereSep->addChild(sphereComplx); |
| 66 |
sphereSep->addChild(sphereMtl); |
| 67 |
sphereSep->addChild(sphere); |
| 68 |
} |
| 69 |
|
| 70 |
#ifdef ENABLE_MTL_EDITOR |
| 71 |
#ifdef USE_SOQT |
| 72 |
SoQtMaterialEditor *mtlEditor = new SoQtMaterialEditor; |
| 73 |
#else |
| 74 |
SoXtMaterialEditor *mtlEditor = new SoXtMaterialEditor; |
| 75 |
#endif |
| 76 |
mtlEditor->attach(sphereMtl); |
| 77 |
mtlEditor->show(); |
| 78 |
#endif |
| 79 |
|
| 80 |
return sphereSep; |
| 81 |
} |