Futher updates to shapes support.

This commit is contained in:
Robert Osfield
2002-11-01 12:20:34 +00:00
parent 432654bde8
commit ee54835144
2 changed files with 29 additions and 9 deletions

View File

@@ -42,13 +42,6 @@ osg::Geode* createShapes()
geode->addDrawable(new osg::ProceduralGeometry(osgNew osg::Cone(osg::Vec3(4.0f,0.0f,0.0f),radius,height)));
geode->addDrawable(new osg::ProceduralGeometry(osgNew osg::Cylinder(osg::Vec3(6.0f,0.0f,0.0f),radius,height)));
// osg::Grid* grid = new osg::Grid;
// grid->allocGrid(100,100,0.0f);
// grid->setXInterval(0.2f);
// grid->setYInterval(0.2f);
// grid->populateGrid(-0.2f,0.2f);
// geode->addDrawable(new osg::ProceduralGeometry(grid));
osg::Grid* grid = new osg::Grid;
grid->allocGrid(38,39);
grid->setXInterval(0.28f);
@@ -63,6 +56,24 @@ osg::Geode* createShapes()
}
geode->addDrawable(new osg::ProceduralGeometry(grid));
osg::ConvexHull* mesh = new osg::ConvexHull;
osg::Vec3Array* vertices = new osg::Vec3Array(4);
(*vertices)[0].set(0.0f,0.0f,4.0f);
(*vertices)[1].set(0.0f,0.0f,0.0f);
(*vertices)[2].set(4.0f,0.0f,0.0f);
(*vertices)[3].set(4.0f,0.0f,4.0f);
osg::UByteArray* indices = new osg::UByteArray(6);
(*indices)[0]=0;
(*indices)[1]=1;
(*indices)[2]=2;
(*indices)[3]=0;
(*indices)[4]=2;
(*indices)[5]=3;
mesh->setVertices(vertices);
mesh->setIndices(indices);
geode->addDrawable(new osg::ProceduralGeometry(mesh));
return geode;
}

View File

@@ -475,12 +475,20 @@ void DrawShapeVisitor::apply(const InfinitePlane& plane)
void DrawShapeVisitor::apply(const TriangleMesh& mesh)
{
std::cout << "draw a mesh "<<&mesh<<std::endl;
const Vec3Array* vertices = mesh.getVertices();
const IndexArray* indices = mesh.getIndices();
if (vertices && indices)
{
glNormal3f(0.0f,0.0f,1.0f);
_state.setVertexPointer(3,GL_FLOAT,0,vertices->getDataPointer());
glDrawElements(GL_TRIANGLES,indices->getNumElements(),indices->getDataType(),indices->getDataPointer());
}
}
void DrawShapeVisitor::apply(const ConvexHull& hull)
{
std::cout << "draw a hull "<<&hull<<std::endl;
apply((const TriangleMesh&)hull);
}
void DrawShapeVisitor::apply(const HeightField& field)
@@ -758,6 +766,7 @@ bool ProceduralGeometry::computeBound() const
ComputeBoundShapeVisitor cbsv(_bbox);
_shape->accept(cbsv);
_bbox_computed = true;
return true;
}