buoyancy and scaled collisions

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: buoyancy and scaled collisions

Postby AntonSynytsia » Sat Nov 22, 2014 10:57 pm

Arkdemon, what if yu extract scale? For isntance, if your body scale is [1,3,4], your point will be pos.x*scale.x, pos.y*scale.y, pos.z*scale.z.
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Tue Nov 25, 2014 11:51 am

Ok I was looking at this and I can see the problem.
I have to change few functions to get it fixed.

the problem is here
Code: Select all
dgVector dgCollisionConvex::CalculateVolumeIntegral (const dgMatrix& globalMatrix, const dgVector& globalPlane) const
{
   dgPlane localPlane (globalMatrix.UntransformPlane (globalPlane));
   dgVector cg (CalculateVolumeIntegral (localPlane));
   
   dgFloat32 volume = cg.m_w;
   cg = globalMatrix.TransformVector (cg);
   cg.m_w = volume;
   return cg;
}


it naively transform the plane equation by the matrix. but if that matrix is scaled then that operation is not valid.
I could extract the scale in the function and it will work, however that will be slow.

it is better to change the function so that it take the scale as an argument, that way the plane can be transformed parametrically. the problem is that this a an interface function so I have to change a couple of them.

I will fix this weekend.
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Tue Nov 25, 2014 12:01 pm

ok thanks, this is almost what I did last time but with a bad algebra on plane scale ^^
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Tue Nov 25, 2014 12:48 pm

actually is was easy, please try again

I did not test it but I think it should work.
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Tue Nov 25, 2014 3:17 pm

Thanks I just tried, but it still make scaled collisions going crazy :/
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Tue Nov 25, 2014 3:41 pm

ok I will scale a collision shape and see what is wrong.

does it happen with all scales and all shapes?
what happens if you have a box with a uniform scale?
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Tue Nov 25, 2014 3:46 pm

even with uniform scale the box spin in any direction
the same for a sphere with non uniform scale.

compound collision are not good too.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Tue Nov 25, 2014 3:54 pm

al right that mean is a silly bug, I will test all three cases tonight.
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby Julio Jerez » Thu Nov 27, 2014 12:23 pm

ok I had a stupid bug, after the calculation I was applying the the rotation and scale of the wrong order. I fixed now and I tested with the code

Code: Select all
test buoyancy on scaled collisions
dVector plane (0.0f, 1.0f, 0.0f, 0.0f);
NewtonCollision* xxx0 = NewtonCreateBox(scene->GetNewton(), 2.0f, 4.0f, 6.0f, 0, NULL);
NewtonCollision* xxx1 = NewtonCreateBox(scene->GetNewton(), 1.0f, 1.0f, 1.0f, 0, NULL);
NewtonCollisionSetScale(xxx1, 2.0f, 4.0f, 6.0f);

dMatrix m (dPitchMatrix(45.0f * 3.141692f / 180.0f) * dYawMatrix(40.0f * 3.141692f / 180.0f) * dRollMatrix(70.0f * 3.141692f / 180.0f));

dVector gravity (0.0f, 0.0f, -9.8f, 0.0f);
dVector cog0 (0.0f, 0.0f, 0.0f, 0.0f);
dVector accelPerUnitMass0;
dVector torquePerUnitMass0;
NewtonConvexCollisionCalculateBuoyancyAcceleration (xxx0, &m[0][0], &cog0[0], &gravity[0], &plane[0], 1.0f, 0.1f, &accelPerUnitMass0[0], &torquePerUnitMass0[0]);

dVector cog1 (0.0f, 0.0f, 0.0f, 0.0f);
dVector accelPerUnitMass1;
dVector torquePerUnitMass1;
NewtonConvexCollisionCalculateBuoyancyAcceleration (xxx1, &m[0][0], &cog1[0], &gravity[0], &plane[0], 1.0f, 0.1f, &accelPerUnitMass1[0], &torquePerUnitMass1[0]);


and it generate the identical result.
Please sync and try again
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Thu Nov 27, 2014 1:25 pm

yes great it works almost on all shape, but the compound collision just sink, so the plane for this one must still incorrect.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Thu Nov 27, 2014 4:48 pm

oh yes I did not add the scale for rotation the child of compound collision.

It is in now, please sync and test again.
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Thu Nov 27, 2014 5:33 pm

hmm strange still the same :/

ha no this is when it has scale < 1 I tried with 0.5 0.5 0.5
hmm also simple call to bodySetScale seem to make a bad shape on it.
I'll check my code again but it's strange

>> yes calling NewtonBodySetCollisionScale several time on compound collision seems to break something.
But this is not related to the scale < 1 I think
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Thu Nov 27, 2014 8:05 pm

I do not understand what you mean now.

did the p[lane transform worked. the file was this

d
Code: Select all
gVector dgCollisionConvex::CalculateVolumeIntegral (const dgMatrix& globalMatrix, const dgVector& globalPlane, const dgCollisionInstance& parentScale) const
{
   dgPlane localPlane (globalMatrix.UntransformPlane (globalPlane));

   const dgVector& scale = parentScale.m_scale;
   switch (parentScale.m_scaleType)
   {
      case dgCollisionInstance::m_unit:
         break;

      case dgCollisionInstance::m_uniform:
      {
         localPlane.m_w *= parentScale.m_invScale.m_x;
         break;
      }
      case dgCollisionInstance::m_nonUniform:
      {
         localPlane = localPlane.CompProduct4 (scale | dgVector::m_wOne);
         dgFloat32 mag2 = localPlane % localPlane;
         localPlane = localPlane.Scale4 (dgRsqrt(mag2));
         break;
      }
      default:
      {
// here is where the transform is applied to the plane
         localPlane = localPlane.CompProduct4 (scale | dgVector::m_wOne);
         dgFloat32 mag2 = localPlane % localPlane;
         localPlane = localPlane.Scale4 (dgRsqrt(mag2));
         localPlane = parentScale.m_aligmentMatrix.UntransformPlane (localPlane);
      }
   }
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Thu Nov 27, 2014 8:52 pm

I just updated again, but the problem on compound collisions still here.
the body sink when others float.

also the body is now scaled improperly.
the scale works when I create the compound collision and scale it just after. but if I scale it again later the scaled shape is bad.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Thu Nov 27, 2014 9:29 pm

that doe make sense I did not change the code that scale the compound collision, the transformation of the plane is separate code. was the compound scale working before?

I test the plane transformation of on compound and it is working, I just test it again and is seem to work
Julio Jerez
Moderator
Moderator
 
Posts: 11043
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to Bugs and Fixes

Who is online

Users browsing this forum: Shaderman and 2 guests