Rays Cannot Detect Billboards

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
magicaxis
Gnoblar
Posts: 15
Joined: Fri Jun 29, 2012 6:48 am
x 2

Rays Cannot Detect Billboards

Post by magicaxis »

Hello all, I realize this is a common question, but I have read and attempted every response on the internet and have had no dice so far.

I have a billboard hovering over an item in space. I want to click on the billboard, and the camera zooms in on the item. The camera zoom and the item are fine, the problem lies in here:

Code: Select all

Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x/float(arg.state.width), mousePos.d_y/float(arg.state.height));
	mRaySceneQuery = mCamera->getSceneManager()->createRayQuery(Ray());
	mRaySceneQuery->setSortByDistance(true);

	if (currSceneType == SCENE_SSVIEW) mRaySceneQuery->setQueryMask(SUN_MASK | SC_MASK | PLANET_MASK | PLANET_BTN_MASK | Ogre::SceneManager::FX_TYPE_MASK);
	//I have tried setQueryTypeMask, but that makes both the keyboard and the mouse become unresponsive.
	mRaySceneQuery->setRay(mouseRay);

	RaySceneQueryResult result = mRaySceneQuery->execute();
	rayHitData myHit = RaycastFromPoint(mRaySceneQuery, mouseRay);
No matter what I do, "result" never includes the billboard. I have tried making the billboard an SC_MASK, an FX_TYPE_MASK, everything i can think of. As a result, myHit never contains the billboard, and the click does not register. Can someone please help, this is driving me up the wall!

Also note: for some reason, Ogre::SceneManager::FX_TYPE_MASK; always comes back as about 536 billion. The other enums are all sensible uint32s, but that one is wild.
Last edited by magicaxis on Fri Jun 29, 2012 9:32 am, edited 1 time in total.
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: RaySceneQuery Cannot Detect Billboards

Post by areay »

Hi there,

I *think* that RaySceneQuery will only return objects that subclass 'Ogre::Movable' and billboards are not derived from that base. I see you've tried to force the rayquery to use FX as a query mask anyway :D

Maybe you could try another approach where you work out the screen coordinates of the billboard and compare that to the mouse's position when it's clicked.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: Rays Cannot Detect Billboards

Post by Kojack »

Billboards always face the camera, but ray scene queries don't know the camera direction so can't tell which direction the billboard is facing (plus if you have two cameras looking at the billboard from different directions, it would have two facing directions) and therefore can't test for collision.

I'd second the idea of working in screen space.
magicaxis
Gnoblar
Posts: 15
Joined: Fri Jun 29, 2012 6:48 am
x 2

Re: Rays Cannot Detect Billboards

Post by magicaxis »

YES! It took a looooot of tinkering in the mouse controller, but i've got it registering! all i have to do now is make the clickable area scale to the size of the icon!
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Rays Cannot Detect Billboards

Post by areay »

Good stuff pal
User avatar
chaosavy
Silver Sponsor
Silver Sponsor
Posts: 578
Joined: Mon Jun 15, 2009 8:29 pm
x 64

Re: Rays Cannot Detect Billboards

Post by chaosavy »

You could also make a manual object - a "2d" rectangle - give it a material of your billboard and then ray scene queries should pick it up, though you'd be giving up a lot of neatness of billbaords (always facing camera, etc).
Visit http://www.VoidDestroyer.com to check out my space sim project - Void Destroyer
FireSpy
Gnoblar
Posts: 8
Joined: Tue May 09, 2006 3:54 am

Re: Rays Cannot Detect Billboards

Post by FireSpy »

So, what was the secret?
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Rays Cannot Detect Billboards

Post by jacmoe »

I think the secret is to know the location of the billboard(s) and then cast a ray against a plane created from that point and the camera orientation.
That really depends on how the billboards are constructed.
Otherwise it would be easier to cast a ray against a bounding volume.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
magicaxis
Gnoblar
Posts: 15
Joined: Fri Jun 29, 2012 6:48 am
x 2

Re: Rays Cannot Detect Billboards

Post by magicaxis »

I basically compared the mouses position with the position of the icon on the screen. If the mouse was within x (x being the width of the billboard), then it was clicked. Here's my code <3

Code: Select all

CEGUI::Point absMouse = CEGUI::MouseCursor::getSingleton().getPosition();

	if (seperation > SCI->getAttachedObject("iconSet")->getRenderingDistance()){
		return false;
	}

	if (absMouse.d_x >= SCIx - 30 &&
		absMouse.d_x <= SCIx + 30 &&
		absMouse.d_y >= SCIy - 30 &&
		absMouse.d_y <= SCIy + 30)//change 30 if the icon is resized
	{
		return true;
	}
	else
	{
 		return false;
	}
Oh yeah, SCIx and SCIy are SpaceCraftIconXlocation. I used this to get the 2d coordinates of the icon on the screen:

Code: Select all

Vector3 eyeSpacePos = mCamera->getViewMatrix(true) * SCI->convertLocalToWorldPosition(SCI->getPosition());
	if (eyeSpacePos.z < 0) 
	{
		Vector3 screenSpacePos = mCamera->getProjectionMatrix() * eyeSpacePos;
        SCIx = screenSpacePos.x;
        SCIy = screenSpacePos.y;
:D
lordbeast
Halfling
Posts: 59
Joined: Fri Jun 03, 2011 11:25 am
Location: Russia
x 6

Re: Rays Cannot Detect Billboards

Post by lordbeast »

Ouch... this is overdose!
Simplest way is to use RaySceneQueryType method

Code: Select all

mRayScnQuery = mSceneMgr->createRayQuery(Ogre::Ray());
mRayScnQuery->setQueryTypeMask(SceneManager::FX_TYPE_MASK);
There are 6 types of QueryTypeMask defined in the SceneManager class as static members:

Code: Select all

WORLD_GEOMETRY_TYPE_MASK //Returns world geometry.
ENTITY_TYPE_MASK         //Returns entities.
FX_TYPE_MASK             //Returns billboardsets / particle systems.
STATICGEOMETRY_TYPE_MASK //Returns static geometry.
LIGHT_TYPE_MASK          //Returns lights.
USER_TYPE_MASK_LIMIT     //User type mask limit.
Intermediate Tutorial 3
It`s a Caesar code. It`s does not works, but simultaneously it`s does not falling down.
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Rays Cannot Detect Billboards

Post by areay »

lordbeast wrote:Ouch... this is overdose!
Simplest way is to use RaySceneQueryType method
Did you not see the part where OP tried that and it didn't work? And that he wants to test against a billboard and not a billboardset?
lordbeast
Halfling
Posts: 59
Joined: Fri Jun 03, 2011 11:25 am
Location: Russia
x 6

Re: Rays Cannot Detect Billboards

Post by lordbeast »

i`m heedless. Sorry.
It`s a Caesar code. It`s does not works, but simultaneously it`s does not falling down.