OgreNewt::BasicRaycast::BasicRaycastInfo problem

ogre_newbie

23-03-2009 11:41:45

I am trying to use the following code to shoot a ray to the scene can get the newton objects' information.
I used a for loop to loop thru the result and get the one with node name starts with "sphere"
There is a runtime error occured when the ray passing thru three objects.
After some debug efforts, I found that the error occured during the second loop, looks like this line : info = ray->getInfoAt(index); is failing.
I used getHitCount() to determine the how many loop there, that should be right and will not exist the number of results the ray got?

Please, big brothers, do you know why there is an invalid "info"? :roll:


CEGUI::Renderer* rend = CEGUI::System::getSingleton().getRenderer();

Ogre::Real mx = l_Vec2.x / rend->getWidth(); // l_Vec2.x = mouse coordinate's x
Ogre::Real my = l_Vec2.y /rend->getHeight(); // l_Vec2.y = mouse coordinate's y
Ogre::Ray camray = mCam->getCameraToViewportRay(mx,my);

Ogre::Vector3 start, end;
start = camray.getOrigin();
end = camray.getPoint( 3500.0 );

OgreNewt::BasicRaycast* ray = new OgreNewt::BasicRaycast( m_World, start, end );
OgreNewt::BasicRaycast::BasicRaycastInfo info;

int hitcount = ray->getHitCount();
Ogre::String nameSphere = "sphere";

for(int index=0; index<hitcount; index++ )
{
info = ray->getInfoAt(index);
//error here!

Ogre::Node* tempnode = info.mBody->getOgreNode();
Ogre::String nodeName= tempnode->getName();

if(Ogre::StringUtil::startsWith(nodeName,nameSphere,true)==true)// if the node has the name begins with 'sphere'
{
.......

melven

23-03-2009 13:05:14

Which version of newton and OgreNewt are you using? In the new Newton 2.0 beta, there's bug on some systems concerning the results of convexcasts (and raycasts... I'm not shure...)

But the error is still strange, the getInfoAt-Function is just returning an BasicRaycastInfo-object from a std::vector... Are you shure you didn't delete the Raycast-object accidentally?
What's your operating system and compiler and what is the exact error message? Could you also post the code of the whole function?

ogre_newbie

24-03-2009 07:40:00

thanks melven!!

I really did the stupid thing! I wrongly put the 'delete ray;' inside at the end of the first loop, that's why it can't make it to the second loop :oops: