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 = ant 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
        public static GearJoint CreateGearJoint(World world, Body bodyA, Body bodyB, Joint jointA, Joint jointB, float ratio)
        {
            GearJoint gearJoint = new GearJoint(bodyA, bodyB, jointA, jointB, ratio);

            world.Add(gearJoint);
            return(gearJoint);
        }
Example #2
0
        private GearsTest()
        {
            {
                // First circle
                CircleShape circle1 = new CircleShape(1.0f, 5);
                Body body1 = BodyFactory.CreateBody(World);
                body1.BodyType = BodyType.Dynamic;
                body1.Position = new Vector2(-3.0f, 12.0f);
                body1.CreateFixture(circle1);

                // Second circle
                CircleShape circle2 = new CircleShape(2.0f, 5);
                Body body2 = BodyFactory.CreateBody(World);
                body2.BodyType = BodyType.Dynamic;
                body2.Position = new Vector2(0.0f, 12.0f);
                body2.CreateFixture(circle2);

                // Rectangle
                Vertices box = PolygonTools.CreateRectangle(0.5f, 5.0f);
                PolygonShape polygonBox = new PolygonShape(box, 5);
                Body body3 = BodyFactory.CreateBody(World);
                body3.BodyType = BodyType.Dynamic;
                body3.Position = new Vector2(2.5f, 12.0f);
                body3.CreateFixture(polygonBox);

                // Fix first circle
                _joint1 = new FixedRevoluteJoint(body1, Vector2.Zero, body1.Position);
                World.AddJoint(_joint1);

                // Fix second circle
                _joint2 = new FixedRevoluteJoint(body2, Vector2.Zero, body2.Position);
                World.AddJoint(_joint2);

                // Fix rectangle
                _joint3 = new FixedPrismaticJoint(body3, body3.Position, new Vector2(0.0f, 1.0f));
                _joint3.LowerLimit = -5.0f;
                _joint3.UpperLimit = 5.0f;
                _joint3.LimitEnabled = true;
                World.AddJoint(_joint3);

                // Attach first and second circle together with a gear joint
                _joint4 = new GearJoint(_joint1, _joint2, circle2.Radius / circle1.Radius);
                World.AddJoint(_joint4);

                // Attach second and rectangle together with a gear joint
                _joint5 = new GearJoint(_joint2, _joint3, -1.0f / circle2.Radius);
                World.AddJoint(_joint5);
            }
        }
Example #3
0
		public override Joint createJoint()
		{
			var joint = new GearJoint( bodyA, bodyB, ownerJoint, otherJoint, ratio );
			joint.collideConnected = collideConnected;
			return joint;
		}
 public static GearJoint CreateGearJoint(World world, Body bodyA, Body bodyB, Joint jointA, Joint jointB, float ratio)
 {
     GearJoint gearJoint = new GearJoint(bodyA, bodyB, jointA, jointB, ratio);
     world.AddJoint(gearJoint);
     return gearJoint;
 }
Example #5
0
        private GearsTest()
        {
            Body ground = BodyFactory.CreateEdge(World, new Vector2(50.0f, 0.0f), new Vector2(-50.0f, 0.0f));

            {
                CircleShape circle1 = new CircleShape(1.0f, 5f);

                PolygonShape box = new PolygonShape(5f);
                box.Vertices = PolygonTools.CreateRectangle(0.5f, 5.0f);

                CircleShape circle2 = new CircleShape(2.0f, 5f);

                Body body1 = BodyFactory.CreateBody(World, new Vector2(10.0f, 9.0f));
                body1.CreateFixture(circle1);

                Body body2 = BodyFactory.CreateBody(World, new Vector2(10.0f, 8.0f));
                body2.BodyType = BodyType.Dynamic;
                body2.CreateFixture(box);

                Body body3 = BodyFactory.CreateBody(World, new Vector2(10.0f, 6.0f));
                body3.BodyType = BodyType.Dynamic;
                body3.CreateFixture(circle2);

                RevoluteJoint joint1 = new RevoluteJoint(body2, body1, body1.Position, true);
                World.AddJoint(joint1);

                RevoluteJoint joint2 = new RevoluteJoint(body2, body3, body3.Position, true);
                World.AddJoint(joint2);

                GearJoint joint4 = new GearJoint(joint1, joint2, circle2.Radius / circle1.Radius);
                joint4.BodyA = body1;
                joint4.BodyB = body3;
                World.AddJoint(joint4);
            }

            {
                CircleShape circle1 = new CircleShape(1.0f, 5.0f);

                CircleShape circle2 = new CircleShape(2.0f, 5.0f);

                PolygonShape box = new PolygonShape(5f);
                box.Vertices = PolygonTools.CreateRectangle(0.5f, 5.0f);

                Body body1 = BodyFactory.CreateBody(World, new Vector2(-3.0f, 12.0f));
                body1.BodyType = BodyType.Dynamic;
                body1.CreateFixture(circle1);

                _joint1 = new RevoluteJoint(ground, body1, body1.Position, true);
                _joint1.ReferenceAngle = body1.Rotation - ground.Rotation;
                World.AddJoint(_joint1);

                Body body2 = BodyFactory.CreateBody(World, new Vector2(0.0f, 12.0f));
                body2.BodyType = BodyType.Dynamic;
                body2.CreateFixture(circle2);

                _joint2 = new RevoluteJoint(ground, body2, body2.Position, true);
                World.AddJoint(_joint2);

                Body body3 = BodyFactory.CreateBody(World, new Vector2(2.5f, 12.0f));
                body3.BodyType = BodyType.Dynamic;
                body3.CreateFixture(box);

                _joint3 = new PrismaticJoint(ground, body3, body3.Position, new Vector2(0.0f, 1.0f));
                _joint3.LowerLimit = -5.0f;
                _joint3.UpperLimit = 5.0f;
                _joint3.LimitEnabled = true;

                World.AddJoint(_joint3);

                _joint4 = new GearJoint(_joint1, _joint2, circle2.Radius / circle1.Radius);
                _joint4.BodyA = body1;
                _joint4.BodyB = body2;
                World.AddJoint(_joint4);

                _joint5 = new GearJoint(_joint2, _joint3, -1.0f / circle2.Radius);
                _joint5.BodyA = body2;
                _joint5.BodyB = body3;
                World.AddJoint(_joint5);
            }
        }
Example #6
0
        //public static FixedFrictionJoint CreateFixedFrictionJoint(World world, Body body, Vector2 bodyAnchor)
        //{
        //    FixedFrictionJoint frictionJoint = new FixedFrictionJoint(body, bodyAnchor);
        //    world.AddJoint(frictionJoint);
        //    return frictionJoint;
        //}

        #endregion

        #region Gear Joint

        public static GearJoint CreateGearJoint(World world, FarseerJoint jointA, FarseerJoint jointB, float ratio)
        {
            GearJoint gearJoint = new GearJoint(jointA, jointB, ratio);
            world.AddJoint(gearJoint);
            return gearJoint;
        }