How to choose the rotation axis in a OSG RotateCylinderDragger

I’ve been looking for an easy way to change the default rotation axis in a RotateCylinderDragger of OpenSceneGraph, and didn’t find one that suited my needs. You can always introduce intermediary transforms, but it would be sub-optimal, and can give some problem when the RotateCylinderDragger is part of a more general CompositeDragger. Diving through the OSG API I have found an easy solution that basically replaces the default constructor and customizes the Projector instead of using the default one. The new contructor takes a Quaternion (osg::Quat) as argument, which indicates the new rotation axis orientation with respect to the default one (0,0,1) when creating an osg::Cylinder. I post a snippet below in case it is useful to someone else:

#include <osgManipulator/Dragger>
#include <osgManipulator/RotateCylinderDragger>
#include <osgManipulator/Projector>
#include <osg/Shape>

/** A custom RotateCylinder that allows the user select the rotation axis */
class CustomRotateCylinderDragger: public osgManipulator::RotateCylinderDragger {
                CustomRotateCylinderDragger(osg::Quat &rotation) {
                        //Set the default rotation axis
                        osg::Cylinder *c=new osg::Cylinder();
                        _projector = new osgManipulator::CylinderPlaneProjector(c);
                        setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
                        setPickColor(osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f));
                ~CustomRotateCylinderDragger() {}
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s