00001
00002
00003 #include "Iguana/Inventor/interface/IgSoArrow.h"
00004 #include <Inventor/nodes/SoTranslation.h>
00005 #include <Inventor/nodes/SoRotation.h>
00006 #include <Inventor/nodes/SoRotationXYZ.h>
00007 #include <Inventor/nodes/SoCylinder.h>
00008 #include <Inventor/nodes/SoCone.h>
00009 #include <Inventor/nodes/SoScale.h>
00010
00011
00012
00013
00014
00015
00016
00017
00018 SO_KIT_SOURCE (IgSoArrow);
00019
00020
00021
00022
00023
00024 void
00025 IgSoArrow::initClass ()
00026 { SO_KIT_INIT_CLASS (IgSoArrow, IgSoShapeKit, "IgSoShapeKit"); }
00027
00028 IgSoArrow::IgSoArrow (void)
00029 {
00030 SO_KIT_CONSTRUCTOR (IgSoArrow);
00031
00032 SO_KIT_ADD_FIELD (tail, (0, 0, 0));
00033 SO_KIT_ADD_FIELD (tip, (0, 1, 0));
00034
00035 SO_KIT_ADD_CATALOG_ENTRY (finalTranslation, SoTranslation, FALSE, separator,\x0, TRUE);
00036 SO_KIT_ADD_CATALOG_ENTRY (scale, SoScale, FALSE, separator,\x0, TRUE);
00037 SO_KIT_ADD_CATALOG_ENTRY (myRotation, SoRotation, FALSE, separator,\x0, TRUE);
00038 SO_KIT_ADD_CATALOG_ENTRY (rot, SoRotationXYZ, FALSE, separator,\x0, TRUE);
00039 SO_KIT_ADD_CATALOG_ENTRY (zTranslation, SoTranslation, FALSE, separator,\x0, TRUE);
00040 SO_KIT_ADD_CATALOG_ENTRY (axisCyl, SoCylinder, FALSE, separator,\x0, TRUE);
00041 SO_KIT_ADD_CATALOG_ENTRY (cTranslation, SoTranslation, FALSE, separator,\x0, TRUE);
00042 SO_KIT_ADD_CATALOG_ENTRY (axisCone, SoCone, FALSE, separator,\x0, TRUE);
00043 SO_KIT_INIT_INSTANCE ();
00044 setUpConnections (true, true);
00045 }
00046
00047 void
00048 IgSoArrow::refresh (void)
00049 {
00050 static const float ARROWSIZE = 0.02;
00051 SoTranslation *finalTranslation = new SoTranslation;
00052 SoScale *scale = new SoScale;
00053 SoRotation *myRotation = new SoRotation;
00054 SoRotationXYZ *rot = new SoRotationXYZ;
00055 SoTranslation *zTranslation = new SoTranslation;
00056 SoCylinder *axisCyl = new SoCylinder;
00057 SoTranslation *cTranslation = new SoTranslation;
00058 SoCone *axisCone = new SoCone;
00059 SbVec3f mtail = tail.getValue ();
00060 SbVec3f mtip = tip.getValue ();
00061 SbVec3f mdiff = mtip - mtail;
00062 double length = mdiff.length ();
00063 SbVec3f ax = SbVec3f (0, 0, 1).cross (mdiff);
00064 double an = asin (ax.length () / length);
00065
00066 if (mdiff[2] < 0)
00067 an = -an;
00068
00069 finalTranslation->translation.setValue (mtail);
00070 scale->scaleFactor.setValue (length/2, length/2, length/2);
00071 myRotation->rotation.setValue (ax, an);
00072 zTranslation->translation.setValue (0, 1, 0);
00073 rot->axis = SoRotationXYZ::X;
00074 rot->angle = (mdiff[2] < 0) ? -M_PI/2. : M_PI/2.;
00075 axisCyl->radius.setValue (2 * ARROWSIZE);
00076 cTranslation->translation.setValue (0, 1, 0);
00077 axisCone->bottomRadius.setValue (4 * ARROWSIZE);
00078 axisCone->height.setValue (8 * ARROWSIZE);
00079
00080 setPart ("finalTranslation", finalTranslation);
00081 setPart ("scale", scale);
00082 setPart ("myRotation", myRotation);
00083 setPart ("rot", rot);
00084 setPart ("zTranslation", zTranslation);
00085 setPart ("axisCyl", axisCyl);
00086 setPart ("cTranslation", cTranslation);
00087 setPart ("axisCone", axisCone);
00088 }