A gear joint is used to connect two joints together. Either joint can be a revolute or prismatic joint. You specify a gear ratio to bind the motions together: coordinate1 + ratio * coordinate2 = constant The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length. @warning The revolute and prismatic joints must be attached to fixed bodies (which must be body1 on those joints).
Inheritance: Joint
Example #1
0
        internal static Joint Create(JointDef def)
        {
            Joint result = null;

            switch (def.Type)
            {
            case JointType.RevoluteJoint:
            {
                result = new RevoluteJoint((RevoluteJointDef)def);
                break;
            }

            case JointType.PrismaticJoint:
            {
                result = new PrismaticJoint((PrismaticJointDef)def);
                break;
            }

            case JointType.DistanceJoint:
            {
                result = new DistanceJoint((DistanceJointDef)def);
                break;
            }

            case JointType.PulleyJoint:
            {
                result = new PulleyJoint((PulleyJointDef)def);
                break;
            }

            case JointType.MouseJoint:
            {
                result = new MouseJoint((MouseJointDef)def);
                break;
            }

            case JointType.GearJoint:
            {
                result = new GearJoint((GearJointDef)def);
                break;
            }

            case JointType.LineJoint:
            {
                result = new LineJoint((LineJointDef)def);
                break;
            }

            default:
            {
                Box2DXDebug.Assert(false);
                break;
            }
            }
            return(result);
        }
Example #2
0
        internal static Joint Create(JointDef def)
        {
            Joint joint = null;

            switch (def.Type)
            {
            case JointType.DistanceJoint:
            {
                joint = new DistanceJoint((DistanceJointDef)def);
            }
            break;

            case JointType.MouseJoint:
            {
                joint = new MouseJoint((MouseJointDef)def);
            }
            break;

            case JointType.PrismaticJoint:
            {
                joint = new PrismaticJoint((PrismaticJointDef)def);
            }
            break;

            case JointType.RevoluteJoint:
            {
                joint = new RevoluteJoint((RevoluteJointDef)def);
            }
            break;

            case JointType.PulleyJoint:
            {
                joint = new PulleyJoint((PulleyJointDef)def);
            }
            break;

            case JointType.GearJoint:
            {
                joint = new GearJoint((GearJointDef)def);
            }
            break;

            default:
                Box2DXDebug.Assert(false);
                break;
            }

            return(joint);
        }
Example #3
0
        public Gears()
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = _world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f));
                ground.CreateFixture(shape, 0);
            }

            {
                CircleShape circle1 = new CircleShape();
                circle1._radius = 1.0f;

                CircleShape circle2 = new CircleShape();
                circle2._radius = 2.0f;

                PolygonShape box = new PolygonShape();
                box.SetAsBox(0.5f, 5.0f);

                BodyDef bd1 = new BodyDef();
                bd1.Position.Set(-3.0f, 12.0f);
                Body body1 = _world.CreateBody(bd1);
                body1.CreateFixture(circle1, 5.0f);

                RevoluteJointDef jd1 = new RevoluteJointDef();
                jd1.Body1 = ground;
                jd1.Body2 = body1;
                jd1.LocalAnchor1 = ground.GetLocalPoint(bd1.Position);
                jd1.LocalAnchor2 = body1.GetLocalPoint(bd1.Position);
                jd1.ReferenceAngle = body1.GetAngle() - ground.GetAngle();
                _joint1 = (RevoluteJoint)_world.CreateJoint(jd1);

                BodyDef bd2 = new BodyDef();
                bd2.Position.Set(0.0f, 12.0f);
                Body body2 = _world.CreateBody(bd2);
                body2.CreateFixture(circle2, 5.0f);

                RevoluteJointDef jd2 = new RevoluteJointDef();
                jd2.Initialize(ground, body2, bd2.Position);
                _joint2 = (RevoluteJoint)_world.CreateJoint(jd2);

                BodyDef bd3 = new BodyDef();
                bd3.Position.Set(2.5f, 12.0f);
                Body body3 = _world.CreateBody(bd3);
                body3.CreateFixture(box, 5.0f);

                PrismaticJointDef jd3 = new PrismaticJointDef();
                jd3.Initialize(ground, body3, bd3.Position, new Vec2(0.0f, 1.0f));
                jd3.LowerTranslation = -5.0f;
                jd3.UpperTranslation = 5.0f;
                jd3.EnableLimit = true;

                _joint3 = (PrismaticJoint)_world.CreateJoint(jd3);

                GearJointDef jd4 = new GearJointDef();
                jd4.Body1 = body1;
                jd4.Body2 = body2;
                jd4.Joint1 = _joint1;
                jd4.Joint2 = _joint2;
                jd4.Ratio = circle2._radius / circle1._radius;
                _joint4 = (GearJoint)_world.CreateJoint(jd4);

                GearJointDef jd5 = new GearJointDef();
                jd5.Body1 = body2;
                jd5.Body2 = body3;
                jd5.Joint1 = _joint2;
                jd5.Joint2 = _joint3;
                jd5.Ratio = -1.0f / circle2._radius;
                _joint5 = (GearJoint)_world.CreateJoint(jd5);
            }
        }
Example #4
0
 internal static Joint Create(JointDef def)
 {
     Joint result = null;
     switch (def.Type)
     {
         case JointType.RevoluteJoint:
         {
             result = new RevoluteJoint((RevoluteJointDef)def);
             break;
         }
         case JointType.PrismaticJoint:
         {
             result = new PrismaticJoint((PrismaticJointDef)def);
             break;
         }
         case JointType.DistanceJoint:
         {
             result = new DistanceJoint((DistanceJointDef)def);
             break;
         }
         case JointType.PulleyJoint:
         {
             result = new PulleyJoint((PulleyJointDef)def);
             break;
         }
         case JointType.MouseJoint:
         {
             result = new MouseJoint((MouseJointDef)def);
             break;
         }
         case JointType.GearJoint:
         {
             result = new GearJoint((GearJointDef)def);
             break;
         }
         case JointType.LineJoint:
         {
             result = new LineJoint((LineJointDef)def);
             break;
         }
         default:
         {
             Box2DXDebug.Assert(false);
             break;
         }
     }
     return result;
 }