Revolute Joint
Revolute joint is a useful joint in box2d that allows 2 bodies to be pinned together at a point without restricting rotation. Lets take an example
The joint can be made between 2 dynamic bodies or between a static and dynamic body. The pendulum on left is a static circle joined to dynamic rectangle. Whereas the cart with 2 wheels is made of dynamic bodies.
The joint can even be outside the body. The square in the middle is joined to the ground body, but the anchor point of the ground is outside the shape limits of the ground.
Apart from pinning the bodies together, the revolute joint also allows for a constant rotation of either of the bodies. The fan on the right is rotating non stop.
Revolute joint can be created like this
//create revolute joint between a and b
var joint_def = new b2RevoluteJointDef();
joint_def.bodyA = a;
joint_def.bodyB = b;
//connect the centers - center in local coordinate - relative to body is 0,0
joint_def.localAnchorA = new b2Vec2(-2, 0);
joint_def.localAnchorB = new b2Vec2(0, 0);
//add the joint to the world
world.CreateJoint(joint_def);
Code
/**
RevoluteJoint in box2d in javascript
Silver Moon (m00n.silv3r@gmail.com)
*/
var b2Vec2 = Box2D.Common.Math.b2Vec2
, b2AABB = Box2D.Collision.b2AABB
, b2BodyDef = Box2D.Dynamics.b2BodyDef
, b2Body = Box2D.Dynamics.b2Body
, b2FixtureDef = Box2D.Dynamics.b2FixtureDef
, b2Fixture = Box2D.Dynamics.b2Fixture
, b2World = Box2D.Dynamics.b2World
, b2PolygonShape...
Read full post here
Revolute joint in box2d in javascript
Revolute joint is a useful joint in box2d that allows 2 bodies to be pinned together at a point without restricting rotation. Lets take an example
The joint can be made between 2 dynamic bodies or between a static and dynamic body. The pendulum on left is a static circle joined to dynamic rectangle. Whereas the cart with 2 wheels is made of dynamic bodies.
The joint can even be outside the body. The square in the middle is joined to the ground body, but the anchor point of the ground is outside the shape limits of the ground.
Apart from pinning the bodies together, the revolute joint also allows for a constant rotation of either of the bodies. The fan on the right is rotating non stop.
Revolute joint can be created like this
//create revolute joint between a and b
var joint_def = new b2RevoluteJointDef();
joint_def.bodyA = a;
joint_def.bodyB = b;
//connect the centers - center in local coordinate - relative to body is 0,0
joint_def.localAnchorA = new b2Vec2(-2, 0);
joint_def.localAnchorB = new b2Vec2(0, 0);
//add the joint to the world
world.CreateJoint(joint_def);
Code
/**
RevoluteJoint in box2d in javascript
Silver Moon (m00n.silv3r@gmail.com)
*/
var b2Vec2 = Box2D.Common.Math.b2Vec2
, b2AABB = Box2D.Collision.b2AABB
, b2BodyDef = Box2D.Dynamics.b2BodyDef
, b2Body = Box2D.Dynamics.b2Body
, b2FixtureDef = Box2D.Dynamics.b2FixtureDef
, b2Fixture = Box2D.Dynamics.b2Fixture
, b2World = Box2D.Dynamics.b2World
, b2PolygonShape...
Read full post here
Revolute joint in box2d in javascript