Page 1 of 3

Distance between 2 objects

PostPosted: Fri Oct 01, 2010 6:19 am
by Cyrus
Hi,
I am using compound collision to represent each object in my world in Newton 2 with Ogre as my rendering engine
I would like to find the nearest distance between 2 objects.
Can some one provide any hiints/pointers?

Thanks in advance.

Re: Distance between 2 objects

PostPosted: Fri Oct 01, 2010 7:50 am
by Julio Jerez
you can use the closest distance functions in newton.

Re: Distance between 2 objects

PostPosted: Fri Oct 01, 2010 9:22 am
by JernejL
NewtonCollisionPointDistance & NewtonCollisionClosestPoint are suitable for this.

Re: Distance between 2 objects

PostPosted: Mon Oct 04, 2010 5:47 am
by Cyrus
Thanks for the replies.

I had 1 more query. If I have compound collision to represent 1 complete object (Ogre Entity), how can I find the distance between 2 objects?

Thanks,

Re: Distance between 2 objects

PostPosted: Mon Oct 04, 2010 8:22 am
by Julio Jerez
but was that the same question?

Code: Select all
 int NewtonCollisionClosestPoint (const NewtonWorld* newtonWorld,
                       const NewtonCollision* collisionA, const dFloat* matrixA,
                                                  const NewtonCollision* collisionB, const dFloat* matrixB,
                               dFloat* contactA, dFloat* contactB, dFloat* normalAB, int threadIndex);


calculates colsest distance, it gives you a point is shape a point on shape A and a point o shape B
who is distance is equal or shorter that any other pair points on shape A and B.

if the objects are colliding teh funtion reuturn zero.

Re: Distance between 2 objects

PostPosted: Mon Oct 04, 2010 8:53 am
by Cyrus
Sorry for any confusion. Let me clarify my second query -
The documentation for NewtonCollisionClosestPoint mentions that - "Calculate the closest points between two disjoint convex collision primitive". I wanted to know if there is a way to find the distance between 2 compound collision

Thanks again.

Re: Distance between 2 objects

PostPosted: Mon Oct 04, 2010 9:39 am
by Julio Jerez
you pass two compounts, compound are made of convex. it works too

bascically it comes down the the point in all sub shapes of collision A that is closer to the a point in all subshapes of collision B.
but is is more sofisticated than that since it use the hierchical organization of the compund shape make that it doe not test shapes tha cod no be any closer..

Re: Distance between 2 objects

PostPosted: Wed Oct 06, 2010 8:49 am
by Cyrus
Whenever we pass two disjoint compound objects, the api (NewtonCollisionClosestPoint) always returns zero!! We are using Newton 2.20
We attached the sample compound objects for which the api fails, we PMed the password for attached rar file.

Can you please check whether you are able to reproduce the problem with the models? Do you think it is a problem with the model?
Thanks.

Re: Distance between 2 objects

PostPosted: Thu Oct 07, 2010 10:59 am
by Cyrus
Please let me know if there is any way to debug this.

Thanks,

Re: Distance between 2 objects

PostPosted: Thu Oct 07, 2010 12:01 pm
by Julio Jerez
you sent two OBJ files one look like a vowl and the other like a goble, I need or load them from using thr editor.
I do not have a way to load OBJ files to make the compound, but I will add a plugin to the file format.
But I do not have time with work. I will check this saturday.
This is not a problems it is just that I am tight at work now but I will do it this weekend

Re: Distance between 2 objects

PostPosted: Tue Oct 12, 2010 9:50 am
by Cyrus
Please let me know if you need more info to reproduce this issue. I can provide the Ogre mesh files if that is easier to work with.

Thanks.

Re: Distance between 2 objects

PostPosted: Tue Oct 12, 2010 11:28 am
by Julio Jerez
Not It is Ok, I can use the OBJ file.
I am trying to add one fix before I post the SDK
I will replay tonight of Tomorrow with the solution.

It is very eassy to do this using the engine, But before I post a script for doing it I like to see why it is no working, because it certainly most.
Basically the script is a brute force that check every subshape gainst every other subshape.
for yours two mesh sample that will be fine, but for very complex mesh it will not, so I will chekc out what is wrong.

Re: Distance between 2 objects

PostPosted: Fri Oct 15, 2010 11:30 pm
by Cyrus
Please let me know if there is any way to debug this. Thanks.

Re: Distance between 2 objects

PostPosted: Sun Oct 17, 2010 8:20 am
by Julio Jerez
I finally am a stable point, I will post 2.25 today with the fix. and also a buch of oteh bug fixes too.
Sorry for the delay.

Re: Distance between 2 objects

PostPosted: Sun Oct 17, 2010 10:17 pm
by Julio Jerez
Upps, I finally managed to add the ability to load compound to the new file format, and I added the closest distance demo to the SDK, eventhing is nice and dandy,
but to my surprice closest distance on compound shapes does not work.
I build the engine in debug mode to see what it is, and this is the code for closest distance when using compound

Code: Select all
dgInt32 dgWorld::ClosestCompoundPoint (
   dgBody* compoundConvexA,
   dgBody* collisionB,
   dgTriplex& contactA,
   dgTriplex& contactB,
   dgTriplex& normalAB,
   dgInt32 threadIndex) const
{
_ASSERTE (0);
return 0;

/*
*/
}


I added a return at the beginning of the function a while back when I made the compund more efficient,
now I have to uncomment that and use the new algoirithm for the newer closest distance.

The function still uses the naive brute force scan which is ok for compound with small number of bodies
but very slow for compund with tousands of subshapes.
I should have this fix sometine today, but if I can not I will enable teh old brute force mode temporarily until I get the optimized version.
My bad. :oops: