I'm trying to copy all the collision impulses in one object to another distant object.
The way I figured it, when in my contactListener's PostSolve function, I should get the contact->manifold->localNormal and apply the impulses in the direction of this times the manifold->point[i].normalImpulse, and the same with the tangentImpulse but with the normal turned 90deg. The problem is that the manifold->localNormal is (0,0) in my PostSolve function. Why is that?
Figure a bit of code is necessary, so you can see if I'm doing something wrong, which I probably am.
The function belongs to an object that is suppose to mirror another object, here simply called "body".
Am I close? Way off?
The way I figured it, when in my contactListener's PostSolve function, I should get the contact->manifold->localNormal and apply the impulses in the direction of this times the manifold->point[i].normalImpulse, and the same with the tangentImpulse but with the normal turned 90deg. The problem is that the manifold->localNormal is (0,0) in my PostSolve function. Why is that?
Figure a bit of code is necessary, so you can see if I'm doing something wrong, which I probably am.
The function belongs to an object that is suppose to mirror another object, here simply called "body".
Code:
PostSolve(b2Contact* contact, const b2ContactImpulse* contactImpulse){
b2Manifold* manifold = contact->GetManifold();
b2Vec2 normal = manifold->localNormal;
int count = manifold->pointCount;
for( int i=0; i < count; i++ ){
b2ManifoldPoint* mp = &manifold->points[i];
b2Vec2 nImpulse = mp->normalImpulse * normal;
b2Vec2 tImpulse = mp->tangentImpulse * tangent(normal);
std::cout << nImpulse.x << ':' << nImpulse.y << ' ';
std::cout << tImpulse.x << ':' << tImpulse.y << '\n';
body->ApplyLinearImpulse( nImpulse, mp->localPoint );
body->ApplyLinearImpulse( tImpulse, mp->localPoint );
}
}
b2Manifold* manifold = contact->GetManifold();
b2Vec2 normal = manifold->localNormal;
int count = manifold->pointCount;
for( int i=0; i < count; i++ ){
b2ManifoldPoint* mp = &manifold->points[i];
b2Vec2 nImpulse = mp->normalImpulse * normal;
b2Vec2 tImpulse = mp->tangentImpulse * tangent(normal);
std::cout << nImpulse.x << ':' << nImpulse.y << ' ';
std::cout << tImpulse.x << ':' << tImpulse.y << '\n';
body->ApplyLinearImpulse( nImpulse, mp->localPoint );
body->ApplyLinearImpulse( tImpulse, mp->localPoint );
}
}
Am I close? Way off?