convex cast problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: convex cast problem

Postby hamsterexplosion » Sat Oct 26, 2013 12:58 pm

i'm trying to cast cylinder collision on certain dynamic bodies with NewtonWorldConvexCast
User avatar
hamsterexplosion
 
Posts: 20
Joined: Thu Jul 11, 2013 11:54 am
Location: ukraine

Re: convex cast problem

Postby hamsterexplosion » Sat Oct 26, 2013 1:24 pm

btw, i've found applications\demosSandbox\Win32\demosSandbox.exe and chosen 'Primitive covex cast' demo and it fails in most of cases too. cylinder and box not working at all, others are working not in all cases and only a sphere shape casts ok
Attachments
1.jpg
1.jpg (172.84 KiB) Viewed 4143 times
User avatar
hamsterexplosion
 
Posts: 20
Joined: Thu Jul 11, 2013 11:54 am
Location: ukraine

Re: convex cast problem

Postby Julio Jerez » Sat Oct 26, 2013 4:40 pm

Last time check that as working.

I will verify and see what is wrong.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby hamsterexplosion » Mon Oct 28, 2013 5:29 pm

any news?
User avatar
hamsterexplosion
 
Posts: 20
Joined: Thu Jul 11, 2013 11:54 am
Location: ukraine

Re: convex cast problem

Postby Julio Jerez » Tue Oct 29, 2013 8:29 am

when I try I did no see the error. but I see now you change the casting shape.
it look like you are casting a chamfered cylinder, I will try with that and hopefully that will expose the bug for everything.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby Julio Jerez » Tue Oct 29, 2013 1:18 pm

Ok I found the bug.
I will fix tonight and post again when you can update from svn.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby Julio Jerez » Wed Oct 30, 2013 8:48 am

Ok, it is fixed now. Please sync to SVN again.
This was a bad bug
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby Bird » Wed Oct 30, 2013 12:54 pm

Julio Jerez wrote:Ok, it is fixed now. Please sync to SVN again.
This was a bad bug

Hi Julio,

I'm having a problem with this latest version. Sometimes when I call NewtonWorldConvexCast () the hit body returned is the one being cast.

Here's a little demo. http://hurleyworks.com/media/flash/AP_ConvexCast/AP_ConvexCast.html
The first time I cast the cow it has a box shape and you can see by action and the debug output that it hits the rock. But then I change to cow shape to convex hull and the cow doesn't move because the body it hits is itself.

Below is the code I'm using. In the Newton.cpp file the comments for NewtonWorldConvexCast state this about the matrix parameter.
*const dFloat* *matrix - pointer to an array of at least three floats containing the beginning and orienetaion of the shape in global space.

Is that correct. That doesn' look like what you're doing in the Convex Cast demo scene.

-Bird


Code: Select all
// convexCast
void NewtonScene::convexCast (const BodyID & bodyID,
                   TraceDataf & traceData)
{   TRACE("NewtonScen::convexCast")

PhysicsBodies::iterator it = bodies_.find(bodyID);
if ( it != bodies_.end() )
{
   PhysicsBody::Ptr pBody = it->second;
   if( pBody && pBody->component )
   {
      const NewtonBody * const newtonBody = (NewtonBody*)pBody->component->userData;
      if( !newtonBody ) return;

      NewtonCollision * const shape = NewtonBodyGetCollision(newtonBody);
      if( !shape ) return;

      dMatrix matrix;
      NewtonToolBase::convertEigenToNewtonPose(pBody->component->worldTransform, matrix);

      Matrix3f orientation = pBody->component->worldTransform.linear();

      // ray is along the Z
      Vector3f rayEnd = pBody->component->worldTransform.translation() + (1000000 * orientation.col(2).normalized());
      dVector endPoint( rayEnd[0], rayEnd[1], rayEnd[2] );
      dFloat hitParam;
      NewtonWorldConvexCastReturnInfo info[16];

      int count = NewtonWorldConvexCast (world_, &matrix[0][0], &endPoint[0], shape, &hitParam, NULL, NULL, &info[0], 4, 0);   
      if (count)
      {
         const NewtonBody* hitBody = info->m_hitBody;
         NewtonEntity * body = (NewtonEntity*) NewtonBodyGetUserData(hitBody);
         matrix.m_posit += (endPoint - matrix.m_posit).Scale (hitParam);
         DB(pBody->name + " hit " + body->name);

         dVector v = matrix.m_posit;
         Vector3f p( v[0], v[1], v[2] );
         pBody->component->worldTransform.translation() = p;

      }
   }
}
}
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: convex cast problem

Postby Julio Jerez » Wed Oct 30, 2013 1:34 pm

is this the very latest I check in this morning?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby Bird » Wed Oct 30, 2013 1:42 pm

Julio Jerez wrote:is this the very latest I check in this morning?


Yes, it's the very latest SVN version 1189

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: convex cast problem

Postby Julio Jerez » Wed Oct 30, 2013 1:53 pm

