00001
00002
00003 #include "Iguana/Inventor/interface/IgSoJet.h"
00004 #include <Inventor/nodes/SoSeparator.h>
00005 #include <Inventor/nodes/SoCone.h>
00006 #include <Inventor/nodes/SoTransform.h>
00007
00008
00009
00010
00011
00012
00013
00014
00015 SO_KIT_SOURCE (IgSoJet);
00016
00017
00018
00019
00020
00021 void
00022 IgSoJet::initClass (void)
00023 { SO_KIT_INIT_CLASS (IgSoJet, IgSoShapeKit, "IgSoShapeKit"); }
00024
00025 IgSoJet::IgSoJet (void)
00026 {
00027 SO_KIT_CONSTRUCTOR (IgSoJet);
00028 SO_KIT_ADD_FIELD (energy, (0.0));
00029 SO_KIT_ADD_FIELD (theta, (0.0));
00030 SO_KIT_ADD_FIELD (phi, (0.0));
00031 SO_KIT_ADD_FIELD (thrust, (1.0));
00032 SO_KIT_ADD_FIELD (maxZ, (4.0)) ;
00033 SO_KIT_ADD_FIELD (maxR, (2.0)) ;
00034 SO_KIT_ADD_FIELD (maxEnergy, (100.0)) ;
00035 SO_KIT_ADD_CATALOG_ENTRY (body, SoSeparator, FALSE, separator,\x0, TRUE);
00036 SO_KIT_ADD_CATALOG_ENTRY (bodyTrans, SoTransform, FALSE, body,\x0, TRUE);
00037 SO_KIT_ADD_CATALOG_ENTRY (bodyCone, SoCone, FALSE, body,\x0, TRUE);
00038 SO_KIT_ADD_CATALOG_ENTRY (hat, SoSeparator, FALSE, separator,\x0, TRUE);
00039 SO_KIT_ADD_CATALOG_ENTRY (hatTrans, SoTransform, FALSE, hat,\x0, TRUE);
00040 SO_KIT_ADD_CATALOG_ENTRY (hatCone, SoCone, FALSE, hat,\x0, TRUE);
00041 SO_KIT_INIT_INSTANCE ();
00042 setUpConnections (true, true);
00043 }
00044
00045 void
00046 IgSoJet::refresh (void)
00047 {
00048 SoTransform *bodyTrans = new SoTransform;
00049 SoCone *bodyCone = new SoCone;
00050 SoTransform *hatTrans = new SoTransform;
00051 SoCone *hatCone = new SoCone;
00052
00053
00054 float theta = this->theta.getValue ();
00055 float phi = this->phi.getValue ();
00056 double ct = cos (theta);
00057 double st = sin (theta);
00058 double cp = cos (phi);
00059 double sp = sin (phi);
00060
00061
00062
00063
00064 SbVec3f rotVec (ct, 0.0, -st * cp);
00065 float alpha = acos (st * sp);
00066
00067
00068
00069
00070
00071 float length1 = ct ? maxZ.getValue () / fabs (ct) : maxZ.getValue ();
00072 float length2 = st ? maxR.getValue () / fabs (st) : maxR.getValue ();
00073 float bodyHeight = length1 < length2 ? length1 : length2;
00074 float bodyRadius = 0.3 * (1.0 / (thrust.getValue () + 0.001));
00075
00076 bodyCone->bottomRadius = bodyRadius;
00077 bodyCone->height = bodyHeight;
00078 bodyTrans->rotation.setValue (rotVec, alpha + M_PI);
00079 bodyTrans->translation = SbVec3f (bodyHeight * st * cp / 2.0,
00080 bodyHeight * st * sp / 2.0,
00081 bodyHeight * ct / 2.0);
00082
00083
00084
00085
00086
00087 float hatRadius = 1.4 * bodyRadius;
00088 float hatHeight = maxR.getValue () * energy.getValue ()
00089 / maxEnergy.getValue ();
00090
00091 hatCone->bottomRadius = hatRadius;
00092 hatCone->height = hatHeight;
00093 hatTrans->rotation.setValue (rotVec, alpha);
00094 hatTrans->translation = SbVec3f ((bodyHeight + hatHeight / 2.0) * st * cp,
00095 (bodyHeight + hatHeight / 2.0) * st * sp,
00096 (bodyHeight + hatHeight / 2.0) * ct);
00097
00098 setPart ("bodyTrans", bodyTrans);
00099 setPart ("bodyCone", bodyCone);
00100 setPart ("hatTrans", hatTrans);
00101 setPart ("hatCone", hatCone);
00102 }