Test if point inside entity/mesh

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
simedj
Goblin
Posts: 262
Joined: Fri Nov 18, 2011 6:50 pm
x 3

Test if point inside entity/mesh

Post by simedj »

First off, I know Ogre isn't a collision engine :) But does it happen provide any way to tell if a point is inside an Entity? I only ask because I know we have ray-hit testing using RaySceneQuery, commonly used for picking.

If not, I was thinking... to test point P against Entity E, you could generate a Ray R which starts at P and travels in any direction. Doing standard picking logic, count the number of intersections N between R and E - providing E is a closed mesh then if N is odd, you know P is inside.

Did I get that right, and is it the best approach? Is it possible to restrict RaySceneQuery to only look at specific Entities?
Looking to find experienced Ogre & shader developers/artists. PM me with a contact email address if interested.
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Test if point inside entity/mesh

Post by tod »

Depending on the precision you want you could use the entities bounding box, or bounding sphere. You will still need to use those for performance, i.e. check box first, and make more complicated calculations later, only if inside the box.

I think standard ray scene query only works with AABB's anyway. You can have a mask for your query to eliminate entities that don't match the mask.
simedj
Goblin
Posts: 262
Joined: Fri Nov 18, 2011 6:50 pm
x 3

Re: Test if point inside entity/mesh

Post by simedj »

tod wrote:Depending on the precision you want you could use the entities bounding box, or bounding sphere. You will still need to use those for performance, i.e. check box first, and make more complicated calculations later, only if inside the box.
I'd need polygon-level testing as I have meshes which would share the same bounding region but don't intersect. But of course you're right, simple tests should be done first (except in the cases there are very few objects or performance is not a problem).
I think standard ray scene query only works with AABB's anyway.
I'm not sure I really follow this, or at least I don't understand the implication?
You can have a mask for your query to eliminate entities that don't match the mask.
Thanks, I'll look into this although I guess I hoped for something more controllable, like ability to directly run a RaySceneQuery against an Entity or collection of Entities I supply. Maybe I can cannibalise Ogre source for this - but I know this functionality isn't designed for that purpose so it might be too tightly integrated.
Looking to find experienced Ogre & shader developers/artists. PM me with a contact email address if interested.
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Test if point inside entity/mesh

Post by tod »

simedj wrote:I'm not sure I really follow this, or at least I don't understand the implication?
I mean RaySceneQuery doesn't do intersection to the polygon level, only axis aligned bounding box. See this.

Doing custom ray for one entity may work, and is probably not very hard, but with multiple entities you better let ogre do it, or, you will have to keep some sort of spacial orientation yourself for those entities, like an octree or something.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Test if point inside entity/mesh

Post by Kojack »

simedj wrote:If not, I was thinking... to test point P against Entity E, you could generate a Ray R which starts at P and travels in any direction. Doing standard picking logic, count the number of intersections N between R and E - providing E is a closed mesh then if N is odd, you know P is inside.
That should work, if the mesh is manifold. A non manifold mesh has holes (or more specifically, it has edges that aren't shared by exactly 2 triangles). Manifold meshes are also required for stencil shadows to work correctly.

But as tod mentioned, ogre on it's own can't do polygon level raycasting. MOC (Minimal Ogre Collision) adds that, or that wiki article he linked to.
simedj
Goblin
Posts: 262
Joined: Fri Nov 18, 2011 6:50 pm
x 3

Re: Test if point inside entity/mesh

Post by simedj »

Ah sorry, I am using that method from the wiki - to me that's almost part of Ogre as it's used so much! I can easily restrict that code to only do the low-level poly testing on specific entities - is it worth even trying to restrict which entities Ogre does its own AABB tests on, or is that testing so quick that thousands of Entities would still not use appreciable time?

And yes, absolutely about manifold/closed meshes. However it does work on non-convex shapes, in fact I think regardless of mesh shape complexity except for a few special cases.

Thanks for the tips.
Looking to find experienced Ogre & shader developers/artists. PM me with a contact email address if interested.
Grognard
Kobold
Posts: 31
Joined: Fri May 03, 2013 2:40 am

Re: Test if point inside entity/mesh

Post by Grognard »

To do it with reasonable speed you really need to decompose the mesh into regions that can be tested as simple boxes, but that's a lot of work. Would be nice for that to make it into ogre but probably would not be easy.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Test if point inside entity/mesh

Post by c6burns »

Not only is this starting to sound non trivial, it's a duplication of many algorithms that should be in your physics engine. If you don't use one, it's officially time to consider using one :)
Post Reply