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 #include <gfx/VisualPath>
00026
00027
00028 #include <osg/Node>
00029 #include <osg/Transform>
00030 #include <osg/MatrixTransform>
00031 #include <osg/PositionAttitudeTransform>
00032 #include <osg/Geode>
00033 #include <osg/Drawable>
00034 #include <osg/Geometry>
00035
00036 using gfx::VisualPath;
00037
00038 using osg::Node;
00039 using osg::Transform;
00040 using osg::MatrixTransform;
00041 using osg::PositionAttitudeTransform;
00042 using osg::Geometry;
00043 using osg::Vec3;
00044
00045
00046 osg::Node* VisualPath::createOSGVisual(Visual::Attributes visualAttributes) const
00047 {
00048 if ((node!=0) && (attributes==visualAttributes))
00049 return &(*node);
00050
00051
00052
00053
00054
00055 array<Real> ta;
00056
00057 Real t=0.0;
00058 Int di=0;
00059 Real dt = distinguishedValue(di);
00060 while (t<1.0) {
00061
00062 if ((t > dt) && (di < numDistinguishedValues())) {
00063 ta.push_back(dt);
00064 if (!Math::equals(t,dt))
00065 ta.push_back(t);
00066
00067 di++;
00068 if (di < numDistinguishedValues())
00069 dt = distinguishedValue(di);
00070 }
00071 else
00072 ta.push_back(t);
00073
00074 t += 0.01;
00075 if (t>1.0) t=1.0;
00076 }
00077 ta.push_back(1.0);
00078
00079
00080
00081 osg::Geode* geode = new osg::Geode();
00082
00083 osg::Geometry* linesGeom = new osg::Geometry();
00084
00085 osg::Vec3Array* vertices = new osg::Vec3Array((ta.size()-1)*2);
00086 for(Int i=0; i<ta.size()-1; i++) {
00087 Point3 p1(position(ta[i]));
00088 Point3 p2(position(ta[i+1]));
00089 (*vertices)[2*i].set(p1.x,p1.y,p1.z);
00090 (*vertices)[2*i+1].set(p2.x,p2.y,p2.z);
00091 }
00092
00093 linesGeom->setVertexArray(vertices);
00094
00095
00096 osg::Vec4Array& colors = *new osg::Vec4Array(1);
00097 colors[0] = osg::Vec4(1.0f,1.0f,0.0f,1.0f);
00098 linesGeom->setColorArray(&colors);
00099 linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
00100
00101
00102
00103 osg::Vec3Array& normals = *new osg::Vec3Array(1);
00104 normals[0] = osg::Vec3(0.0f,-1.0f,0.0f);
00105 linesGeom->setNormalArray(&normals);
00106 linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
00107
00108 linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,(ta.size()-1)*2));
00109
00110
00111 geode->addDrawable(linesGeom);
00112
00113 attributes = visualAttributes;
00114 geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
00115
00116 node = geode;
00117
00118 return &(*node);
00119 }
00120