buoyancy and scaled collisions

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

buoyancy and scaled collisions

Postby arkeon » Wed Nov 19, 2014 9:06 am

Hello,

you should give a try on the buoyancy demo using scaled collision.
I wonder if the collision volume is correct.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Wed Nov 19, 2014 10:23 am

it maybe me wrong. did you try?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Wed Nov 19, 2014 12:40 pm

Yes for now I could not get a correct volume / plane detection.
CalculateVolumeIntegral allways return 0 in my case.

But maybe I just don't understand what the plane should be ^^

I did a quick test in the demo to add random scale and a lot of objects where in falling.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Wed Nov 19, 2014 3:53 pm

no, I thong is may be wrong. I do not think the code the do the plane cut consider the scale.
I will verify.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Wed Nov 19, 2014 5:20 pm

ok thanks.

just another question.

in the demo you have
Code: Select all
// get the fluid plane for the upper face of the trigger volume
         //NewtonBody* const body = m_controller->GetBody();
         m_plane = dVector (0.0f, 1.0f, 0.0f, 1.5f);


what should be a good method to get the plane from the upper face of the trigger volume ?
and what is the fourth value 1.5 ?
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Wed Nov 19, 2014 6:45 pm

The plane is defined as the surface that generate by all point that are a zero distance for some other point alone some direction vectors
If the direction vector is V and the arbitrary point is P0 then the distance for any point
P to P0 alone V is

D = V dot (P – P0)

If you expand that you get

D = P.x * V.x + P.y * V.y + P.z * V.z - ( P0.x * V.x + P0.y * V.y + P0.z * V.z)

But this ( P0.x * V.x + P0.y * V.y + P0.z * V.z)
Is a constant we can call E, and we call P.x = A, P.y = B, P.Z = C

Then the plane equation is

e = A * x + B * y + C * Z + D

when e = zero then that a plane equation
in that example D is 1.5, anything above 1.5 is above the plane everything below 1.5 is below the plane.

how do I find it? I do not, is set like that by design. I say I want the water surface at 1.5 meters from the ground. then I write the plane equation for a plane that is horizontal and is at 1.5 meter above the ground
The trigger volume is just for the engine to capture when an body is close to the that plane so that the buoyancy is applied, because otherwise a plane extent to infinity.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Wed Nov 19, 2014 7:21 pm

ok thanks this is what I was thinking, so my problem must be in the plane test.

so you convert the global plane to the local collision coords and then test which vertices are under or upper the plan.

and this is here the test seems to fail for me.

the w (level) of the plane should be scaled or the vertices maybe in this tests ?
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Wed Nov 19, 2014 10:22 pm

yes exactly.

The scaled should be applied to the plane to bring to the space of the un-scaled collision, do the calculation an then the result is converted back to the space of the scaled shape.

But I do not remember doing that so it most be wrong.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Thu Nov 20, 2014 11:51 am

does it seems correct to you ?

