Buoyancy in 3.14 [SOLVED]

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Buoyancy in 3.14 [SOLVED]

Postby pHySiQuE » Wed Jun 07, 2017 6:12 pm

One of my users reported a problem with water physics in Newton 3.14 (skip to 0:35):



Has there been any changes that could affect how this works?

This is my buoyancy code:
Code: Select all
         if (mass > 0.0f)
         {
            NewtonBodyGetAABB(visitor, p0, p1);
            if (p0[1] < world->waterheight)
            {
               dMatrix matrix;
               dVector cog;
               dVector accelPerUnitMass;
               dVector torquePerUnitMass;
               const dVector gravity(0.0f, world->gravity.y, 0.0f, 0.0f);

               NewtonBodyGetMatrix(visitor, &matrix[0][0]);
               NewtonBodyGetCentreOfMass(visitor, &cog[0]);
               //cog = matrix.TransformVector(cog);
               NewtonCollision* const collision = NewtonBodyGetCollision(visitor);

               dFloat shapeVolume = NewtonConvexCollisionCalculateVolume(collision);
               dFloat fluidDentity = 1.0f / (m_waterToSolidVolumeRatio * shapeVolume);
               dFloat viscosity = 0.995f;

               NewtonConvexCollisionCalculateBuoyancyAcceleration(collision, &matrix[0][0], &cog[0], &gravity[0], &m_plane[0], fluidDentity, viscosity, &accelPerUnitMass[0], &torquePerUnitMass[0]);

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

               // here this is show it was done before in 1.5 and 2.xx
               dVector omega;
               NewtonBodyGetOmega(visitor, &omega[0]);
               omega = omega.Scale(viscosity);
               NewtonBodySetOmega(visitor, &omega[0]);

               NewtonBodyGetVelocity(visitor, &omega[0]);
               omega = omega.Scale(viscosity);
               NewtonBodySetVelocity(visitor, &omega[0]);

               NewtonBodyAddForce(visitor, &force[0]);
               NewtonBodyAddTorque(visitor, &torque[0]);               
            }
         }
Last edited by pHySiQuE on Thu Jun 08, 2017 5:18 pm, edited 1 time in total.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Buoyancy in 3.14

Postby Julio Jerez » Thu Jun 08, 2017 9:23 am

no nothing has changed there. played the sand box demo, it behaves as it did before.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Buoyancy in 3.14

Postby pHySiQuE » Thu Jun 08, 2017 5:15 pm

This was occuring because I commented out this line so that the engine would compile with Newton as a DLL:
Code: Select all
cog = matrix.TransformVector(cog);


I replaced it with my own transform code and it worked.

Are the math functions available from the DLL?
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Buoyancy in 3.14

Postby Julio Jerez » Thu Jun 08, 2017 5:18 pm

the math functions aren't dll because most of then are inline,
maybe TransformVector is not inlined but it should be.

you can use you own math thought.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Buoyancy in 3.14 [SOLVED]

Postby pHySiQuE » Thu Jun 08, 2017 5:18 pm

Okay, my own math worked. :mrgreen:

Thanks!
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 16 guests