Lshink
22-09-2006 01:49:07
Hello:
I have been trying to create a function to get my terrain height given a x, z position so I can place objects easier on my terrain. I've directly taken most of the code in the FrameListener (such as creating the ball and moving the camera above the terrain) and put them into my CreateScene(), however for some odd reason, it doesn't work. (Yes, I'm still a bit new to Ogre and PLSM2)
Heres my code:
Any help would be appreciated
I have been trying to create a function to get my terrain height given a x, z position so I can place objects easier on my terrain. I've directly taken most of the code in the FrameListener (such as creating the ball and moving the camera above the terrain) and put them into my CreateScene(), however for some odd reason, it doesn't work. (Yes, I'm still a bit new to Ogre and PLSM2)
Heres my code:
const Real getHeight(Vector3 pos)
{
RaySceneQuery *mRayQuery;
mRayQuery = mScnMgr->createRayQuery(Ray(Vector3::ZERO, Vector3::NEGATIVE_UNIT_Y));
mRayQuery->setRay (Ray(pos, Vector3::NEGATIVE_UNIT_Y));
mRayQuery->setQueryMask (RSQ_FirstTerrain); //PLSM2 only
RaySceneQueryResult& qryResult = mRayQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
const Real height = it->worldFragment->singleIntersection.y;
return height;
}
else
return -1.0f;
}
Any help would be appreciated