//Edit updated the code
this one is almost working but objects seems to float on the local axis :/
Code: Select all
dFloat Ixx;
   dFloat Iyy;
   dFloat Izz;
   dFloat mass;
         
  NewtonBodyGetMassMatrix(visitor->getNewtonBody(), &mass, &Ixx, &Iyy, &Izz);
   if (mass > 0.0f)
  {
      dMatrix matrix;
    dMatrix offmatrix;
      dVector cog;
      dVector accelPerUnitMass;
      dVector torquePerUnitMass;

    //gravity
    Ogre::Vector3 gravity(Ogre::Vector3::ZERO);
    if(mApplyGravity && mNode != 0 && mNode->GetParentScene() != 0)
      gravity = mNode->GetParentScene()->GetPhysicsWorld()->GetPhysicGravity();

    //get plane from the top of trigger body
    dVector plane(0.0f, 1.0f, 0.0f, 1.5f);
    NewtonCollision* const pcollision = NewtonBodyGetCollision(O3Body->getNewtonBody());
    NewtonBodyGetMatrix(O3Body->getNewtonBody(), &offmatrix[0][0]);

    dVector minABB;
    dVector maxABB;
    NewtonCollisionCalculateAABB(pcollision, &offmatrix[0][0], &minABB[0], &maxABB[0]);

    Ogre::Quaternion pquat = mNode->GetOgreSceneNodePointer()->_getDerivedOrientation();
    Ogre::Vector3 dir = pquat * Ogre::Vector3::UNIT_Y;

    //scale visitor values
      NewtonCollision* const collision = NewtonBodyGetCollision(visitor->getNewtonBody());
    NewtonBodyGetMatrix(visitor->getNewtonBody(), &matrix[0][0]);

    dVector scale(1.0f, 1.0f, 1.0f, 1.0f);
    NewtonCollisionGetScale(collision, &scale.m_x, &scale.m_y, &scale.m_z);
    dVector invscale(1.0f / scale.m_x, 1.0f / scale.m_y, 1.0f / scale.m_z, 1.0f);

      NewtonBodyGetCentreOfMass(visitor->getNewtonBody(), &cog[0]);
    matrix.m_posit = matrix.m_posit.CompProduct(invscale);
    cog = matrix.TransformVector(cog.CompProduct(invscale));

    //plane;
    plane.m_x = dir.x;
    plane.m_y = dir.y;
    plane.m_z = dir.z;
    plane.m_w = dir.dotProduct(-Ogre::Vector3(maxABB.m_x * invscale.m_x, maxABB.m_y * invscale.m_y, maxABB.m_z * invscale.m_z));

    dFloat shapeVolume = NewtonConvexCollisionCalculateVolume(collision) * invscale.m_x * invscale.m_y * invscale.m_z;
      dFloat fluidDentity = mass / (mFluidWaterToVolume * shapeVolume);

    NewtonConvexCollisionCalculateBuoyancyAcceleration(collision, &matrix[0][0], &cog[0], &gravity.x, &plane[0], fluidDentity, mFluidViscosity, &accelPerUnitMass[0], &torquePerUnitMass[0]);

    dVector force (accelPerUnitMass.CompProduct(scale).Scale(mass));
      dVector torque (torquePerUnitMass.CompProduct(scale).Scale(mass));

      NewtonBodyAddForce (visitor->getNewtonBody(), &force[0]);
      NewtonBodyAddTorque (visitor->getNewtonBody(), &torque[0]);
   }


just noticed that the viscosity parameter behavior is commented in newton dgCollisionInstance::CalculateBuoyancyAcceleration

do you plan to get it back ?
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby arkeon » Fri Nov 21, 2014 6:43 am

no luck :/

I'll wait you get the time to manage the scales in this.

I would not disable the scale since this is the only way in newton3 to make an non uniform ellipsoid (and this is a usefull feature in many cases).
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Fri Nov 21, 2014 1:26 pm

no do no disable the scale, scale is essential to the engine,

this is eassy to fix, I will do it tomorrow.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Fri Nov 21, 2014 1:28 pm

Ok thanks, I'm trying to understand in newton but maths are just worst than chinese for me ^^

I tried this but the result is the same:

Code: Select all
dgVector dgCollisionConvex::CalculateVolumeIntegral (const dgMatrix& globalMatrix, const dgVector& globalPlane, const dgVector& scale) const
{
   dgPlane localPlane (globalMatrix.UntransformPlane (globalPlane));
  localPlane.Scale(((dgFloat32)1.0f / scale.m_x) * ((dgFloat32)1.0f / scale.m_y) * ((dgFloat32)1.0f / scale.m_z));
  dgVector cg (CalculateVolumeIntegral (localPlane).CompProduct3(scale));
   
   dgFloat32 volume = cg.m_w * scale.m_x * scale.m_y * scale.m_z;
   cg = globalMatrix.TransformVector (cg);
   cg.m_w = volume;
   return cg;
}
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby Julio Jerez » Fri Nov 21, 2014 1:41 pm

when I fix it I will show you the exact place where to place the reformation.
you have the idea,

basically the simple

space the plane on input, and scale the value out exit.

what may confuse you is how to apply a non uniform scale to a plane. It is simple but not intuitive.
Is one of those thing that you nee to truth the algebra.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: buoyancy and scaled collisions

Postby arkeon » Fri Nov 21, 2014 1:44 pm

hehe ok I'll just wait and stop breaking everything :)

I was wondering that it must be made in previous functions since the compound collision still not act the same than the others (even if it act weird)
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: buoyancy and scaled collisions

Postby arkeon » Sat Nov 22, 2014 9:04 pm

what should be the proper calculation for the fluid density ?

when I use density = mass / (ratio * objectvolume)
the heavier objects are bouncing out of the trigger volume instead of sinking (object with unit scale)

it seems better when I use
density = 1 / (mass * ratio * objectvolume)

but it don't work either for objects lighter than 1 kg


will you have time to make the scale correction soon ? I have a release on monday and have to know if I put this feature in it or not :)
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 8 guests

cron