Getting all intersections with a compound collision.

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Getting all intersections with a compound collision.

Postby Crashy » Wed Jan 09, 2019 6:33 pm

Hi,

Doing a raycast can return all the bodies hit by the ray but, when using compound collision, only the intersection with the first sub collision is returned.

To be more precise, I'm doing something with a collision composed of multiple shapes encapsulated one in other, but currently only the intersection of the ray with the outer one is returned.

Is there a way to get all intersections, not only the first one ? If not, how hard would it be to add such a feature ?

Thanks.
Crashy
 
Posts: 99
Joined: Fri Dec 03, 2010 6:30 am

Re: Getting all intersections with a compound collision.

Postby Julio Jerez » Wed Jan 09, 2019 6:47 pm

it always cast from front to back, but if in the raycast callback if you return 1.0 it will continue tracing all the shapes.
Julio Jerez
Moderator
Moderator
 
Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting all intersections with a compound collision.

Postby Crashy » Thu Jan 10, 2019 3:07 am

Hi,
Thanks for your answer.
I'm already returning 1.2f to get all intersections, but that's not quite the result I want.

I've made a drawing of what I'm doing:
ray.jpg
ray.jpg (31.05 KiB) Viewed 947 times

Blue and red are two different bodies.

Right now, here is what I get:
  • returning a value <1.0f in the callback gives me intersection 1
  • returning a value >1.0f in the callback gives me intersection 1 & 3
However, what I'd like to have, is to get all points 1,2,3,4,5,6, or at least 1,3,4.

I guess I could alter or make a variant of dgBody::RayCast to do more precise ray/collision intersection tests, doing a loop with the ray start position set to the previous intersection position or something like that.
Crashy
 
Posts: 99
Joined: Fri Dec 03, 2010 6:30 am

Re: Getting all intersections with a compound collision.

Postby JernejL » Thu Jan 10, 2019 12:18 pm

Direction of ray matters, if your faces are facing backwards, it won't return those hits, you might need to do 2 rays, one for each direction.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1441
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Getting all intersections with a compound collision.

Postby Julio Jerez » Thu Jan 10, 2019 4:15 pm

I just check the compound ray cast, and you are right is will not cast anything inside.
I never considered anyone getting the inside shapes.
you will have do that on your size.

you could return 1.2 and collect all the shape intersected the ray
the for each shape you can trace a ray in the opposite direction to get the other hit.
and you compound you can iterate over internal sub shape doing the same.

This is an opertiaon trha I do not see much use for, so I am not spending time of it.
Julio Jerez
Moderator
Moderator
 
Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting all intersections with a compound collision.

Postby Crashy » Fri Jan 11, 2019 5:35 am

Thank you Julio & JernejL for your hints.
NP for not doing that on your side, it's a very specific request, and I can do this myself, I was just asking if there was a way to do it with current implementaiton of raycasting.

For information, I want to do that because I need to simulate bombshells going through multiple layers of armouring

Thanks. :)
Crashy
 
Posts: 99
Joined: Fri Dec 03, 2010 6:30 am

Re: Getting all intersections with a compound collision.

Postby MeltingPlastic » Sat Apr 06, 2019 9:15 pm

Hi Julio,

In my RayCast Function I am not getting callbacks when the ray hits each sub-collision shape. I just get one intersection on the whole body. I return 1.0f in the filter callback. Anything I could be missing?

Also collisionID is always 0 for me.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: Getting all intersections with a compound collision.

Postby Julio Jerez » Sun Apr 07, 2019 11:56 am

This question have me very confused, what kind of problem requires all the interaction of a compound?

The ray cast is cast bodies not shapes.

What I can do is make the shape ray cast do do the all shape if it does not do it already.
With this the user do the ray just like is doing now, them in the callback check if the body is a compound, and if it is, them call ray cast on that shape and get all the sunshade traces but the ray.
Will that help?
Julio Jerez
Moderator
Moderator
 
Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting all intersections with a compound collision.

Postby MeltingPlastic » Sun Apr 07, 2019 12:13 pm

I am making a game where Rigid Bodies can have very large compound collisions. During Gameplay I combine RigidBodies together by "Solidifying" them into single rigid bodies with complex compound collisions. I need to do raycasts that detect sub collisions so that I know what part of the body I am hitting. The Urho3D Api maintains separate "Collision Shape" components for each sub collision. I want to be able to know what component I am essentially hitting with the raycast so that I can know the component.

I need to extract the user data from each sub collision to find the Urho3D component.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: Getting all intersections with a compound collision.

Postby Julio Jerez » Sun Apr 07, 2019 12:44 pm

Ok later today I will modify the compound demo to trace all the sub shapes, of a ray cast.
Julio Jerez
Moderator
Moderator
 
Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting all intersections with a compound collision.

Postby MeltingPlastic » Sun Apr 07, 2019 1:09 pm

Ok Sounds Great! Thanks!
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: Getting all intersections with a compound collision.

Postby Julio Jerez » Sun Apr 07, 2019 3:30 pm

Ok I set up the test, the function is no written yet, but of you sync you can see how it will work.
the function you want to look at is void RayCastAllSubShapes(const dVector& p0, const dVector& p1)
in the compound demo.
I implemented in a listener.

basically is simple cats the compound again but of you get the idea, a naïve implementation would be iterating over all sub shapes calling NewtonCollisionRayCast(collision, &localP0[0], &localP1[0], &normal[0], &attribute) on each and collision the one that return a less than zero value.
of course the final will do better that that.

if you sync you will see how is set up, and you can tell me if this is what you have in mind.
Julio Jerez
Moderator
Moderator
 
Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting all intersections with a compound collision.

Postby Julio Jerez » Sun Apr 07, 2019 5:21 pm

BTW the demo crashes because calling collide one compound required some initialization, that's actually bug in the engine that has always been there, Dave just notified me about.
I will fix later.
Julio Jerez
Moderator
Moderator
 
Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Getting all intersections with a compound collision.

Postby MeltingPlastic » Sun Apr 07, 2019 7:01 pm

Ideally I would think NewtonWorldRayCast would do everything. As the ray hit different subcollisions of a body the FilterCallbacks would be called with pointers to the different subcollisions (of course the body pointer would be the same while the ray is traversing through a single body). If its unnecessarily expensive maybe a parameter could be added to enable/disable subcollision intersections.

I do see what your saying about iterating over all possible subcollisions and testing using NewtonCollisionRayCast. I'll look at that.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: Getting all intersections with a compound collision.

Postby Julio Jerez » Mon Apr 08, 2019 3:54 pm

ok MeltingPlastic I now implement the function the way you say,
look at function
void RayCastCompoundsAllSubShapes(const dVector& origin, const dVector& end)

in the compound demo, I believe that is what yo meant.

is does not do anything yet, is just trace sub shape hit each time it find a sub shape on a compound.
Later I will make that it will display the hit points, to make sure they are all correct.

but the skeleton of the implementation is there.

it you want to make a complex NewtonWorldRayCast you can just take the RayCastCompoundsAllSubShapes and add it you callback and the base of the option you can do what ever you want.

I hope this is not too confusing.
Julio Jerez
Moderator
Moderator
 
Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 8 guests

cron