[osg-users] Distance to camera

Tomlinson, Gordon GTOMLINSON at overwatch.textron.com
Mon Mar 9 11:26:13 PDT 2009


Pump Vincents Vec's in and just replace fasterSqrt SQRT func and square
with  SQR func
inline double const
getDistance( double const start[3], double const end[3] ) {

    double dist =  fasterSqrt( rv3d::square( start[0] - end[0] ) + 
                     square( start[1] - end[1] ) + 
                     square( start[2] - end[2] ) );
return osg::isNaN( dist) ? (double)1.0 : dist;
 
} 
 

Gordon
Product Manager 3d
__________________________________________________________
Gordon Tomlinson
Email  : gtomlinson @ overwatch.textron.com
__________________________________________________________

 

________________________________

From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Vincent
Bourdier
Sent: Monday, March 09, 2009 1:03 PM
To: osg-users at lists.openscenegraph.org
Subject: Re: [osg-users] Distance to camera


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 <osgforum at tevs.eu>


	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.or
g
	


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090309/5c3167ce/attachment-0003.htm>


More information about the osg-users mailing list