How to make certain objects destroy with collision strength

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

How to make certain objects destroy with collision strength

Postby arkdemon » Sat Jan 25, 2014 4:33 pm

Hello everyone. Is it possible to make bodies destroy (or explode or change form) when the collision is too strong ( for example: plane accident) and if so how?
Thank you for your answers.
My name is arkdemon and I don't approve this message :D
User avatar
arkdemon
 
Posts: 90
Joined: Sat Jan 18, 2014 12:38 pm

Re: How to make certain objects destroy with collision stren

Postby Julio Jerez » Sat Jan 25, 2014 5:37 pm

in the contact callback , you cna write somethpm hios

Code: Select all
      dFloat breakImpact = 0.0f;
      for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint(m_myBody); joint; joint = NewtonBodyGetNextContactJoint(m_myBody, joint)) {
         for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {
            dVector contactForce;
            NewtonMaterial* const material = NewtonContactGetMaterial (contact);
            dFloat impulseImpact = NewtonMaterialGetContactMaxNormalImpact(material);
            if (impulseImpact > breakImpact) {
               breakImpact = impulseImpact;
            }
         }
      }


i steh collsion was large tna soem value you can put in tsome list, an dthe you can destroy the object or do what eel you want.

look at teh demo
../newton-dynamics\applications\demosSandbox\sdkDemos\demos\SimpleConvexFracturing.cpp
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to make certain objects destroy with collision stren

Postby arkdemon » Sat Jan 25, 2014 5:59 pm

Ok thank you for your answer. The problem is as I am a newbie with Newton Game Dynamics, I do not know how to use the joints and what their use is. What are they exactly and what is this contact callback you are talking about?
Again, thank you for your help
My name is arkdemon and I don't approve this message :D
User avatar
arkdemon
 
Posts: 90
Joined: Sat Jan 18, 2014 12:38 pm

Re: How to make certain objects destroy with collision stren

Postby Julio Jerez » Sat Jan 25, 2014 7:09 pm

if you have a pointer to a newton body you can to chek if it is detroyed, you can write a function like this
Code: Select all
bool CheckToDestroyBody (NewtonBody* const body, float maxStrength)
{
    for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
        for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {
            dVector contactForce;
            NewtonMaterial* const material = NewtonContactGetMaterial (contact);
            dFloat impulseImpact = NewtonMaterialGetContactMaxNormalImpact(material);
            if (impulseImpact > maxStrength) {
                return true;
            }
        }
    }
    return false;
}



Joints in Netwon are contacts, if you want to check on whi bodies you need to do that check, you can set a contact callbakc lie this
Code: Select all
void GenericContactProcess (const NewtonJoint* contactJoint, dFloat timestep, int threadIndex)
{
   NewtonBody* const body0 = NewtonJointGetBody0(contactJoint);
    NewtonBody* const body1 = NewtonJointGetBody1(contactJoint);
    // and you can put those bodies in some list for late calling the destruction check
}


when yo ucrat eteh world you can set teh contact callbakc like this

Code: Select all
   NewtonWorld* const world = scene->GetNewton();
   int defaultMaterialID = NewtonMaterialGetDefaultGroupID (world);
   NewtonMaterialSetCollisionCallback (world, defaultMaterialID, defaultMaterialID, NULL, UserOnAABBOverlap, GenericContactProcess );


the when two bodis collide, function GenericContactProcess will be called wit teh pointe to a joint.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to make certain objects destroy with collision stren

Postby arkdemon » Sun Jan 26, 2014 6:44 am

Ok thank you very much for your help. I will try to implement it and then I will post the results.

Personally, I wanted to say that I have not seen yet such a configurable library as Newton Game Dynamics and I wanted to say thank you A LOT for this wonderful lib which is fast and does beautiful results. The only drawback that I can find is, I think, the tutorials. The doc is well done but it lacks a bit of tutorials because the lib is very complete and there are lots of things to learn for newbies like me.
My name is arkdemon and I don't approve this message :D
User avatar
arkdemon
 
Posts: 90
Joined: Sat Jan 18, 2014 12:38 pm

Re: How to make certain objects destroy with collision stren

Postby arkdemon » Sun Jan 26, 2014 6:47 am

Sorry, but what do I have to put in UserOnAABBOverlap?
Thank you
My name is arkdemon and I don't approve this message :D
User avatar
arkdemon
 
Posts: 90
Joined: Sat Jan 18, 2014 12:38 pm

Re: How to make certain objects destroy with collision stren

Postby Julio Jerez » Sun Jan 26, 2014 9:16 am

that's another function call pointer. that one is called when the aabb of the bodies overlap, you can test if you want them to collide or not there by returning true or false.
look a the prototype in Newton.h file

you can pass NULL or some thing as simple as this
Code: Select all
static int UserOnAABBOverlap (const NewtonMaterial* const material, const NewtonBody* const body0, const NewtonBody* const body1, int threadIndex)
{
   return 1;
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to make certain objects destroy with collision stren

Postby arkdemon » Sun Jan 26, 2014 10:05 am

Ok thank you.
And to make some debris how do I do?
My name is arkdemon and I don't approve this message :D
User avatar
arkdemon
 
Posts: 90
Joined: Sat Jan 18, 2014 12:38 pm

Re: How to make certain objects destroy with collision stren

Postby Julio Jerez » Sun Jan 26, 2014 12:53 pm

I do not know what you are doing, but you can look at demo ../applications\demosSandbox\sdkDemos\demos\SimpleConvexFracturing.cpp
has you run the sandbox demos?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to make certain objects destroy with collision stren

Postby arkdemon » Sun Jan 26, 2014 12:58 pm

Hello yes I have but, I do not understand exactly what it does.
My name is arkdemon and I don't approve this message :D
User avatar
arkdemon
 
Posts: 90
Joined: Sat Jan 18, 2014 12:38 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron