Hi,

I'm playing with the osgcompositeviewer example in order to load and show the 
axes in the scene. I want that when I rotate the model in the first view, the 
axes get updated accordingly, but I don't want them to change position or allow 
the user to zoom them.

So, I got this thing running (at least I think so), but I' would like to know 
if this is the right way to do this.

In the View three I load the axes.osg file and add it as a child of a 
PositionAttitudeTransform node. This transform will be the scene node of the 
third view. Also I rotate the axes node so the Y axis will be pointing upwards 
and the Z axis will increase towards me.


Code:

      // Should check the pointers...
            osg::ref_ptr<osg::Node> axes = osgDB::readNodeFile("axes.osg");
            axes->setName( "AXES" );

            osg::ref_ptr<osg::PositionAttitudeTransform> pat = new 
osg::PositionAttitudeTransform;
            pat->setName( "PAT" );
            pat->setAttitude( osg::Quat( osg::DegreesToRadians( 90.0 ), 
osg::X_AXIS ) );
            pat->addChild( axes );
            pat->addUpdateCallback( new AttitudeCallback( 
viewer.getView(0)->getCamera() ) );

            view->setSceneData( pat.get() );




Now, for the update of the axes node I used a callback:


Code:

class AttitudeCallback: public osg::NodeCallback {
public:
    AttitudeCallback( osg::Camera* c ) : NodeCallback(), cam( c ) {
    }
    virtual void operator ()( osg::Node* node, osg::NodeVisitor* vis ) {
        const osg::Matrixd vmat = cam->getViewMatrix();

        std::cout << "CALLBACK: " << node->getName() << std::endl;

        osg::ref_ptr<osg::PositionAttitudeTransform> pat = 
dynamic_cast<osg::PositionAttitudeTransform*>( node );
        if( pat ) {
            const osg::Quat axis_rot( osg::DegreesToRadians( 90.0 ), 
osg::X_AXIS );
            pat->setAttitude( /*axis_rot **/ vmat.getRotate() * axis_rot );
            pat->setScale( osg::Vec3d( 0.5, 0.5, 0.5 ) );
        }
        traverse( node, vis );
    }
private:
    osg::ref_ptr<osg::Camera> cam;
};




I'm wondering whether instead of using a CompositeViewer, I could use the 
single Viewer and set a new viewport/camera to host the axes node.

And, if when I create the PositionAttitudeTransform in the third view and set 
then the scale and remove the pat->setScale(...) line from the callback, the 
axes don't get scaled at all! Why is that?
... 

Thank you and sorry for this huge post!!

Cheers,
Andrés

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60392#60392





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to