Contact events

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Contact events

Postby sea » Fri Aug 29, 2008 6:03 pm

Hi! I'm trying to make some objects that disappear after any contact with each other/environment. I thought about some event system in my physics adapter. After a while I found NewtonMaterialSetCollisionCallback. It sounds good, but it's very problematic. I was looking for a solution many hours and I found nothing.

Firstly I used NewtonContactBegin to simply call my own event functions of some objects, but it didn't work at all. I thought that this function is called when collision begins, but it's called when objects are able to collide. So, I decided to use NewtonContactProcess. I think it would help, but I don't know how to read from its attributes pointers to contacting objects. There was the same situation with NewtonContactEnd. I'd rather avoid creating new materials for each object, because it would make a mess from my physics.

I was searching on this board, google, etc. and nothing simply helped me. If you have some idea how to solve this problem, please answer.

Greets.
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm

Re: Contact events

Postby JernejL » Fri Aug 29, 2008 6:17 pm

There are many demos, which do just that (show how to handle material contact interaction), what you need to do is, store a object pointer as userdata on the object, and retrieve it in the callback and then use that as your object handle.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Contact events

Postby sea » Sat Aug 30, 2008 5:21 pm

I analysed some demos, but I didn't found a solution... Maybe I was looking for it in wrong demos, or something... Anyway, I have some user data and there's no problem when I have an access to it. I would show my problem in different words. Is there any way to get the pointers to contacting bodies from
Code: Select all
int NewtonContactProcess(const NewtonMaterial* material, const NewtonContact* contact)
?

I tried to use NewtonContactBegin and there is no problem reading user data, but this function is called when there was a possible collision between bodies (so my objects were disappearing after bounding box hit - it was visible especially in tree collisions). NewtonContactProcess seems to be doing what I want. My physics adapter is object-oriented and should be very flexible, so maybe that's why it's hard to manage.

I'd rather you write some documentation describing every structure in Newton. Of course, with some note, that using this might be dangerous in some cases. But it would help some developers with evil, satanic ideas. Or tell me about the correct demos, maybe my search was wrong (I apologize for, but usually I'm able to solve my problems - except this one :( ).
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm

Re: Contact events

Postby agi_shi » Sat Aug 30, 2008 10:50 pm

EDIT: Wait, are you using 1.53? I suggest you PM Julio, he'll give you a link to the betas for testing (a lot more robust, the below code is only for the betas). As for 1.53, you'll need to store the two bodies from the contactBegin callback as they are guaranteed to be the same two bodies for the contactProcess callback which is guaranteed to be called subsequently to contactBegin (once for each contact).

(betas:)
It's a bit tricky to grasp at first, but in the end you want something like so:
Code: Select all
void processContactCB(const NewtonJoint *joint, float dt, int thread)
        {

            NewtonWorld *_world = NewtonBodyGetWorld(NewtonJointGetBody0(joint));

            NewtonBody *body0 = NewtonJointGetBody0(joint);
            NewtonBody *body1 = NewtonJointGetBody1(joint);

            ...
       }
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Contact events

Postby Julio Jerez » Sun Aug 31, 2008 12:00 am

as today sea is on 2.0
I hope that he can get upto spee soon so te he can get the the point he was.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Contact events

Postby sea » Sun Aug 31, 2008 12:47 pm

Now it works fine, thank you all very much :)
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 14 guests