#include #include using namespace osg; /////////////////////////////////////////////////////////////////////////////// // // draw shape // class DrawShapeVisitor : public ConstShapeVisitor { public: DrawShapeVisitor(State& state,TessellationHints* hints): _state(state), _hints(hints) {} virtual void apply(const Sphere&); virtual void apply(const Box&); virtual void apply(const Cone&); virtual void apply(const Cylinder&); virtual void apply(const InfinitePlane&); virtual void apply(const TriangleMesh&); virtual void apply(const ConvexHull&); virtual void apply(const HeightField&); virtual void apply(const CompositeShape&); State& _state; TessellationHints* _hints; }; void DrawShapeVisitor::apply(const Sphere& sphere) { glPushMatrix(); glTranslatef(sphere.getCenter().x(),sphere.getCenter().y(),sphere.getCenter().z()); unsigned int numSegments = 40; unsigned int numRows = 20; float lDelta = osg::PI/(float)numRows; float vDelta = 1.0f/(float)numRows; float angleDelta = osg::PI*2.0f/(float)numSegments; float texCoordHorzDelta = 1.0f/(float)numSegments; float lBase=-osg::PI*0.5f; float rBase=0.0f; float zBase=-sphere.getRadius(); float vBase=0.0f; float nzBase=-1.0f; float nRatioBase=0.0f; for(unsigned int rowi=0; rowizMax) zMax = z; } } _bb.set(field.getOrigin()+osg::Vec3(0.0f,0.0f,zMin), field.getOrigin()+osg::Vec3(field.getXInterval()*field.getNumColumns(),field.getYInterval()*field.getNumRows(),zMax)); } void ComputeBoundShapeVisitor::apply(const CompositeShape&) { } ProceduralGeometry::ProceduralGeometry() { } ProceduralGeometry::ProceduralGeometry(Shape* shape) { setShape(shape); } ProceduralGeometry::ProceduralGeometry(const ProceduralGeometry& pg,const CopyOp& copyop): Drawable(pg,copyop) { } ProceduralGeometry::~ProceduralGeometry() { } void ProceduralGeometry::drawImmediateMode(State& state) { if (_shape.valid()) { DrawShapeVisitor dsv(state,_tessellationHints.get()); _shape->accept(dsv); } } void ProceduralGeometry::accept(AttributeFunctor& af) { } void ProceduralGeometry::accept(PrimitiveFunctor& pf) { } bool ProceduralGeometry::computeBound() const { if (_shape.valid()) { ComputeBoundShapeVisitor cbsv(_bbox); _shape->accept(cbsv); _bbox_computed = true; return true; } return false; }