00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030 #include <Inventor/SoDB.h>
00031 #include <Inventor/SoInput.h>
00032 #include <Inventor/engines/SoCalculator.h>
00033 #include <Inventor/misc/SoChildList.h>
00034 #include <Inventor/nodes/SoCylinder.h>
00035 #include <Inventor/nodes/SoScale.h>
00036 #include <Inventor/nodes/SoTranslation.h>
00037
00038 #include <assert.h>
00039 #include <math.h>
00040
00041 #include "SoTorquePointer.h"
00042 #include "curvedArrow.dat"
00043
00044 SO_NODE_SOURCE(SoTorquePointer);
00045
00047 SoSeparator *SoTorquePointer::curvedArrow;
00048
00055 void
00056 SoTorquePointer::initClass()
00057 {
00058
00059 SO_NODE_INIT_CLASS(SoTorquePointer, SoComplexShape, "SoComplexShape");
00060
00061 SoInput in;
00062 in.setBuffer((void *) curvedArrowData, (size_t) sizeof(curvedArrowData));
00063 curvedArrow = SoDB::readAll(&in);
00064
00065 curvedArrow->ref();
00066 }
00067
00071 SoTorquePointer::SoTorquePointer()
00072 {
00073 children = new SoChildList(this);
00074
00075 SO_NODE_CONSTRUCTOR(SoTorquePointer);
00076 SO_NODE_ADD_FIELD(cylRadius, (0.5));
00077 SO_NODE_ADD_FIELD(height, (4.0));
00078 }
00079
00083 SoTorquePointer::~SoTorquePointer()
00084 {
00085 delete children;
00086 }
00087
00094 void
00095 SoTorquePointer::generateChildren()
00096 {
00097
00098
00099 assert (children->getLength() == 0);
00100
00101
00102
00103 SoCalculator *calEngine = new SoCalculator;
00104 calEngine->a.connectFrom(&height);
00105 calEngine->b.connectFrom(&cylRadius);
00106
00107
00108 calEngine->expression.set1Value(0, "oA = vec3f(0,a/2.0,0)");
00109
00110
00111 calEngine->expression.set1Value(1, "oB = vec3f(0.0, 0.95*a, 0.0)");
00112
00113
00114 calEngine->expression.set1Value(2, "oC = vec3f(b/0.5,b/0.5,b/0.5)");
00115
00116 SoCylinder *shaft = new SoCylinder;
00117 shaft->radius.connectFrom(&cylRadius);
00118 shaft->height.connectFrom(&height);
00119
00120 SoTranslation *shaftTran = new SoTranslation;
00121 shaftTran->translation.connectFrom(&calEngine->oA);
00122
00123 SoTranslation *arrowTran = new SoTranslation;
00124 arrowTran->translation.connectFrom(&calEngine->oB);
00125
00126 SoScale *arrowScale = new SoScale;
00127 arrowScale->scaleFactor.connectFrom(&calEngine->oC);
00128
00129 SoSeparator *arrowSep = new SoSeparator;
00130 arrowSep->addChild(arrowTran);
00131 arrowSep->addChild(arrowScale);
00132 arrowSep->addChild(curvedArrow);
00133
00134 SoSeparator *root = new SoSeparator;
00135 root->addChild(arrowSep);
00136 root->addChild(shaftTran);
00137 root->addChild(shaft);
00138
00139 children->append(root);
00140 }
00141
00142
00143
00144
00145
00146
00147