[osg-users] Distance to camera

Robert Osfield robert.osfield at gmail.com
Mon Mar 9 10:09:23 PDT 2009


Hi Peter,

Go look at how LOD::traverse() is implemented in src/LOD.cpp.

Robert.

On Mon, Mar 9, 2009 at 4:47 PM, Peter <osgforum at tevs.eu> wrote:
> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



More information about the osg-users mailing list