Two quick questions so I can finish up a tutorial...
Posted: Tue Feb 01, 2005 7:59 am
I am wrapping up a tutorial on mouse movement and scene queries involving worldFragments. I have two quick questions i need to wrap up before I can finish this and put it on the wiki:
First, I am using this code to check for the left mouse button:
Clearly, this is the wrong thing to do, but I can't seem to find the enum where mouse buttons are defined. Left is 16, right is 32, but where this is defined, I have no clue. Any ideas what enum I should look for?
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?
Keep in mind this is supposed to be as simple and to the point as possible for teaching purposes. I'm going to do a full mask/object picking tutorial as a follow up to this one.
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 );
}