0
votes

I have collision detection in my game. Now I need point of collison. I get it with:

int numPoints = contact.b2contact->GetManifold()->pointCount;
b2WorldManifold worldManifold;
contact.b2contact->GetWorldManifold( &worldManifold );
for (int i = 0; i < numPoints; i++)
{
    NSLog(@"%@" NSStringFormCGPoint(ccp(worldManifold.points[i].x,worldManifold.points[i].y));
} 

This log shows position but in box2d standards. How I should properly convert it to Cocos2d v2 cords? Because multiply by PTM_RATIO not working very well.

UPDATE

At this moment I came up with this.

b2Manifold* mainfold = contact->GetManifold();
int numPoints = mainfold->pointCount;

    for (int i=0; i<numPoints; i++) {
        b2ManifoldPoint *p = mainfold->points;
        NSLog(@"Dot:%@",NSStringFromCGPoint(ccp(p->localPoint.x * PTM_RATIO, p->localPoint.y * PTM_RATIO);));
    }

But that shows correct point only for one body.

1

1 Answers

0
votes

I think your first example was correct, but you were not properly converting the points to world points. Something like this might work (I'm not at my computer to test it out, but I think this will give you the right direction anyway.

int numPoints = contact.b2contact->GetManifold()->pointCount;
b2WorldManifold worldManifold;
contact.b2contact->GetWorldManifold( &worldManifold );
for (int i = 0; i < numPoints; i++)
{
    b2Vec2 worldPoint = worldManifold.points[i]->GetWorldPoint();
    NSLOG(@"(%f,%f)", worldPoint.x*PTM_RATIO, worldPoint.y*PTM_RATIO);
}