Physics Blowing Up

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Physics Blowing Up

Postby Firefly » Mon Aug 11, 2008 4:24 am

Ok, I might be doing something wrong but I can't figure out why setting the position of a body would cause it blow up all the physics afterward.

Code: Select all
D3DXMATRIX rot, trans, result;
D3DXMatrixIdentity(&rot);
D3DXMatrixIdentity(&trans);

D3DXMatrixTranslation(&trans, GetPosition().x, GetPosition().y, GetPosition().z);
D3DXMatrixRotationZ(&rot, D3DXToRadian(90));
result = rot * trans;

m_pCollision = NewtonCreateBox(m_pWorld, m_vSize.x, m_vSize.y, m_vSize.z, &result.m[0][0]);


Setting the rotation on its own works fine, but once I add the translation my objects go crazy and float around the level and do sudden jerky movements.
Firefly
 
Posts: 32
Joined: Wed Jan 17, 2007 4:58 am

Re: Physics Blowing Up

Postby Julio Jerez » Mon Aug 11, 2008 6:26 am

you neet to mak esur ethe emel mat4_4 of teh matrix is 1.0
I do nto think the function set translation is doing that.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics Blowing Up

Postby Firefly » Mon Aug 11, 2008 6:53 am

I managed to fix it by only doing rotation in that part. Then later on setting the translation using NewtonSetBodyMatrix. I will test your theory though and let you know.

Another question relating to another matter, how does NewtonOnAABBOverlap work? I'm trying to use it for entities that can be walked into and picked up.. such as health and weapons, etc.

This is my callback code. I'm trying call the "Touch" function of each entity taking part in the collision. But ent1 is always null and ent0 is always true and it is the entity that is setup to be a trigger.

Code: Select all
int AABBOverlap (const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1, int threadIndex)
{
   CPhysicsBody* ent0 = NULL;
   CPhysicsBody* ent1 = NULL;

   ent0 = (CPhysicsBody*)NewtonBodyGetUserData(body0);
   ent1 = (CPhysicsBody*)NewtonBodyGetUserData(body1);

   if ( ent0 && ent1 )
   {
      ent0->Touch(ent1);
      ent1->Touch(ent0);
   }

   return 1;
}
Firefly
 
Posts: 32
Joined: Wed Jan 17, 2007 4:58 am

Re: Physics Blowing Up

Postby Julio Jerez » Mon Aug 11, 2008 10:00 am

the pointer to the bodies on the callback can never be NULL.
this is the AABBOverlap function callback in the bouyancy demo
Code: Select all
static int ApplyBuoyancy (const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1, int threadIndex)
{
   const NewtonBody* body;
   const NewtonBody* trigger;
   RenderPrimitive* primitive;

   // get the body with the trigger volume
   if (NewtonCollisionIsTriggerVolume (NewtonBodyGetCollision(body0))) {
      body = body1;
      trigger = body0;
   } else {
      body = body0;
      trigger = body1;
   }

   _ASSERTE (NewtonCollisionIsTriggerVolume (NewtonBodyGetCollision(trigger)));
   _ASSERTE (!NewtonCollisionIsTriggerVolume (NewtonBodyGetCollision(body)));

   dVector gravity (0.0f, -10.0f, 0.0f, 0.0f);

   primitive = (RenderPrimitive*) NewtonBodyGetUserData(body);

//   dFloat density;
//   dFloat mass;
//   dFloat dommy;
//   dFloat volume;
//   NewtonBodyGetMassMatrix(body, &mass, &dommy, &dommy, &dommy);
//   volume = NewtonConvexCollisionCalculateVolume(NewtonBodyGetCollision(body));
//   density = 1.5f * mass / volume;

   NewtonBodyAddBuoyancyForce (body, primitive->m_density, 0.8f, 0.8f, &gravity[0], PhysicsBouyancyPlane, (void*) trigger);
   return 1;
}

I check if one of the body to be a trigger,
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics Blowing Up

Postby Firefly » Mon Aug 11, 2008 10:41 am

The problem isn't that the body is null, its that getting the user data for body it collides with is always null.

Each time the callback is called I can get can user data for the body that is the trigger, but if I walk my player into this trigger body, the second body in the callback should be giving me back the user data for my player.. but it doesn't... so I'm asking why.

This code might make more sense to you:

Code: Select all
int AABBOverlap (const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1, int threadIndex)
{
   const NewtonBody* body;
   const NewtonBody* trigger;

   CPhysicsBody* triggerEnt = NULL;
   CPhysicsBody* otherEnt = NULL;

   if (NewtonCollisionIsTriggerVolume (NewtonBodyGetCollision(body0)))
   {
      body = body1;
      trigger = body0;
   }
   else
   {
      body = body0;
      trigger = body1;
   }

   triggerEnt = (CPhysicsBody*)NewtonBodyGetUserData(trigger);
   otherEnt = (CPhysicsBody*)NewtonBodyGetUserData(body);

        // ERROR: otherEnt is always NULL, why????
   if ( triggerEnt && otherEnt )
   {
      triggerEnt->Touch(otherEnt);
      otherEnt->Touch(triggerEnt);
   }

   return 1;
}
Firefly
 
Posts: 32
Joined: Wed Jan 17, 2007 4:58 am

Re: Physics Blowing Up

Postby Julio Jerez » Mon Aug 11, 2008 12:57 pm

are you setting the user data in the body when you create then?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics Blowing Up

Postby Firefly » Mon Aug 11, 2008 9:48 pm

