Static body with force...

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Static body with force...

Postby telmopereira » Wed May 19, 2010 9:26 am

Hi everyone,

What i am trying to do is create a static body, like a box, that i don't want to move. So for that i create the box with collision using CollisionTree ... In that way it detects that there is a contact between that box and the rest of the objects and i guarantee that my box never moves. However there is a problem...i want to know the force that this box "suffer" when some object it that, but using CollisionTree the getForce function always returns (0,0,0). I try out with collision Box and mass = 0. On this way the object is static but the values i am getting are not realistic...sometimes are (0,0,0), and other times give high values, or values in axis that makes not sense...

Another problem is because i am controlling one object (a sphere in this case), when my sphere collides with other object of the scene, that object moves and my sphere don't "get inside" the other object...with the mass=0 applied to a box, the object that i control can pass through the box, can be "inside" the box...how can i manage this ?

Many thanks,

Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Static body with force...

Postby Julio Jerez » Wed May 19, 2010 11:02 am

you can not get the force on a static body, but you can get the indirectly from the body in contact with that static body.
you can iterate over teh contact joints tha connect the body to the static body and get the force magnitud, the point and the normal,
and you can reconstruct the forces that are acting over that static body.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Static body with force...

Postby telmopereira » Wed May 19, 2010 11:07 am

When i try the collision Box and mass = 0 i use the getForce and i receive values but not si realistic...sometimes are (0,0,0), and other times give high values, or values in axis that makes not sense...

Do you have idea why?
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Static body with force...

Postby Julio Jerez » Wed May 19, 2010 11:24 am

GetForce retun Net Force on a Body, if you want to caculate the force acting of thr static body here is a funtion you can use for that

Code: Select all
dVector GetForceOnStaticBody (NewtonBody* body, NewtonBody* staticBody)
{

dVector totalForce (0, 0, 0);
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
      NewtonBody* body0;
      NewtonBody* body1;

      body0 = NewtonJointGetBody0(joint);
      body1 = NewtonJointGetBody1(joint);
      if ((body0 == staticBody) || (body1 == staticBody)) {

         for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {

            float forceMag;
            dVector point;
            dVector normal;   
            NewtonMaterial* material;

            material = NewtonContactGetMaterial (contact);
            
            NewtonMaterialGetContactForce (material, &forceMag);
            NewtonMaterialGetContactPositionAndNormal (material, &point.m_x, &normal.m_x);

            totalForce += normal.Scale (-forceMag);
         }
      }
   }
     return  totalForce;
}


you need to call it after a NewtonUpdate, that way the force will be valid in the same frame.
calling it in a call back will not guarantee the force will be valid on that frame since callback are made from many points in the engine
but and the forces are calculated in the last solver stage.
That mean you will hav eto make teh call afte the Netwon update.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Static body with force...

Postby telmopereira » Wed May 19, 2010 11:28 am

And how is the best to create a static body ? Setting collision as box and mass = 0 or using a collision like collisionTree ?

Many thanks man
Telmo
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Static body with force...

Postby Julio Jerez » Wed May 19, 2010 11:29 am

any body with mass = 0 is a static body.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Static body with force...

Postby telmopereira » Wed May 19, 2010 11:33 am

I suppose that the code that you post also will work on bodys that are not static right ?
telmopereira
 
Posts: 29
Joined: Thu Apr 15, 2010 12:52 pm

Re: Static body with force...

Postby Julio Jerez » Wed May 19, 2010 11:40 am

Body must be a not static body. It will no work if you call it with body
body will the the ball, and staticBody is the other body, it can be any othe body.
what the funtion return is teh force that Body is assetting on staticBody.
for example say body is a Box restion of a floor.
you call

dVector GetForceOnStaticBody (box, floor)

and you get the weigh the of the Box.

if for example teh Box was the last box on a stack of several boxes on top, then you ge the weigh of the Box plus all the boxes on the top.
if the Box was just hitting the Floor for some altitude, the for get and impulse force
that is the change of mometum per the timestep plus the weight of the Box.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron