[osg-users] Distance to camera

Vincent Bourdier vincent.bourdier at gmail.com
Wed Mar 11 01:07:25 PDT 2009


Hi Peter,

2009/3/10 Peter <osgforum at tevs.eu>

> Hi Vincent,
>
> Thanks for your advice, but node doesn't have the method getWorldMatrix(),
> it has only getWorldMatrices().


Of course, sorry I did not verify the exact syntax.


>
> I tried this:
> osg::Vec3 position = node->getBound()->center() *
> node->getWorldMatrices()[0];
> but it returned same value like this:
> osg::Vec3 position = node->getBound()->center();
> and I am sure it's not the right value, because when I'm above my node,
> position of camera is totally different then position of node.
>

For me, node->getBound()->center() * node->getWorldMatrices()[0] is
something that we can consider as right, so I think your camera position is
not good...

Vincent.


> Peter
>
>
> Vincent.B wrote:
> > Hi,
> >
> > I use the manipulator->gtInverseMatrix().getTrans() to have camera
> position
> > node->getBound->center() * node->getWorldMatrix() to have node center,
> and then you just have to compute the difference.
> >
> > Vincent.
> >
> > 2009/3/9 Peter <>
> >
> > >  Hi all,
> > >
> > > I'd like to make callback which compute the distance from LOD object to
> camera.
> > > I tried this:
> > >
> > >
> > > Code:
> > >
> > > class DistanceCallback : public osg::NodeCallback
> > > {
> > > public:
> > >   virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
> > >   {
> > >      osg::LOD *lod = dynamic_cast<osg::LOD *> (node);
> > >      nv->setVisitorType(osg::NodeVisitor::CULL_VISITOR);
> > >      if (lod != NULL)
> > >      {
> > >         float distance =
> nv->getDistanceToEyePoint(lod->getCenter(),true);
> > >         std::cout << distance << std::endl;
> > >      }
> > >      traverse(node, nv);
> > >   }
> > > };
> > >
> > >
> > >
> > >
> > > but 0 is returned.
> > >
> > > I also tried this:
> > >
> > >
> > > Code:
> > >
> > > class DistanceCallback : public osg::NodeCallback
> > > {
> > > public:
> > >   virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
> > >   {
> > >      osg::LOD *lod = dynamic_cast<osg::LOD *> (node);
> > >      if (lod != NULL)
> > >      {
> > >         osgUtil::CullVisitor* visitor = new osgUtil::CullVisitor();
> > >         float distance =
> visitor->getDistanceToEyePoint(lod->getCenter(),true);
> > >         std::cout << distance << std::endl;
> > >      }
> > >      traverse(node, nv);
> > >   }
> > > };
> > >
> > >
> > >
> > >
> > > but the value is constant.
> > > Can anyone help?
> > >
> > > Thanks,
> > > Peter
> > >
> > > ------------------
> > > Read this topic online here:
> > > http://forum.openscenegraph.org/viewtopic.php?p=8108#8108 (
> http://forum.openscenegraph.org/viewtopic.php?p=8108#8108)
> > >
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > osg-users mailing list
> > >  ()
> > >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org(
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> > >
> >
> >
> >  ------------------
> > Post generated by Mail2Forum
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=8189#8189
>
>
>
>
>
> _______________________________________________
> 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/20090311/460afb07/attachment-0003.htm>


More information about the osg-users mailing list