A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Ripiz » Tue Aug 03, 2010 9:49 am
I noticed there's function NewtonMaterialSetCollisionCallback() but it works only if one material collides other material and will call function only between these two specific materials. Is there a way to make callback for specific body? Like, if it's missile and I want to make it explode on contact, I don't care if it'll collide wood, metal, or blackhole, I just want it to explode, how do I do that?

Thanks in advance.
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Ripiz » Wed Aug 04, 2010 4:18 am
I meant which Newton function to use to set such callback to Explode() function, not how to make explosion

void Explode(/* some params */){
}
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by JernejL » Wed Aug 04, 2010 5:31 am
inside NewtonContactsProcess use NewtonJointGetBody0 and NewtonJointGetBody1 to see what bodies touched, then do your "explosion".
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Ripiz » Wed Aug 04, 2010 1:35 pm
I set material on my missile:
- Code: Select all
NewtonBodySetMaterialGroupID (body, NewtonFireballMaterial);
My callback:
- Code: Select all
void collisionFireballCallback(const NewtonJoint* contactJoint, dFloat timestep, int threadIndex){
extern int NewtonFireballMaterial;
extern vector<ParticleEmitter*> particleEmitters;
extern NewtonWorld *world;
NewtonBody *body = 0;
body = NewtonJointGetBody0(contactJoint);
if(NewtonBodyGetMaterialGroupID(body) == NewtonFireballMaterial){
ParticleEmitter *emitter = (ParticleEmitter*)NewtonBodyGetUserData(body);
for(unsigned int i = 0; i < particleEmitters.size(); i++){
if(particleEmitters[i] == emitter){
particleEmitters.erase(particleEmitters.begin() + i);
NewtonDestroyBody(world, body);
particleEmitters.push_back(new ParticleEmitter(emitter->loc, Explode, 0.5f));
delete emitter;
break;
}
}
}
body = NewtonJointGetBody1(contactJoint);
if(NewtonBodyGetMaterialGroupID(body) == NewtonFireballMaterial){
ParticleEmitter *emitter = (ParticleEmitter*)NewtonBodyGetUserData(body);
for(unsigned int i = 0; i < particleEmitters.size(); i++){
if(particleEmitters[i] == emitter){
particleEmitters.erase(particleEmitters.begin() + i);
NewtonDestroyBody(world, body);
particleEmitters.push_back(new ParticleEmitter(emitter->loc, Explode, 0.5f));
delete emitter;
break;
}
}
}
}
Problem is, that if I call 'delete emitter;' inside callback it causes some weird heap error and application crashes. I have suspicions that it's Newton problem, because I delete ParticleEmitter in other places too but it's all fine if I comment out both 'delete emitter;' lines in this callback. Anyone have idea how to fix this?
-
Ripiz
-
- Posts: 47
- Joined: Sat Oct 03, 2009 12:07 pm
by Julio Jerez » Wed Aug 04, 2010 1:52 pm
if you are running a dll and you try to delete an object from a callback comming from the DLL,
but that object was not allocated by that DLL, you will have a heap corruption.
rule 101, of programming with DLL is delete and alloc in the same dll Module,
you can place the object you wna to delete into a queuse and then deleted it afte teh neton Update.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- 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 44 guests