A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Adversus » Wed Jan 12, 2011 1:27 pm
Using the code below sometimes (most times returns 0.0f) and the problem just got worse when I switched to using a KinematicController.
Any ideas why this might be?
Thanks.
- Code: Select all
for( void* contact = NewtonContactJointGetFirstContact (OnCollisionContactJoint);
contact;
contact = NewtonContactJointGetNextContact(OnCollisionContactJoint, contact) )
{
vector3df forceMag(0.0f);
NewtonMaterial* material = NewtonContactGetMaterial (contact);
NewtonMaterialGetContactForce (material, &forceMag.X);
totalForceMag += forceMag;
totalNumContacts++;
}
-
Adversus
-
- Posts: 29
- Joined: Tue Oct 12, 2010 8:39 am
by Julio Jerez » Wed Jan 12, 2011 1:35 pm
I do not undernatand the question
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Adversus » Thu Jan 13, 2011 9:13 pm
Sorry that functions returns the totalForceMag variable
and that is sometimes 0.0f when there has been contact which it shouldn't be if there has been contact.
-
Adversus
-
- Posts: 29
- Joined: Tue Oct 12, 2010 8:39 am
by Julio Jerez » Thu Jan 13, 2011 9:44 pm
what are you trying to do?
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Adversus » Tue Jan 18, 2011 11:02 pm
Determine how much damage I should apply to the shields when it collides with something. The harder the impact the greater the damage.
-
Adversus
-
- Posts: 29
- Joined: Tue Oct 12, 2010 8:39 am
by Julio Jerez » Wed Jan 19, 2011 9:56 am
But Impact are not forces, you can cannot get the Impact force in a contact call back because the are calculated afte the contact happens.
you can however get the force it after the Netwon Update using the Contact Iterator.
Basically you can check in the Material callback for the contact velocity, and if it is larger than some threshhold, you can save the contact joint into an array,
then after the newton update, you can go over thr array and collect the forces at each contact point using the same type of function you are using in a contact callback to iterate over the contacts.
this will give you impact force (impulses) but it will alos provide the resting forces and you will not knwo which is which.
you can also get everything resting forces and impart forces, by just just flaging the contact with non residual normal velocity at the contact point in the callback.
But it this is like any other game, you only need the Impact forces (forces with larger than the predefined normal velocity) for a damage model.
you can also use the normal velocity at the contact, in many cases this is berter for Game play because it is a more linear quantity tha a impact force.
for example say you has two bodies one is 1 pound and other is 100 pound falling from the same high to te efloor.
both will have same velocity, so there will get same damage using the impact velocity in the conctact callback
but there will get very different impact forces using the impact force the way I explained above.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Adversus » Thu Jan 20, 2011 11:18 pm
Ok thanks Juan that makes sense.
However I have another problem that is sort of related.
I also use NewtonCollisionSetAsTriggerVolume and unfortunately if I do as you suggest then that contact gets removed and therefore not accessible to the iterator outside the callback. I understand why this is the case however if this is the best method how should I then execute code when using a trigger volume?
At the moment it's all in one place, the contact callback however I sometimes get first chance access violations when I try to allocate memory in this (or any functions it calls) so I would prefer if I could move this to outside the callback (and therefore NewtonUpdate) too.
Thanks for your help.
-
Adversus
-
- Posts: 29
- Joined: Tue Oct 12, 2010 8:39 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests