A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Crashy » Wed Jul 24, 2013 11:39 am
Hi,
I'm trying to simulate the fact that objects get damages when colliding too hard, but I don't know how to do it properly.
I first tried to use the contact normal speed, but the results were hazardous.
My next idea is to compare the body velocity before and after contact, and if the difference is too high, apply damages. Is this the right way to do it, or is there a more clever one?
Thanks
-
Crashy
-
- Posts: 101
- Joined: Fri Dec 03, 2010 6:30 am
by Julio Jerez » Wed Jul 24, 2013 1:30 pm
the contact speed should do the trick.
velocity before and after is no a really goo method because all you woudl be measurin is teh corefiecne of restitituion.
bascially the entire formulation of the phsycis engine thet the total memnetum momnetum is conversved, threfore velocity before and after and collsion.
threfore if a ow body collide must ligne lie oen will game angular velocity and lose linear velocity bu the sum will be the same.
you will et very a behavior that will apera very erratic, bu that's because you will not be measuring tha change of angualar mometum.
the contact velocity along the contact normal is a better metric, and should be vey consistent every time.
if thi was not teh case them teh entire engien would not work.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Crashy » Thu Jul 25, 2013 9:42 am
Ok I understand better now. I have changed my test to take in account the fact that some parts of the aircraft are more fragile than other, and not resistant to the same type of collision.
Thank you.
-
Crashy
-
- Posts: 101
- Joined: Fri Dec 03, 2010 6:30 am
by FSA » Sun Jul 28, 2013 6:17 pm
How can I get the Contact speed?
-

FSA
-
- Posts: 322
- Joined: Wed Dec 21, 2011 9:47 am
by Julio Jerez » Sun Jul 28, 2013 7:11 pm
in you contact callback you can add a loop like this
- Code: Select all
void GenericContactProcess (const NewtonJoint* contactJoint, dFloat timestep, int threadIndex)
{
NewtonBody* const body = NewtonJointGetBody0(contactJoint);
for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact)) {
dFloat speed;
dVector point;
dVector normal;
dVector dir0;
dVector dir1;
dVector force;
NewtonMaterial* const material = NewtonContactGetMaterial (contact);
NewtonMaterialGetContactForce (material, body, &force.m_x);
NewtonMaterialGetContactPositionAndNormal (material, body, &point.m_x, &normal.m_x);
NewtonMaterialGetContactTangentDirections (material, body, &dir0.m_x, &dir1.m_x);
speed = NewtonMaterialGetContactNormalSpeed(material);
//speed = NewtonMaterialGetContactNormalSpeed(material);
// play sound base of the contact speed.
//
}
}
you can get all the information teh a contact generates.
you do not even have to do it in the call back you can call thos funtion for any body of interest like this at any time
here is a function form the sandbox demo
file: ..\applications\demosSandbox\sdkDemos\toolBox\PhysicsUtils.cpp
- Code: Select all
dVector ForceBetweenBody (NewtonBody* const body0, NewtonBody* const body1)
{
dVector reactionforce (0.0f, 0.0f, 0.0f, 0.0f);
for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint(body0); joint; joint = NewtonBodyGetNextContactJoint(body0, joint)) {
if ((NewtonJointGetBody0(joint) == body0) || (NewtonJointGetBody0(joint) == body1)) {
for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {
dVector point;
dVector normal;
dVector contactForce;
NewtonMaterial* const material = NewtonContactGetMaterial (contact);
NewtonMaterialGetContactPositionAndNormal (material, body0, &point.m_x, &normal.m_x);
NewtonMaterialGetContactForce(material, body0, &contactForce[0]);
//forceAcc += normal.Scale (forceMag);
reactionforce += contactForce;
}
break;
}
}
return reactionforce;
}
once to get the material, you can get the force or the impulse, hwo even doing on the callback is teh only tiem tha you cna get the ipulse before teh conact are resolved.
for example sta a ball is falling on a flat plane, and it hit the floor and 100 m/s
if you read the contact velocity on the call back you will get 100 m/s on each contact. but you cna not read teh force need to prevent penetartion
if you read the contac velocity afte the inpact you will read the bounce velocity, and teh force that teh collsion generetd to preven teh interpenetation.
-
Julio Jerez
- 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 1 guest