0

I try to realize a collision system with some Ogre::Ray but it seems that it doesn't work ...

Here's is the code :

Ogre::Vector3 robotPos = mRobotNode->getPosition();
Ogre::Ray robotRay(Ogre::Vector3(robotPos.x,5000.0f,robotPos.z),Ogre::Vector3::NEGATIVE_UNIT_Y);

mRaySceneQuery->setRay(robotRay);
mRaySceneQuery->setSortByDistance(false);

Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr;

for(itr = result.begin();itr != result.end(); itr++)
{
    if(itr->worldFragment)
    {

        Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;
        if(terrainHeight!=robotPos.y)
        {
            mRobotNode->setPosition(Ogre::Vector3(robotPos.x,terrainHeight,robotPos.z));
            mCameraNode->setPosition(Ogre::Vector3(robotPos.x,terrainHeight,robotPos.z));
            break;
        }
    }
}

This code is putting in the function : framerenderingqueued :)

but my mesh stays below the terrain

Someone can help me? :) Thanks

1 Answers1

0

Why dont you go deeper with a debugger? You can realize, that problem in your "if(terrainHeight!=robotPos.y)" condition, or maybe your "result" variable has zero elements inside, ot maybe no one of result element has positive "worldFragment" field.
If you provide a little more information about what happening in runtime, it can be helpful to identificate the problem.

ars
  • 707
  • 4
  • 14