Hi Peter,
You callback is pretty odd, while I don't exactly know what you are
trying to do and why, whatever it is the callback you've written is
almost certainly not the way to do.
Could you take half a dozen steps back and then explain from a high
level what you are trying to do in your app then perhaps others can
spot the right way for you to do this.
Robert.
On Mon, Jun 2, 2008 at 9:47 AM, Peter Wraae Marino <[EMAIL PROTECTED]> wrote:
> Hi users,
>
> I have a problem with my scene shaking. I have simplied the problem to the
> code below. A short description- the code find the position in the scene
> where the center of screen is projected onto a plane. This position is given
> to a PositionAttitudeTransform so the "box" is transformed to that position.
>
> You will notice when the application starts it shakes. (why?)
> You will also notice when panning the camera the scene shakes (why?)
>
> anyone?,
> Peter Wraae Marino
>
>
> #include <osgViewer/Viewer>
> #include <osg/ShapeDrawable>
> #include <osgManipulator/Projector>
>
> class CMyCallback : public osg::NodeCallback
> {
> public:
> void operator()( osg::Node* node, osg::NodeVisitor* nv )
> {
> osg::Camera* pCam = 0;
> osg::Node* p = node;
> while ( p )
> {
> pCam = dynamic_cast<osg::Camera*>(p);
> if ( pCam )
> {
> osg::PositionAttitudeTransform* pPat =
> dynamic_cast<osg::PositionAttitudeTransform*>(node);
> osg::Plane plane( osg::Vec3(0,0,1), osg::Vec3(0,0,0) );
> osg::ref_ptr<osgManipulator::PlaneProjector> rPlaneProj = new
> osgManipulator::PlaneProjector;
> rPlaneProj->setPlane( plane );
> osg::Vec3 v;
> osgManipulator::PointerInfo pi;
>
> pi.reset();
> pi.setCamera( pCam );
> pi.setMousePosition( 256, 256 ); // center of 512x512 window
> rPlaneProj->project( pi, v );
> pPat->setPosition( v );
> break;
> }
> p = p->getParent( 0 );
> }
> NodeCallback::traverse(node,nv);
> }
> };
>
> osg::Node* CreateScene()
> {
> osg::PositionAttitudeTransform* pPat = new osg::PositionAttitudeTransform;
> osg::Geode* pGeode = new osg::Geode();
> pGeode->addDrawable( new osg::ShapeDrawable( new
> osg::Box(osg::Vec3(0.0f,0.0f,0.0f),2.0f) ) );
> pPat->addChild( pGeode );
> pPat->setUpdateCallback( new CMyCallback );
> return pPat;
> }
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> // construct the viewer
> osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
> // make the viewer create a 512x512 window and position it at 32, 32
> viewer->setUpViewInWindow( 32, 32, 512, 512 );
> // set the scene-graph data the viewer will render
> viewer->setSceneData( CreateScene() );
> // execute main loop
> return viewer->run();
> }
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org