[SOLVED]RaySceneQuery on terrain to get height

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:


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 :)

tuan kuranes

22-09-2006 13:13:29

using SDK ?
if sdk change mask to RSQ_HEIGHT

Lshink

22-09-2006 17:55:18

using SDK ?
if sdk change mask to RSQ_HEIGHT


Sorry, I didn't state that. I'm actually using the source, not SDK. Version 1.2.0...Dagon? I think thats what its called :)

PatrickB3

22-09-2006 20:14:51

Queries have changed.

Change:
mRayQuery->setQueryMask (RSQ_FirstTerrain); //PLSM2 only
RaySceneQueryResult& qryResult = mRayQuery->execute();


To:

mRayQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK );
mRayQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);

// Execute query
RaySceneQueryResult & qryResult = MouseRaySceneQuery->execute();


That should make it work.

Now, another issue is that if you are doing it in CreateScene you probably won't get any valid results anyways. It can only get the height on pages that are actually loaded. The best place to place objects is in the TerrainListener, placing them in the pageLoaded function. That is called whenver a page has been loaded.

Lshink

23-09-2006 15:19:33

Hey PatrickB3:

Thanks for the help! There was actually already some code written to do what I wanted under the pagePreLoaded() function. Guess I should have looked a bit harder.

Thanks for the info though!