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

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
x 1
Contact:

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

Post 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.
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Post 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
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
x 1
Contact:

Post by Clay »

Odd, 16 and 32 work as well. =)

Thanks.
User avatar
epopov
Halfling
Posts: 85
Joined: Tue Jun 10, 2003 2:57 pm
Contact:

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

Post 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]
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post 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.
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
x 1
Contact:

Post 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?
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post 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"
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
x 1
Contact:

Post by Clay »

Duh. Right. I always seem to try things the hard way. Thanks. =)
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
x 1
Contact:

Post 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.
Post Reply