raycast performance

rschlend

14-12-2006 05:19:25

Hi--

Just a quick question regarding raycasts and performance...

The only examples I have show a raycast as follows:

OgreNewt::BasicRaycast* ray = new OgreNewt::BasicRaycast( m_World, start, end );
OgreNewt::BasicRaycast::BasicRaycastInfo info = ray->getFirstHit();
if (info.mBody)
{
//do something
}
delete ray;


Well I noticed the go method in the ray class and figured I could do something like:



//In the constructor of a class
OgreNewt::BasicRaycast* ray = new OgreNewt::BasicRaycast( m_World, start, end );
//////////////////////////

//In the callback
ray->go( m_World, start, end );
info = ray->getFirstHit();
if (info.mBody)
{
//do something
}
/////////////////////////


This seems to work, however when the raycast does not collide with anything I *think* it keeps the last hit along with frontRay->getHitCount() >= 1. In anycase info.mBody is not null if there was ever a previous raycast hit.

Is this the expected result? If so don't all of the new and delete's hurt performance? Is there another way to do this similar to my pseduo code I showed in the second portion? If anyone knows that performance difference is small anyhow and it's not worth me troubling over please let me know.

Thanks for all the advice in advance,

rschlend

alphamax

24-12-2006 16:42:27

I am interested about all this questions Too...

Someone have an idea ?

Thanks :P