Quantcast
Channel: BinaryTides » Box2d
Viewing all articles
Browse latest Browse all 8

Distance joint in box2d in javascript

$
0
0
Distance
In the previous post on mouse joints we learned how to interact with box2d objects using the mouse. Now its time to take a look at another joint in box2d, the distance joint. Distance joint connects 2 bodies maintaining a fixed distance between them, its like metal wire connecting the 2 bodies, such that the wire would neither expand nor shrink, but allow the bodies to rotate about the point of joint.
Lets take a look at the distance joint.

See the circle and rectangle connected with the blue wire. Now thats supposed to be invisible, its drawn here just for the sake of indicating where the joint is. In a real application it would be replaced by appropriate graphics.
Joint of that kind can be used to make something like a pendulum. Ofcourse additional force would be needed to keep a body moving non-stop.
Source
The source is mostly from the mouse joint example, except that it adds an extra joint element.

/**
Distance joint demo of 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
, b2MassData = Box2D.Collision.Shapes.b2MassData
, b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape
, b2CircleShape = Box2D.Collision.Shapes.b2CircleShape
, b2DebugDraw = Box2D.Dynamics.b2DebugDraw
, b2MouseJointDef...

Read full post here
Distance joint in box2d in javascript


Viewing all articles
Browse latest Browse all 8

Trending Articles