Page 1 of 1

Chipmunk 5.1 cpContact point

Posted: Mon Feb 15, 2010 7:55 am
by cpnewbies
Hi,
Can anyone let me know what is the new function to obtains the contact point for Chipmunk 5.1.

Prior chipmunk 5, I had the following particle emitter (cocos2d on iPhone) on my callback function.

ParticleSystem *emitter = [ParticleExplosion node];
emitter.position = cpv(contacts->p.x, contacts->p.y);
emitter.life = 0.2f;
emitter.duration = 0.2f;
emitter.lifeVar = 0.2f;
emitter.totalParticles = abs(a->body->v.y)*0.2;
[game addChild:emitter z:3];
emitter.autoRemoveOnFinish = YES;

With the new Chipmunk 5.1, I try the following but don't seem to get the correct contact point when 2 object collide.
CCParticleSystem *emitter = [CCParticleExplosion node];
NSLog(@"....contact point...(%f,%f)......",(cpArbiterGetNormal(arb, 0)).x,(cpArbiterGetNormal(arb, 0)).y );
emitter.position = cpArbiterGetNormal(arb, 0);
emitter.life = 0.2f;
emitter.duration = 0.2f;
emitter.lifeVar = 0.2f;
emitter.totalParticles = abs(a->body->v.y)*0.2;
[game addChild:emitter z:3];
emitter.autoRemoveOnFinish = YES;

The NSLog output does not give me the correct point.

Re: Chipmunk 5.1 cpContact point

Posted: Mon Feb 15, 2010 10:16 am
by slembcke
You are using the normal, you want the contact point. The normal is the direction the surface points at the point of collision.

Re: Chipmunk 5.1 cpContact point

Posted: Tue Feb 16, 2010 4:47 am
by cpnewbies
Any guide on how to get the cpContact point when 2 object collided?

Re: Chipmunk 5.1 cpContact point

Posted: Tue Feb 16, 2010 9:44 am
by slembcke
cpArbiterGetNormal() -> cpArbiterGetPoint()

<rant>Not to sound cranky, (maybe a little) but they are right next to each other in both the header and the documentation. How is it that you found one but not the other? It can be very frustrating to spend a lot of time writing documentation and spend my time answering half of the questions here with things that are in the documentation.</rant>

Please please please read the documentation that I spent so much time writing before asking on the forums.

Re: Chipmunk 5.1 cpContact point

Posted: Tue Feb 16, 2010 4:16 pm
by cpnewbies
Thank Scott. Before I start this post I did try the cpArbitergetnormal and cpArbiterGetpoint. I can't can't get both to work as I don't know how to get the n. Try diff value of n but does not work. Then, thought of just ask around to get a quick answer. I admit I did not go deeper into your source code.

Will try to do that. Thank for maintaining such a great forum and sorry for the question ask.

Re: Chipmunk 5.1 cpContact point

Posted: Tue Feb 16, 2010 5:06 pm
by slembcke
The normal is the 'n'. I'm not sure what you mean when you said you couldn't get both to work.

I don't mean to sound like I'm singling you out on asking questions like that. It's just very frustrating.

Re: Chipmunk 5.1 cpContact point

Posted: Wed Feb 17, 2010 9:02 am
by cpnewbies
No worries. You are absolutely reasonable with your comment. Partly due to my lack of understanding of the Chipmunk 5.1.

I manage to figure out the solution (not sure the best way but it works). In the simplest term (for the benefit of other in case)

In Chipmunk prior 5.1, I had
"emitter.position = cpv(contacts->p.x, contacts->p.y);"
to tell me the contact point between 2 object when they collide so that I can do some particle system on the contact point.

In had upgraded to Chipmunk 5.1 and try to figure out the similar way to achieve the above. At last found
"emitter.position = arb->contacts->p;"

Previously, I was trying to achieve the same objective using cpArbiterGetNormal and cpArbiterGetPoint (I tried before post this question). The challenges is try to figure out "i'th contact point" of the function (I mistakenly say 'n', instead of 'i'). [cpVect cpArbiterGetPoint(cpArbiter *arb, int i)]. Tried the 'i' value of '0', '1'. No luck. I guess when 2 object collided, there are more than 1 contact point (correct me if I am wrong) and identifying the 'i' is a challenge for me.



Thanks

Re: Chipmunk 5.1 cpContact point

Posted: Wed Feb 17, 2010 10:24 am
by slembcke
Ah. I see what you mean now.

The reason why those getter functions exist is to correctly flip the normals to match the collision order specified by the collision handler types. Points don't really have a direction so they are fine. What you are doing is equivalent to grabbing the first collision point, cpArbiterGetPoint(0).