[osg-users] Creating shapes using Geometry
Paul Martz
pmartz at skew-matrix.com
Mon Dec 3 19:08:45 PST 2007
_____
From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Renan
Mendes
Sent: Sunday, December 02, 2007 3:40 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Creating shapes using Geometry
Hey, Jean-Sébastien.
Now I'm asking for that example code you've offered me, if that still
stands... I haven't tried hard enough, to be honest, but I sure have no
extra time to deal with this properly right now. Not to mention the guy I
work with, which is breathing down my neck... I would appreciate that favor
very much.
Thanks.
Renan M Z Mendes
Hi Renan -- Not sure exactly what aspect of this you're having trouble with.
I've attached some very simple code for drawing a unit circle into one of
the three coordinate planes; if this simple code insults your intelligence,
I apologize. Expanding this code to draw spheres, cones, cylinders, etc., is
an exercise in trig and use of the OpenGL primitive types.
Hope this helps get you started...
-Paul
#include <osg/LineWidth>
#include <osg/Geometry>
#include <osg/math>
#include <math.h>
osg::Vec3Array*
circleVerts( int plane, int approx )
{
const double angle( osg::PI * 2. / (double) approx );
osg::Vec3Array* v = new osg::Vec3Array;
int idx;
for( idx=0; idx<approx; idx++)
{
double cosAngle = cos(idx*angle);
double sinAngle = sin(idx*angle);
double x(0.), y(0.), z(0.);
switch (plane) {
case 0: // X
y = cosAngle;
z = sinAngle;
break;
case 1: // Y
x = cosAngle;
z = sinAngle;
break;
case 2: // Z
x = cosAngle;
y = sinAngle;
break;
}
v->push_back( osg::Vec3( x, y, z ) );
}
return v;
}
osg::Geode*
circles( int plane, int approx )
{
osg::Geode* geode = new osg::Geode;
osg::LineWidth* lw = new osg::LineWidth( 3. );
geode->getOrCreateStateSet()->setAttributeAndModes( lw,
osg::StateAttribute::ON );
osg::Geometry* geom = new osg::Geometry;
osg::Vec3Array* v = circleVerts( plane, approx );
geom->setVertexArray( v );
osg::Vec4Array* c = new osg::Vec4Array;
c->push_back( osg::Vec4( 1., 1., 1., 1. ) );
geom->setColorArray( c );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );
geom->addPrimitiveSet( new osg::DrawArrays( GL_LINE_LOOP, 0, approx ) );
geode->addDrawable( geom );
return geode;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20071203/dde148a4/attachment.html
More information about the osg-users
mailing list