Commit 8a80211e by Sebastian Eichelbaum

[CHANGE] createUnitCubeAsLines now allows to turn off line-strips.

parent d1b2db69
......@@ -242,34 +242,77 @@ osg::ref_ptr< osg::Geometry > wge::createUnitCube( const WColor& color )
return createCube( WPosition( 0.0, 0.0, 0.0 ), WPosition( 1.0, 1.0, 1.0 ), color );
}
osg::ref_ptr< osg::Geometry > wge::createUnitCubeAsLines( const WColor& color )
osg::ref_ptr< osg::Geometry > wge::createUnitCubeAsLines( const WColor& color, bool asLines )
{
// create the unit cube manually as the ShapeDrawable and osg::Box does not provide 3D texture coordinates
osg::ref_ptr< osg::Geometry > cube = new osg::Geometry();
osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >( new osg::Vec3Array );
osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >( new osg::Vec4Array );
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
if( !asLines )
{
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
}
else
{
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
cube->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, vertices->size() ) );
}
// set it up and set arrays
cube->setVertexArray( vertices );
......
......@@ -113,10 +113,11 @@ namespace wge
* Creates a osg::Geometry containing an unit cube as line-strips, having 3D texture coordinates.
*
* \param color the color to set for all vertices
* \param asLines force the cube to be made only of lines, no line strips.
*
* \return the geometry
*/
osg::ref_ptr< osg::Geometry > createUnitCubeAsLines( const WColor& color );
osg::ref_ptr< osg::Geometry > createUnitCubeAsLines( const WColor& color, bool asLines = false );
/**
* Extract the vertices and triangles from a WTriangleMesh and save them
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment