Archimedes Buoyancy

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Archimedes Buoyancy

Postby Nearga » Sun Sep 07, 2008 9:43 am

okay, so i add new material(bouyancyForceMaterialID), callback for it(ApplyBuoyancy), in callback i search for bodies, that are falling into the water(with a help of NewtonCollisionIsTriggerVolume) and started to add buoyanicy force, as i got some problems

Code: Select all
NewtonBodyAddBuoyancyForce (body, primitive->m_density, 0.8f, 0.8f, &gravity[0], PhysicsBouyancyPlane, (void*) trigger);


1) what is parameter dFloat fluidDensity - fluid density. in NewtonBodyAddBuoyancyForce ?
2) what is const dFloat *gravityVector - if it is a vector that shows gravity (0,0,-10), why it is dVector gravity (0.0f, -10.0f, 0.0f, 0.0f); in example ?
3) what is the last parameter (void*) trigger, it is not published in wiki...
4) whats going on in function PhysicsBouyancyPlane?
Code: Select all
static int PhysicsBouyancyPlane (const int collisionID, void *context, const dFloat* matrix, dFloat* globalSpacePlane)
{
   const NewtonBody* trigger;
   const dMatrix& globalSpaceMatrix =  *(dMatrix*)matrix;

   trigger = (const NewtonBody*) context;

   // find the fluid surface by casting a ray on the trigger volume in the direction of teh gravity

   dVector p0 (globalSpaceMatrix.m_posit);
   dVector p1 (globalSpaceMatrix.m_posit);

   p0.m_y += 100.0f;
   p1.m_y -= 100.0f;

   // get the matrix of the trigger volume
   dMatrix volumeMatrix;
   NewtonBodyGetMatrix(trigger, &volumeMatrix[0][0]);

   // transform the ray to the local space of the trigger volume
   dVector q0 (volumeMatrix.UntransformVector(p0));
   dVector q1 (volumeMatrix.UntransformVector(p1));

   // cast the ray of the collision shape of the trigger volume
   int attribute;
   dFloat param;
   dVector normal;
   param = NewtonCollisionRayCast (NewtonBodyGetCollision(trigger), &q0[0], &q1[0], &normal[0], &attribute);

   _ASSERTE (param >= 0.0f);
   _ASSERTE (param <= 1.0f);

   // now rotate the ray normal  and the intersection point to global space
   normal = volumeMatrix.RotateVector(normal);
   dVector point (p0 + (p1 - p0).Scale(param));

   // return the plane equation
   globalSpacePlane[0] = normal.m_x;
   globalSpacePlane[1] = normal.m_y;
   globalSpacePlane[2] = normal.m_z;
   globalSpacePlane[3] = -(normal % point);
   return 1;
}
Nearga
 
Posts: 21
Joined: Thu Jul 31, 2008 11:47 am

Re: Archimedes Buoyancy

Postby Nearga » Tue Sep 09, 2008 4:02 am

heh, too many questions? :))
Nearga
 
Posts: 21
Joined: Thu Jul 31, 2008 11:47 am

Re: Archimedes Buoyancy

Postby Nearga » Thu Sep 11, 2008 10:03 am

okay, 4-th question is still actual... whats going on in that function ?
Code: Select all
static int PhysicsBouyancyPlane (const int collisionID, void *context, const dFloat* matrix, dFloat* globalSpacePlane)
{
   const NewtonBody* trigger;
   const dMatrix& globalSpaceMatrix =  *(dMatrix*)matrix;

   trigger = (const NewtonBody*) context;

   // find the fluid surface by casting a ray on the trigger volume in the direction of teh gravity

   dVector p0 (globalSpaceMatrix.m_posit);
   dVector p1 (globalSpaceMatrix.m_posit);

   p0.m_y += 100.0f;
   p1.m_y -= 100.0f;

   // get the matrix of the trigger volume
   dMatrix volumeMatrix;
   NewtonBodyGetMatrix(trigger, &volumeMatrix[0][0]);

   // transform the ray to the local space of the trigger volume
   dVector q0 (volumeMatrix.UntransformVector(p0));
   dVector q1 (volumeMatrix.UntransformVector(p1));

   // cast the ray of the collision shape of the trigger volume
   int attribute;
   dFloat param;
   dVector normal;
   param = NewtonCollisionRayCast (NewtonBodyGetCollision(trigger), &q0[0], &q1[0], &normal[0], &attribute);

   _ASSERTE (param >= 0.0f);
   _ASSERTE (param <= 1.0f);

   // now rotate the ray normal  and the intersection point to global space
   normal = volumeMatrix.RotateVector(normal);
   dVector point (p0 + (p1 - p0).Scale(param));

   // return the plane equation
   globalSpacePlane[0] = normal.m_x;
   globalSpacePlane[1] = normal.m_y;
   globalSpacePlane[2] = normal.m_z;
   globalSpacePlane[3] = -(normal % point);
   return 1;
}


why do we need to make a ray?
Nearga
 
Posts: 21
Joined: Thu Jul 31, 2008 11:47 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests