[osg-users] object shaking

Peter Wraae Marino osghelp at gmail.com
Mon Jun 2 02:52:51 PDT 2008


Hi Robert,

I tried your suggestion and yes it does work, the panning of the camera
doesn't shake the scene anymore. .. but the startup position of the camera
is shaking?

Also I understand why this works, but don't really approve of it because it
makes my code more "hardcoded" because I need to implement a direct update
call after viewer->updateTraversal() which is kinda breaking the whole
framework that osg is built for. For example if at a later point you decide
to add another traversal then I will have to manually add it here myself.
Also anyone using my code will have to break their main loop to handle the
grid example.

Isn't there a method to make sure my updatecallback is called after the
camera has done it's stuff?

regards,
Peter

On Mon, Jun 2, 2008 at 11:22 AM, Robert Osfield <robert.osfield at gmail.com>
wrote:

> Hi Peter,
>
> One step that might be useful to you would be to break the main loop
> out into its constuent parts i.e.
>
>   viewer.run();
>
> becomes:
>
>  viewer.setCameraManipulator(new osgGA::TrackballManipulator);
>
>  viewer.realize();
>
>  while(!viewer.done())
>  {
>      viewer.advance();
>      viewer.eventTraversals();
>      viewer.updateTraversals(); /// update will set the camera's view
> matrix from the CameraManipulator
>      // do your update stuff here
>      viewer.renderingTraversals();
>   }
>
> This way you'll know that the camera is the same position that it'll
> be rendered with, as this might well be the source of your jitter.
>
> Robert.
>
> On Mon, Jun 2, 2008 at 10:05 AM, Peter Wraae Marino <osghelp at gmail.com>
> wrote:
> > Hi,
> >
> > Ok.. I tried to make the example simple.. but perhaps I made it more
> > confusing. I'll try to explain what my end
> > result shoud have been.
> >
> > I'm trying to create a grid that is always visible from the viewer. The
> grid
> > needs to scale at certain points when the
> > user zooms in/out.
> >
> > The basic idea was to use an updatecallback on the
> PositionAttitudeTransform
> > so I can position and scale it accordinaly. The grid is currently being
> > tested on a plane XY and Z=0
> >
> > To calculate the correct scaling of the grid to the current view, I need
> the
> > camera.
> >
> > To calculate where the grid should be located I used the
> > osgManipulator::PlaneProjector to project a  point from the center of the
> > view to our plane. This gives a position in the world where I can place
> the
> > grid (of course I will need to align the grid to an interval).
> >
> > This is what I want to end up with.
> >
> > So the first step was to position the grid and already something went
> wrong
> > there.. to me it looks like the camera
> > update and my updatecall back are out of sync.
> >
> > Does this help?
> > Peter
> >
> > On Mon, Jun 2, 2008 at 10:53 AM, Robert Osfield <
> robert.osfield at gmail.com>
> > wrote:
> >>
> >> 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 <osghelp at gmail.com>
> >> 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
> >> > osg-users at lists.openscenegraph.org
> >> >
> >> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >> >
> >> >
> >> _______________________________________________
> >> osg-users mailing list
> >> osg-users at lists.openscenegraph.org
> >>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > osg-users at lists.openscenegraph.org
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080602/6d405ea0/attachment.htm>


More information about the osg-users mailing list