I have been introducing myself to the box2d world via flashyTodd's famous tutorials. Although the tutorials use version 2.0, I have found that updating the examples to work with 2.1 is not a particularly hard job. However, one fix that I have had to make feels too...inefficient, I guess.
The problem came about when I was going through tutorial #49 (http://www.kerp.net/box2d/displaylesson.php?chapter=2&lesson=49). The trouble I was having was finding out how to reference the normal of two objects colliding when working within the b2Contact class.
In the tutorials, Todd uses the following line to find the normal (he is able to work within the b2ContactPoint class):
The only fix I could come up with is the following:
My fix just finds the vector between the center of mass of the two objects.
Basically, I just feel like there is a neater way of getting normals in 2.1, but my noob status is preventing me from finding it.
Thanks,
Mike
The problem came about when I was going through tutorial #49 (http://www.kerp.net/box2d/displaylesson.php?chapter=2&lesson=49). The trouble I was having was finding out how to reference the normal of two objects colliding when working within the b2Contact class.
In the tutorials, Todd uses the following line to find the normal (he is able to work within the b2ContactPoint class):
Code:
override public function Add(point:b2ContactPoint):void {
PegActor(point.shape1().GetBody().GetUserData()).setCollisionInfo(
point.normal
);
}
PegActor(point.shape1().GetBody().GetUserData()).setCollisionInfo(
point.normal
);
}
The only fix I could come up with is the following:
Code:
override public function BeginContact(contact:b2Contact):void
{
PegActor(contact.GetFixtureA().GetBody().GetUserData()).setCollisionInfo(
new b2Vec2(contact.GetFixtureB().GetBody().GetWorldCenter().x -
contact.GetFixtureA().GetBody().GetWorldCenter().x,
contact.GetFixtureB().GetBody().GetWorldCenter().y -
contact.GetFixtureA().GetBody().GetWorldCenter().y
)
);
}
{
PegActor(contact.GetFixtureA().GetBody().GetUserData()).setCollisionInfo(
new b2Vec2(contact.GetFixtureB().GetBody().GetWorldCenter().x -
contact.GetFixtureA().GetBody().GetWorldCenter().x,
contact.GetFixtureB().GetBody().GetWorldCenter().y -
contact.GetFixtureA().GetBody().GetWorldCenter().y
)
);
}
My fix just finds the vector between the center of mass of the two objects.
Basically, I just feel like there is a neater way of getting normals in 2.1, but my noob status is preventing me from finding it.
Thanks,
Mike