First, I am using this code to check for the left mouse button:
Code: Select all
if (e->getButtonID() == 16)I am using this code for my RaySceneQuery. I am trying to get the height at the x, y under the camera. The query works fine. My question is:
1) Should I be using some sort of mask to ONLY hit the terrain? I never seem to hit anything other than the terrain, but I want to make sure.
2) This leads me to believe that the default mask (IE if you don't give any SceneNodes a mask), excludes everything but the terrain. Is this correct?
Code: Select all
Vector3 camPos = mCamera->getPosition( );
Ray cameraRay( Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y );
mRaySceneQuery->setRay( cameraRay );
// Perform the scene query
RaySceneQueryResult &result = mRaySceneQuery->execute();
RaySceneQueryResult::iterator itr = result.begin( );
// Get the results, set the camera height
if ( itr != result.end() && itr->worldFragment )
{
Real terrainHeight = itr->worldFragment->singleIntersection.y;
if ((terrainHeight + 10.0f) > camPos.y)
mCamera->setPosition( camPos.x, terrainHeight + 10.0f, camPos.z );
}
