If you want to create a sophisticated mechanical contraption you might want to use gears. In principle you can create gears in Box2D by using compound shapes to model gear teeth. This is not very efficient and might be tedious to author. You also have to be careful to line up the gears so the teeth mesh smoothly. Box2D has a simpler method of creating gears: the gear joint.

The gear joint can only connect revolute and/or prismatic joints.

Like the pulley ratio, you can specify a gear ratio. However, in this case the gear ratio can be negative. Also keep in mind that when one joint is a revolute joint (angular) and the other joint is prismatic (translation), and then the gear ratio will have units of length or one over length.

coordinate1 + ratio * coordinate2 == constant

Make sure the following codes are at the beginning.
var    b2Vec2 = Box2D.Common.Math.b2Vec2
,      b2BodyDef = Box2D.Dynamics.b2BodyDef
,      b2Body = Box2D.Dynamics.b2Body
,      b2FixtureDef = Box2D.Dynamics.b2FixtureDef
,      b2World = Box2D.Dynamics.b2World
,      b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape
,      b2CircleShape = Box2D.Collision.Shapes.b2CircleShape
,      b2MouseJointDef =  Box2D.Dynamics.Joints.b2MouseJointDef
,	   b2GearJointDef = Box2D.Dynamics.Joints.b2GearJointDef
,	   b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef
,      b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef
,	   b2WeldJointDef = Box2D.Dynamics.Joints.b2WeldJointDeff
,      b2DebugDraw = Box2D.Dynamics.b2DebugDraw
,      b2Fixture = Box2D.Dynamics.b2Fixture
,      b2AABB = Box2D.Collision.b2AABB;
Line 8, 9 and 10 should be present.

Gear Joint Definition

// Revolute Joint
var revoluteJointDef = new b2RevoluteJointDef();
revoluteJointDef.Initialize(world.GetGroundBody(), wheel, wheel.GetWorldCenter());  //ground must be the first body
revoluteJointDef.maxMotorTorque = 1100.0;
revoluteJointDef.motorSpeed = 3.0;
revoluteJointDef.enableMotor = true;
revoluteJoint = world.CreateJoint(revoluteJointDef);

// Prismatic Joint	
var worldAxis = new b2Vec2(0, 1);
var prismaticJointDef = new b2PrismaticJointDef();
prismaticJointDef.Initialize(world.GetGroundBody(), box, box.GetWorldCenter(), worldAxis);  //ground must be the first body
prismaticJointDef.lowerTranslation = -5.0;
prismaticJointDef.upperTranslation = 2.5;
prismaticJointDef.enableLimit = true;
prismaticJoint = world.CreateJoint(prismaticJointDef);
// Finally Gear Joint	 
var gearJointDef = new b2GearJointDef();
gearJointDef.joint1 = revoluteJoint;
gearJointDef.joint2 = prismaticJoint;
gearJointDef.bodyA = box;
gearJointDef.bodyB = wheel;
gearJointDef.ratio = 1;
gearJoint = world.CreateJoint(gearJointDef);
I have created a "Revolute Joint" between a Ground Body and wheel. Then a "Prismatic Joint" between a Ground Body and box. And finally "Gear Joint" between box and wheel using the two joints previously created. The definition for gear joint is quite simple so no need to explain.

The world provides a single static ground body with no collision shapes. You can use this to simplify the creation of joints and static shapes.


(Try playing with mouse)

By administrator at 10:55:44 PM 13 Comment(s)


5 versicherungen im paket
By 9TbWeL71ed on 12 Oct, 2016 at 03:23:46 PM
By HfAhEZcI on 13 Oct, 2016 at 09:34:01 AM
financieras asnef sin aval credito hipotecario ingles
By GEmAunDo6xTm on 26 Oct, 2016 at 12:41:56 PM
can i cancel a car insurance claim car insurance quotes hollard
By N2tpkFqWAe on 27 Oct, 2016 at 07:00:53 AM
takes points car insurance quotes been advances something NJ car insurance receive sex car insurance free quotes however two premiums encourage than purchasing discount car insurance benz
By u6bVPUjnW on 31 Oct, 2016 at 12:40:29 PMänger-prozente.html versicherung kfz anfänger
By pWNVpNzpexk on 5 Nov, 2016 at 02:27:26 AM ventajas y desventajas de prestamos familiares
By dvsXWW1ldD on 8 Nov, 2016 at 04:03:54 PMöse-kredite-für-studenten.html
By 26asQf8lu on 7 Jan, 2017 at 03:39:48 AM
dove acquistare cialis in italia Cialis verkossa sverige cialis gene sicuro Online
By PS5tHIZ1W on 12 Jan, 2017 at 07:18:52 PM
best car insurance in Westland MI car insurance quotes Chandler AZ
By bmQGuMvXz on 15 Jan, 2017 at 09:26:32 AMöses-unternehmen.htmlägypten.html kredit baufinanzierung hypothek oversluiten
By loV6htgoDC on 17 Jan, 2017 at 03:57:26 AM vergleich autoversicherung deutschland rechner gutschein autoversicherung berechnen
By ty0O39VFi on 3 Feb, 2017 at 07:58:11 AM
wii internet game hack play free
By lXLE1BlYV on 16 Feb, 2017 at 05:35:40 PM

Add a Comment

Please enter the email address.Invalid format. (Won't be Displayed)
Notify me of followup comments
Enter the displayed Code: captcha