| 1 |
#include <math.h> |
| 2 |
#include <Inventor/So.h> |
| 3 |
#include <Inventor/nodes/SoTexture2.h> |
| 4 |
|
| 5 |
//////////////////////////////////////////////////////////////////////// |
| 6 |
// |
| 7 |
// the mass here for the smaller primary must less than or equal to 0.0; |
| 8 |
// |
| 9 |
SoSeparator * |
| 10 |
createPrimary(double mass, double pos, float scale, char *txtureFileName) |
| 11 |
// |
| 12 |
//////////////////////////////////////////////////////////////////////// |
| 13 |
{ |
| 14 |
float radius = pow(fabs(mass)/((4.0/3.0)*M_PI),1.0/3.0); |
| 15 |
radius = radius*scale/5.0; |
| 16 |
radius = (radius < 0.01) ? 0.01 : radius; |
| 17 |
|
| 18 |
// create a root |
| 19 |
SoSeparator *primSep = new SoSeparator; |
| 20 |
|
| 21 |
// mapping a texture |
| 22 |
SoTexture2 *primTxture = new SoTexture2; |
| 23 |
primTxture->filename.setValue(txtureFileName); |
| 24 |
primSep->addChild(primTxture); |
| 25 |
|
| 26 |
// define the prim transform |
| 27 |
SoTransform *primXform = new SoTransform; |
| 28 |
primXform->translation.setValue(pos, 0.0, 0.0); |
| 29 |
primXform->rotation.setValue(SbVec3f(1, 0.0, 0.0),M_PI_2); |
| 30 |
primSep->addChild(primXform); |
| 31 |
|
| 32 |
//define the prim |
| 33 |
SoSphere *prim = new SoSphere; |
| 34 |
prim->radius = radius; |
| 35 |
primSep->addChild(prim); |
| 36 |
|
| 37 |
return primSep; |
| 38 |
} |