Bird wrote:
*const dFloat* *matrix - pointer to an array of at least three floats containing the beginning and orienetaion of the shape in global space.

Is that correct. That doesn' look like what you're doing in the Convex Cast demo scene.


that commnet woudl be wrong.
matrix ix a 4 x 4 orthonormal matrix, teh form soudl be

f.x f.y f.z 0.0
u.x u.y u.z 0.0
r.x r.y r.z 0.0
p.x p.y p.z 1.0

f, u, r are three mutually perpendicular unit vertor
p is the position, is is important that p.w = 1.0

I am sure you have it right, but make sure that it is right
to clarify, did this was working and just broke on my last fix or was it broke before.

The fix that I made has a weak point that I put a comment, besaicee I clal a function, by becau set hfuntion is virtual,
I did not want to change the interface to pass another parametr, instead I overwote the data structure that is passed as parameter.
That kind of stuff is amost never right, but data structure is created locally, so I thought that there was no need to save the old paramerer.

Plase very that the matrix is right, before I make sure thet fix is 100 safe.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby Julio Jerez » Wed Oct 30, 2013 2:12 pm

When I look at the video, I see that when you change form box to convex hull, the cast function detect the cow.
Some questions in this function
int count = NewtonWorldConvexCast (world_, &matrix[0][0], &endPoint[0], shape, &hitParam, NULL, NULL, &info[0], 4, 0);
you are not passing the NewtonWorldRayPrefilterCallback prefilter an dthe user data.

The cast will report the closest hit, which in this case happen to be the cow itself, and I am guessing it I because of rounding error in the matrix.
You need to implement a funtion NewtonWorldRayPrefilterCallback and pass that as a argument to NewtonWorldConvexCast,
then on the function you put object that you need to filter, like for example the objet that originate the cast.
The funtion is call wi the casted body, the shape hit, and the userdata that you pass to the call, then in the fiolter call bakc you chek if the body, maches
anyone that you place on some list of objects, and if it does returrn false so that is skip that object or shape.
It is very similar to ray cast.

My guess that this is the problem
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby Bird » Wed Oct 30, 2013 2:24 pm

I am sure you have it right, but make sure that it is right
to clarify, did this was working and just broke on my last fix or was it broke before.

Yes, I'm sure the matrix is correct. I was having some other problems that I was about to report but your last update this morning fixed them all.

I'm still not sure about the matrix parameter in the NewtonWorldConvexCast() call . In the Sandbox demo it looks like you set the matrix position to the mouse position in world space. I thought it had to be the position of the shape being cast.

Code: Select all
float x = dFloat (mouseX);
float y = dFloat (mouseY);
dVector p0 (camera->ScreenToWorld(dVector (x, y, 0.0f, 0.0f)));
dVector p1 (camera->ScreenToWorld(dVector (x, y, 1.0f, 0.0f)));

// do the convex cast here
dMatrix matrix (GetIdentityMatrix());
matrix.m_posit = p0;
dFloat hitParam;
NewtonWorldConvexCastReturnInfo info[16];
NewtonCollision* const shape = m_stupidLevel->GetCurrentShape();
int count = NewtonWorldConvexCast (world, &matrix[0][0], &p1[0], shape, &hitParam, NULL, NULL, &info[0], 4, 0);


The funtion is call wi the casted body, the shape hit, and the userdata that you pass to the call, then in the fiolter call bakc you chek if the body, maches
anyone that you place on some list of objects, and if it does returrn false so that is skip that object or shape.
It is very similar to ray cast.

My guess that this is the problem


Ok, I'll give that a try. Thanks for the help

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

Re: convex cast problem

Postby Julio Jerez » Wed Oct 30, 2013 2:40 pm

The function takes a matrix that represent the origin from where cast start, that can be any matrxi in global space. and a destination point
This is just like raycast, the only difference Is that because this function sweep a shape, the shape has to have an orientation.
In the sand box demo I shoe the mouse exposition in global space because the start point is the camera eye point. In your case the matrix should be the transformation matrix of the cow. So the ray goes for the cow origin to whatever destination point you want.
There is also a new ConvexRayCast function, that si just like that but, that do no calculate contacts.

you can compare ray cast to a convex cast side by side, if you conside a raycast equal to a convexcast that cast a point.
the convex cast need to define the orientation of the shape, and the shape itself, the rest is all the same.
It does not has to be a shape of a body in a scene. Using the shape of a body is convinent because it gives both the shape and the initial matrix.

I am guess that those other bugs were release to the bugs fix that I checked.
The filter bug was alwa there, but you never saw because those oteh bugs.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: convex cast problem

Postby Bird » Wed Oct 30, 2013 2:48 pm

Ok, thanks for the explanation. I hooked up the NewtonWorldRayPrefilterCallback and that works perfectly now.

-Bird
Bird
 
Posts: 636
Joined: Tue Nov 22, 2011 1:27 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron