RaySceneQueries got hit but no worldfragment

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
questore
Gnoblar
Posts: 7
Joined: Sun Jun 03, 2012 9:48 am

RaySceneQueries got hit but no worldfragment

Post by questore »

Hi guys!
Im new here, so sorry about my bad english.
My problem is that every example using RaySceneQueries to get the hit position like this:

Code: Select all

 (Item).getWorldFragment().getSingleIntersection();
after it checked that iterator not null and its got a next element
I'm using Mogre so my methods name a little diferent but similar

Code: Select all

RayResults[i].worldFragment.singleIntersection;
The problem is that sometimes worldFragment.singleIntersection gives "null" result while RayResults.Count still NOT 0 but 1 or 2.
Im using only the Imediate tutorials "terrain.cfg" as only 3D object.
Why is that? Is that a Morge specific problem, or is it ogre related?
User avatar
Xplodwild
Goblin
Posts: 231
Joined: Thu Feb 12, 2009 3:49 pm
Location: France
x 13
Contact:

Re: RaySceneQueries got hit but no worldfragment

Post by Xplodwild »

How are you creating the terrain? The old "terrain.cfg" method that uses setWorldGeometry is outdated since Ogre 1.7. I don't know exactly about MOgre but I guess it followed the path with the new Terrain component.
questore
Gnoblar
Posts: 7
Joined: Sun Jun 03, 2012 9:48 am

Re: RaySceneQueries got hit but no worldfragment

Post by questore »

Yes, I'm using the old terrain method, the tutorial showed that. I hope new terrain system will fix problem...i let u know my results.
Thx
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Re: RaySceneQueries got hit but no worldfragment

Post by Jabberwocky »

It's been a while since I used the old TerrainSceneManager.
But you need to be careful - a RaySceneQuery can hit either the terrain or a movable object.
When one of the results is for a movable object, worldFragment will be null.
Image
questore
Gnoblar
Posts: 7
Joined: Sun Jun 03, 2012 9:48 am

Re: RaySceneQueries got hit but no worldfragment

Post by questore »

I have tried the new terrain system according to this site:
http://www.ogre3d.org/tikiwiki/Mogre+Basic+Tutorial+3b
The problem is that my code now giving me a null result to every RaySceneQueries result.
Is it posible that the new system recognize terrain as a movable object and not a worldfragment?
If it is, then how should i know what object did the ray hit and where is the hitpoint?
Although mouseRayResults.movable.Name gives me no name so its not a real movable object No What? :)
by the way result.count is 4 or 5 so it hits something but im looking at flat ground so i dont know how it can hit 4 os 5 target.
User avatar
Xplodwild
Goblin
Posts: 231
Joined: Thu Feb 12, 2009 3:49 pm
Location: France
x 13
Contact:

Re: RaySceneQueries got hit but no worldfragment

Post by Xplodwild »

Terrain is MovableObject.

I think Ogre::Terrain::getHeightAtWorldPosition is what you need ;)
questore
Gnoblar
Posts: 7
Joined: Sun Jun 03, 2012 9:48 am

Re: RaySceneQueries got hit but no worldfragment

Post by questore »

Xplodwild wrote:Terrain is MovableObject.

I think Ogre::Terrain::getHeightAtWorldPosition is what you need ;)
No, you misunderstood me, maybe its my fault, i try it another way.
What i need is the Vector3 position of the ray where its hiting the terrain OR movable object fragment and a way to know the name of the object that i just hit... :)
User avatar
Xplodwild
Goblin
Posts: 231
Joined: Thu Feb 12, 2009 3:49 pm
Location: France
x 13
Contact:

Re: RaySceneQueries got hit but no worldfragment

Post by Xplodwild »

I'm not sure if you can get the name of a Terrain node, but here's how I do it :

Code: Select all

QList<TerrainNode*> nodes = scene->getTerrainNodes();
                // calculate the picked terrain
                for (QList<TerrainNode*>::iterator itx = nodes.begin(); itx != nodes.end(); ++itx)
                {
                        float tempdist = (*itx)->hitTest(mouseRay, pos2);
                        if(tempdist >= 0.0f && tempdist < distance)
                        {
                                pos1 = pos2;
                                distance = tempdist;
                                currentPage = *itx;               
                        }
                }

               if (currentPage == 0) { // it's an object }
questore
Gnoblar
Posts: 7
Joined: Sun Jun 03, 2012 9:48 am

Re: RaySceneQueries got hit but no worldfragment

Post by questore »

I know how to detect if its a terrainfragment now
I also know how to get the name of the hited object if its not Terrain or a non named object.

Code: Select all

if (mouseRayResults[i].movable.MovableType.ToString() == "OgreTerrainNodeMovable") { //do something with terrain object }
else if (mouseRayResults[i].movable.Name != ""){ //mouseRayResults[i].movable.Name is the name of the object we just hited }
Never mind... I can calculate the hitpoint Vector with Camera.Position + (mouseRayResults.distance * mouseRay.Direction)
Here comes the strange part...
Im geting a mouseRayResults.distance=0 when im close enough and looking at the terrain strait down from about 300f. What could be the problem?
questore
Gnoblar
Posts: 7
Joined: Sun Jun 03, 2012 9:48 am

Re: RaySceneQueries got hit but no worldfragment

Post by questore »

More info:
The result.distance gives perfect velues for every other object except new terrain system.
Ive tried: Old Terrain system AND random objects. Both working nicely when i check raydistance but new terrain system gives these strange raydistance values.
I realy need some help about this.
:(
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: RaySceneQueries got hit but no worldfragment

Post by areay »

New terrain system will not return any intersections when using standard rays. This has been asked a few times before, search for 'ray terrain'
questore
Gnoblar
Posts: 7
Joined: Sun Jun 03, 2012 9:48 am

Re: RaySceneQueries got hit but no worldfragment

Post by questore »

I have found what i need. The only strange thing is, that after i get ONCE the "terrainrayresult.poisiton" it won't give me the position after (even in the next codeline), so it could be confusing for starters if u want to check it and do something with it after. I guess u have to store it and its ok then.
THX everyone.
Post Reply