00001
00002
00003 #include "Iguana/Inventor/interface/IgSoTowerRadii.h"
00004 #include "Inventor/nodes/SoMarkerSet.h"
00005 #include "Inventor/nodes/SoLineSet.h"
00006 #include "Inventor/nodes/SoVertexProperty.h"
00007
00008
00009
00010
00011
00012
00013
00014
00015 SO_KIT_SOURCE (IgSoTowerRadii);
00016
00017
00018
00019
00020
00021 void
00022 IgSoTowerRadii::initClass (void)
00023 { SO_KIT_INIT_CLASS (IgSoTowerRadii, IgSoShapeKit, "IgSoShapeKit"); }
00024
00025 IgSoTowerRadii::IgSoTowerRadii (void)
00026 {
00027 SO_KIT_CONSTRUCTOR (IgSoTowerRadii);
00028 SO_KIT_ADD_FIELD (center, (0.0f,0.0f));
00029 SO_KIT_ADD_FIELD (radius, (1.0f));
00030 SO_KIT_ADD_FIELD (displayCenter, (false));
00031 SO_KIT_ADD_CATALOG_ENTRY (line, SoLineSet, FALSE, separator,\x0, TRUE);
00032 SO_KIT_ADD_CATALOG_ENTRY (marker, SoMarkerSet, FALSE, separator,\x0, TRUE);
00033 SO_KIT_INIT_INSTANCE ();
00034 setUpConnections (true, true);
00035 }
00036
00037 void
00038 IgSoTowerRadii::refresh (void)
00039 {
00040 SoVertexProperty *vtx = new SoVertexProperty;
00041 SoLineSet *line = new SoLineSet;
00042 int segments = 60;
00043
00044 double segAngle = 2 * M_PI / segments;
00045 double r = radius.getValue ();
00046 float cx, cz;
00047 int i = 0;
00048
00049 center.getValue ().getValue (cx, cz);
00050 for (i = 0; i < segments; i++)
00051 vtx->vertex.set1Value (i, SbVec3f (r * cos (i * segAngle) + cx,
00052 0,
00053 r * sin (i * segAngle) + cz));
00054
00055 vtx->vertex.set1Value (i, SbVec3f (r * cos (0) + cx,
00056 0,
00057 r * sin (0) + cz));
00058 vtx->normal = SbVec3f (0, 0, 1);
00059 vtx->normalBinding = SoVertexProperty::OVERALL;
00060 vtx->materialBinding = SoVertexProperty::OVERALL;
00061 line->numVertices = segments + 1;
00062 line->vertexProperty = vtx;
00063
00064 if (displayCenter.getValue ())
00065 {
00066 SoMFInt32 markerIndex;
00067 markerIndex.setValue (SoMarkerSet::CROSS_5_5);
00068
00069 SoMarkerSet *marker = new SoMarkerSet;
00070 SoVertexProperty *mvtx = new SoVertexProperty;
00071 mvtx->vertex.set1Value (0, SbVec3f (cx, 0, cz));
00072 marker->vertexProperty = mvtx;
00073 marker->markerIndex = markerIndex;
00074 marker->numPoints = 1;
00075 marker->startIndex = 0;
00076
00077 setPart ("marker", marker);
00078 }
00079 else
00080 {
00081 setPart ("marker", NULL);
00082 }
00083
00084 setPart ("line", line);
00085 }