Page 1 of 1

Two quick questions so I can finish up a tutorial...

Posted: Tue Feb 01, 2005 7:59 am
by Clay
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:

Code: Select all

if (e->getButtonID() == 16)
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?

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 );
         }
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.

Posted: Tue Feb 01, 2005 8:36 am
by johnhpus
First Question:
As for Mouse buttons I don't know if there even is an enum.
0 = left, 1 = right, 2 = middle ( I might have right and middle mixed up, and on further consideration these might not be the same in the new Azeroth, I haven't used it yet

John

Posted: Tue Feb 01, 2005 9:13 am
by Clay
Odd, 16 and 32 work as well. =)

Thanks.

Re: Two quick questions so I can finish up a tutorial...

Posted: Tue Feb 01, 2005 9:46 am
by epopov
Clay wrote: First, I am using this code to check for the left mouse button:

Code: Select all

if (e->getButtonID() == 16)
I don't know what is e (a gui element ?). I myself use something like that to check for the left / right mouse button:

Code: Select all

if (mPickMode && mLevel->getInputDevice()->getMouseButton(0) &&  mTimeUntilNextToggle <= 0) {
    // left mouse button
} else if (mLevel->getInputDevice()->getMouseButton(1) &&  mTimeUntilNextToggle <= 0) {
    // right mouse button
}
getInputDevice() returns a Ogre::InputReader pointer.

[EDIT]
I think the 0, 1 and 2 values from Johnhpus are for getMouseButton(), not for your getButtonID().
[/EDIT]

Posted: Tue Feb 01, 2005 9:59 am
by tuan kuranes
e->getButtonID() == MouseEvent::BUTTON0_MASK

(MouseEvent::BUTTON1_MASK, MouseEvent::BUTTON2_MASK, MouseEvent::BUTTON3_MASK, MouseEvent::BUTTON1_MASK, MouseEvent::BUTTON_ANY_MASK)

if mRaySceneQuery is a TerrainRaySceneQuery it hits only terrain.

Posted: Tue Feb 01, 2005 5:17 pm
by Clay
Yikes sorry, e was a MouseEvent. No more posting at 4am for me.

I was under the impression that SceneQueries normally intersect with objects (given the Ogre::RaySceneQueryResultEntry::movable entry). Is this something that will eventually be changed for TerrainSceneQueries or is this "the way things work" and I need to come up with a different way of finding intersections with MovableObjects while using the TerrainSceneManager?

Posted: Tue Feb 01, 2005 5:36 pm
by tuan kuranes
TerrainRaySceneQuery code seems pretty dedicated to terrain only intersection.
I would use IntersectionSceneQuery for all objects,

That 's how I understood it, reading code, but don't know if it's "the way things work"

Posted: Tue Feb 01, 2005 5:51 pm
by Clay
Duh. Right. I always seem to try things the hard way. Thanks. =)

Posted: Wed Feb 02, 2005 11:13 pm
by Clay
I hate leaving questions unanswered. For anyone who finds this thread later:
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?
This is wrong. Actually the reason this works:

Code: Select all

// 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 );
         }
Is because the terrain is always returned first thanks to the way the TerrainSceneManager is implemented. Technically this should be rewritten to find the worldFragment in a for loop, since a later change to the TerrainSceneManager could break this.