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"?
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"?
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'
{
.......