Yes I'm not that silly. That's how I can get user data for the trigger. Both the player and trigger entities derive from CPhysicsBody, so the user data for both should be valid but in this callback they're not. It's as if its just not detecting the player is walking into the trigger. Is there anything else I need to set up to cause it to trigger?
Firefly
 
Posts: 32
Joined: Wed Jan 17, 2007 4:58 am

Re: Physics Blowing Up

Postby Julio Jerez » Tue Aug 12, 2008 12:43 am

not, you should ge the user data for the body anywhere.
I just added two assert to teh callback in teh archimedes bouunacy demo and it works

Code: Select all
static int ApplyBuoyancyAABBLevel (const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1, int threadIndex)
{
   const NewtonBody* body;
   const NewtonBody* trigger;
   RenderPrimitive* primitive;

   _ASSERTE (NewtonBodyGetUserData(body0));
   _ASSERTE (NewtonBodyGetUserData(body1));

   // get the body with the trigger volume
   if (NewtonCollisionIsTriggerVolume (NewtonBodyGetCollision(body0))) {
      body = body1;
      trigger = body0;
   } else {
      body = body0;
      trigger = body1;
   }

   _ASSERTE (NewtonCollisionIsTriggerVolume (NewtonBodyGetCollision(trigger)));
   _ASSERTE (!NewtonCollisionIsTriggerVolume (NewtonBodyGetCollision(body)));

   dVector gravity (0.0f, -10.0f, 0.0f, 0.0f);

   primitive = (RenderPrimitive*) NewtonBodyGetUserData(body);
   NewtonBodyAddBuoyancyForce (body, primitive->m_density, 0.8f, 0.8f, &gravity[0], PhysicsBouyancyPlane, (void*) trigger);
   return 1;
}

If you are getting a NULL userdata it must be because you are creation a body and not setting any user data because the engien do nto touch any user data ever.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics Blowing Up

Postby Firefly » Tue Aug 12, 2008 3:25 am

I assure you the user data IS being set, exactly how the trigger's user data is. For some reason it just isn't picking up that theres a collision happening.
Firefly
 
Posts: 32
Joined: Wed Jan 17, 2007 4:58 am

Re: Physics Blowing Up

Postby Julio Jerez » Tue Aug 12, 2008 7:54 am

that can not be possible
The trigger data is not different than anything else, it is just a collision for wich contact are not calculated
can you send me a running demo?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics Blowing Up

Postby Firefly » Wed Aug 13, 2008 1:54 am

Ohh *. Hold on a minute, AABBOverlap.. does that only work for actual AABB's? like boxes? Coz my player is enclosed in a cylinder.

If that's the case, what do you propose is the best solution for creating entities that:

1. Optionally collide with the world
2. Don't have physical reaction to players colliding into them (much like the trigger volumes)
3. Players can walk into them and "trigger" a Touch event

I assume I'd have to use the ContactProcess callback instead?

Anyways, I've sent you a demo of the AABBOverlap problem in the a PM.
Firefly
 
Posts: 32
Joined: Wed Jan 17, 2007 4:58 am

Re: Physics Blowing Up

Postby agi_shi » Wed Aug 13, 2008 7:51 am

No, AABB is for all objects that might be colliding. Basically, its your broad-phase collisions, with the contact process callback being your narrow-phase collisions.

Honestly, I've never encountered your issue so far (except some odd bugs I had with 1.53, but those are long gone now in 2.0).
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Physics Blowing Up

Postby Julio Jerez » Wed Aug 13, 2008 9:52 am

Firefly wrote:1. Optionally collide with the world
2. Don't have physical reaction to players colliding into them (much like the trigger volumes)
3. Players can walk into them and "trigger" a Touch event


for that you need a material filter because the body is not a trigger and it is not a body.
It is a trigger for other bodies and it is a body for the world.

Using the old method of 1.53 you will need to make a trigger material, a world material and a body material, then
set connection Trigger-World to be normal collidable
set connection Trigger-Body material to be normal collidable by setting a contact callback that reject all contacts
set connection body Material-world Material to normal collision

that was the method in 1.53 and it is expensive, with 2.0 is a little different, but more efficient

make only two material world and body material.
make the trigger body and set his collision shape to trigger volume, also make the body infinite mass .
asign the Body Material to trigger volume,
Now if a body interest the trigger volume body will receive a callback but no contact will be calculated.
If you need to move the trigger volume you can set it matrix after the simulation loop or on any of the callback.
In the black Hole demo I use that trick,
I made a big trigger object and I set the matrix to the matrix of a smaller body that is the start inside,
that is just one technique you can use any method you want.


2.0 supports both methods, just the one is more efficient that the other.
if you want trigger that are invisible to some object and not to others then the only way is by using the first method and use callback filter,
It is the more powerful the trigger method is a simpler special case that is used by commercial engines,
and since its is perceived as an advance feature of commercial engine I added but in reality is nothing but a special case of the Material we already had in 1.53 and still have in 2.0

Note:
BTW teh demo is very cool. is that the player controller on the SDK, or your own?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics Blowing Up

Postby Firefly » Thu Aug 14, 2008 7:05 am

Ah very cool. Tested what you mentioned in the PM and yep it was the materials. I'll have to go set up a nice material manager :D

BTW: Thanks, it's my own player controller but its only very simple, no where near as complex as the one in the SDK. I have to improve it eventually. The demo I showed is a team project for our course at Uni. But a lot of the code is from my engine, so once I get some time to get more done on that I'll show you some more stuff :)
Firefly
 
Posts: 32
Joined: Wed Jan 17, 2007 4:58 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron