On Wed, Sep 10, 2008 at 8:16 AM, ami guru <[EMAIL PROTECTED]> wrote:
> Hello forum,
>
>
> Are there any utility functions for drawing spheres, planes , boxes ,cubes
> etc. within OSG's framework?
>
>
>
> Sajjad
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
To draw regular shapes in OSG, refer to classes derived to
'osg::Shape'. Following is a segment from a program while
experimenting with those classes.
Also to find out if a particular shape is implemented in OSG, I
usually refer to HTML documentation (Generated using Doxygen). Just
refer to all the classes.
----------------------------------
osg::ref_ptr<osg::MatrixTransform> draw_shape(std::string shape, float x)
{
/* Geode containing a shape. */
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::ShapeDrawable> sd;
if(shape == "box") {
osg::ref_ptr<osg::Box> box = new osg::Box(osg::Vec3f(), 5.0);
sd = new osg::ShapeDrawable(box.get());
geode->addDrawable(sd.get());
} else if(shape == "cylinder") {
osg::ref_ptr<osg::Cylinder> cylinder = new
osg::Cylinder(osg::Vec3f(), 2.0, 5.0);
sd = new osg::ShapeDrawable(cylinder.get());
geode->addDrawable(sd.get());
} else if(shape == "capsule") {
osg::ref_ptr<osg::Capsule> capsule = new
osg::Capsule(osg::Vec3f(), 2.0, 5.0);
sd = new osg::ShapeDrawable(capsule.get());
geode->addDrawable(sd.get());
} else if(shape == "cone") {
osg::ref_ptr<osg::Cone> cone = new osg::Cone(osg::Vec3f(), 2.0,
5.0);
sd = new osg::ShapeDrawable(cone.get());
geode->addDrawable(sd.get());
} else if(shape == "sphere") {
osg::ref_ptr<osg::Sphere> sphere = new
osg::Sphere(osg::Vec3f(), 2.0);
sd = new osg::ShapeDrawable(sphere.get());
geode->addDrawable(sd.get());
}
/* Use matrix tranform to place the object at desired position
* from origin. */
osg::ref_ptr<osg::MatrixTransform> mtleft = new osg::MatrixTransform;
mtleft->setDataVariance(osg::Object::STATIC);
osg::Matrix m;
m.makeTranslate(x, 0.0, 0.0);
mtleft->setMatrix(m);
/* Add geode to matrix transform object. */
mtleft->addChild(geode.get());
return mtleft.get();
}
--
Vijay Patil
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org