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