コード例 #1
0
void ShapeVisitor_VisualizerCreator::visit( Layout::Shape_Plane& shape )
{
	// OSG does not support InfinitePlane drawing at this time, maybe try to use this piece of code with the new version of OSG
	/*
	osg::InfinitePlane * plane = new osg::InfinitePlane;
	plane->set (shape.getNormalVector (), getScaledDistance (shape.getD ()));

	osg::ShapeDrawable * sd = new osg::ShapeDrawable;
	sd->setShape (plane);
	sd->setColor (osg::Vec4 (0, 0.5, 0.0, 0.5));

	now we use a temporary code instead - drawing a plane using box:
	if(shape.isInvisible()) {
	    createdVisualizer_ = new osg::Group;
	    return;
	}
	*/

	// position of center point
	osg::Vec3f center( 0, 0, ( -shape.getD() ) / shape.getNormalVector().z() ); // some point on the plane
	//qDebug() << "center: " << center.z();

	// size of grid
	int size = 1000;
	// number of lines on one side of grid
	int noOfLines = 10;

	// compute 4 corners of grid based on center point
	// osg::Vec3Array* gridVertices = new osg::Vec3Array;
	// gridVertices->push_back( center + osg::Vec3f( -size/2, size/2, 0) ); // top left
	// gridVertices->push_back( center + osg::Vec3f(size/2, size/2, 0) ); // top right
	// gridVertices->push_back( center + osg::Vec3f(-size/2,-size/2, 0) ); // bottom right
	// gridVertices->push_back( center + osg::Vec3f( size/2,-size/2, 0) ); // bottom left

	osg::Geometry* gridGeometry;
	gridGeometry = createGridGeometry( size, noOfLines, center );

	// creating new geode
	osg::Geode* geode = new osg::Geode;

	// assign geometry
	geode->addDrawable( gridGeometry );
	// turn off GL_LIGHTNING
	gridGeometry->getOrCreateStateSet()->setMode( GL_LIGHTING,osg::StateAttribute::OFF );
	// setting color of grid
	osg::Vec4Array* colors = new osg::Vec4Array;
	colors->push_back( osg::Vec4( 0.0f, 0.0f, 1.0f, 0.6f ) ); // blue
	gridGeometry->setColorArray( colors );
	gridGeometry->setColorBinding( osg::Geometry::BIND_OVERALL );

	createdVisualizer_ = geode;
}
コード例 #2
0
void ShapeVisitor_VisualizerCreator::visit (Layout::Shape_Plane & shape) {
	// OSG does not support InfinitePlane drawing at this time, maybe try to use this piece of code with the new version of OSG
	/*
	osg::InfinitePlane * plane = new osg::InfinitePlane;
	plane->set (shape.getNormalVector (), getScaledDistance (shape.getD ()));

	osg::ShapeDrawable * sd = new osg::ShapeDrawable;
	sd->setShape (plane);
	sd->setColor (osg::Vec4 (0, 0.5, 0.0, 0.5));
	*/

	// now we use a temporary code instead - drawing a plane using box:

	// center
	osg::Vec3 center (0, 0, (- shape.getD ()) / shape.getNormalVector ().z () ); // some point on the plane

	// rotation
	osg::Quat quat;
	quat.makeRotate (osg::Z_AXIS, shape.getNormalVector ());

	osg::Box * box = new osg::Box;
	box->setCenter (getScaledPosition (center));
	box->setRotation (quat);
	box->setHalfLengths (osg::Vec3 (1000, 1000, 1));

	osg::ShapeDrawable * sd = new osg::ShapeDrawable;
	sd->setShape (box);
	sd->setColor (osg::Vec4 (0, 0, 1.0, 0.06));
	sd->getOrCreateStateSet()->setMode (GL_BLEND, osg::StateAttribute::ON);
	sd->getStateSet()->setRenderingHint (osg::StateSet::TRANSPARENT_BIN);

	osg::Geode * geode = new osg::Geode;
	geode->addDrawable (sd);

	createdVisualizer_ = geode;
}