FIX for: separate() and cpArbiterGetNormal()

Discuss any Chipmunk bugs here.
Post Reply
aisman
Posts: 145
Joined: Tue Mar 04, 2008 2:21 am
Contact:

FIX for: separate() and cpArbiterGetNormal()

Post by aisman »

From the online help:
cpVect cpArbiterGetNormal(cpArbiter *arb, int i)Returns the collision normal for the i’th contact point, flipping it if necessary. Note: Currently due to how Chipmunk’s collision detection is implemented, the collision normals will be the same for all collision points. You can simply do cpArbiterGetNormal(arb, 0) and not have to check each contact point. Note: calling this function from the separate() callback is undefined.

This source snippet let use the cpArbiterGetNormal() on seperate() callback too. (Maybe another return value if the arb->contact = 0 is needed)

Code: Select all

static inline cpVect
cpArbiterGetNormal(const cpArbiter *arb, int i)
{

	if (  arb->contacts )
	{
		cpVect n = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(n);
		return arb->CP_PRIVATE(swappedColl) ? cpvneg(n) : n;
	}
	return cpv(-9999.9999f,-9999.9999f);
}
Of course you can use the snippet also for: cpArbiterGetPoint(...)
Chipmunk4PB: The fastest way to write games together with PureBasic and the Chipmunk physics engine.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: FIX for: separate() and cpArbiterGetNormal()

Post by slembcke »

What good does that do you though? Instead of being undefined, it returns an unhelpful value. I suppose I could add an assertion instead?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests