Gear joint definition. This definition requires two existing revolute or prismatic joints (any combination will work). The provided joints must attach a dynamic body to a static body.
Inheritance: JointDef
Exemple #1
0
        public GearJoint(GearJointDef def)
            : base(def)
        {
            JointType type1 = def.Joint1.GetType();
            JointType type2 = def.Joint2.GetType();

            Box2DXDebug.Assert(type1 == JointType.RevoluteJoint || type1 == JointType.PrismaticJoint);
            Box2DXDebug.Assert(type2 == JointType.RevoluteJoint || type2 == JointType.PrismaticJoint);
            Box2DXDebug.Assert(def.Joint1.GetBody1().IsStatic());
            Box2DXDebug.Assert(def.Joint2.GetBody1().IsStatic());

            _revolute1  = null;
            _prismatic1 = null;
            _revolute2  = null;
            _prismatic2 = null;

            float coordinate1, coordinate2;

            _ground1 = def.Joint1.GetBody1();
            _body1   = def.Joint1.GetBody2();
            if (type1 == JointType.RevoluteJoint)
            {
                _revolute1     = (RevoluteJoint)def.Joint1;
                _groundAnchor1 = _revolute1._localAnchor1;
                _localAnchor1  = _revolute1._localAnchor2;
                coordinate1    = _revolute1.JointAngle;
            }
            else
            {
                _prismatic1    = (PrismaticJoint)def.Joint1;
                _groundAnchor1 = _prismatic1._localAnchor1;
                _localAnchor1  = _prismatic1._localAnchor2;
                coordinate1    = _prismatic1.JointTranslation;
            }

            _ground2 = def.Joint2.GetBody1();
            _body2   = def.Joint2.GetBody2();
            if (type2 == JointType.RevoluteJoint)
            {
                _revolute2     = (RevoluteJoint)def.Joint2;
                _groundAnchor2 = _revolute2._localAnchor1;
                _localAnchor2  = _revolute2._localAnchor2;
                coordinate2    = _revolute2.JointAngle;
            }
            else
            {
                _prismatic2    = (PrismaticJoint)def.Joint2;
                _groundAnchor2 = _prismatic2._localAnchor1;
                _localAnchor2  = _prismatic2._localAnchor2;
                coordinate2    = _prismatic2.JointTranslation;
            }

            _ratio = def.Ratio;

            _constant = coordinate1 + _ratio * coordinate2;

            _impulse = 0.0f;
        }
Exemple #2
0
        public GearJoint(GearJointDef def) : base(def)
        {
            JointType type  = def.Joint1.GetType();
            JointType type2 = def.Joint2.GetType();

            Box2DXDebug.Assert(type == JointType.RevoluteJoint || type == JointType.PrismaticJoint);
            Box2DXDebug.Assert(type2 == JointType.RevoluteJoint || type2 == JointType.PrismaticJoint);
            Box2DXDebug.Assert(def.Joint1.GetBody1().IsStatic());
            Box2DXDebug.Assert(def.Joint2.GetBody1().IsStatic());
            this._revolute1  = null;
            this._prismatic1 = null;
            this._revolute2  = null;
            this._prismatic2 = null;
            this._ground1    = def.Joint1.GetBody1();
            this._body1      = def.Joint1.GetBody2();
            float num;

            if (type == JointType.RevoluteJoint)
            {
                this._revolute1     = (RevoluteJoint)def.Joint1;
                this._groundAnchor1 = this._revolute1._localAnchor1;
                this._localAnchor1  = this._revolute1._localAnchor2;
                num = this._revolute1.JointAngle;
            }
            else
            {
                this._prismatic1    = (PrismaticJoint)def.Joint1;
                this._groundAnchor1 = this._prismatic1._localAnchor1;
                this._localAnchor1  = this._prismatic1._localAnchor2;
                num = this._prismatic1.JointTranslation;
            }
            this._ground2 = def.Joint2.GetBody1();
            this._body2   = def.Joint2.GetBody2();
            float num2;

            if (type2 == JointType.RevoluteJoint)
            {
                this._revolute2     = (RevoluteJoint)def.Joint2;
                this._groundAnchor2 = this._revolute2._localAnchor1;
                this._localAnchor2  = this._revolute2._localAnchor2;
                num2 = this._revolute2.JointAngle;
            }
            else
            {
                this._prismatic2    = (PrismaticJoint)def.Joint2;
                this._groundAnchor2 = this._prismatic2._localAnchor1;
                this._localAnchor2  = this._prismatic2._localAnchor2;
                num2 = this._prismatic2.JointTranslation;
            }
            this._ratio    = def.Ratio;
            this._constant = num + this._ratio * num2;
            this._impulse  = 0f;
        }
Exemple #3
0
 public GearJoint(GearJointDef def)
     : base(def)
 {
     JointType type = def.Joint1.GetType();
     JointType type2 = def.Joint2.GetType();
     Box2DXDebug.Assert(type == JointType.RevoluteJoint || type == JointType.PrismaticJoint);
     Box2DXDebug.Assert(type2 == JointType.RevoluteJoint || type2 == JointType.PrismaticJoint);
     Box2DXDebug.Assert(def.Joint1.GetBody1().IsStatic());
     Box2DXDebug.Assert(def.Joint2.GetBody1().IsStatic());
     this._revolute1 = null;
     this._prismatic1 = null;
     this._revolute2 = null;
     this._prismatic2 = null;
     this._ground1 = def.Joint1.GetBody1();
     this._body1 = def.Joint1.GetBody2();
     float num;
     if (type == JointType.RevoluteJoint)
     {
         this._revolute1 = (RevoluteJoint)def.Joint1;
         this._groundAnchor1 = this._revolute1._localAnchor1;
         this._localAnchor1 = this._revolute1._localAnchor2;
         num = this._revolute1.JointAngle;
     }
     else
     {
         this._prismatic1 = (PrismaticJoint)def.Joint1;
         this._groundAnchor1 = this._prismatic1._localAnchor1;
         this._localAnchor1 = this._prismatic1._localAnchor2;
         num = this._prismatic1.JointTranslation;
     }
     this._ground2 = def.Joint2.GetBody1();
     this._body2 = def.Joint2.GetBody2();
     float num2;
     if (type2 == JointType.RevoluteJoint)
     {
         this._revolute2 = (RevoluteJoint)def.Joint2;
         this._groundAnchor2 = this._revolute2._localAnchor1;
         this._localAnchor2 = this._revolute2._localAnchor2;
         num2 = this._revolute2.JointAngle;
     }
     else
     {
         this._prismatic2 = (PrismaticJoint)def.Joint2;
         this._groundAnchor2 = this._prismatic2._localAnchor1;
         this._localAnchor2 = this._prismatic2._localAnchor2;
         num2 = this._prismatic2.JointTranslation;
     }
     this._ratio = def.Ratio;
     this._constant = num + this._ratio * num2;
     this._impulse = 0f;
 }
Exemple #4
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);
            }
        }
Exemple #5
0
		public GearJoint(GearJointDef def)
			: base(def)
		{
			JointType type1 = def.Joint1.GetType();
			JointType type2 = def.Joint2.GetType();

			Box2DXDebug.Assert(type1 == JointType.RevoluteJoint || type1 == JointType.PrismaticJoint);
			Box2DXDebug.Assert(type2 == JointType.RevoluteJoint || type2 == JointType.PrismaticJoint);
			Box2DXDebug.Assert(def.Joint1.GetBody1().IsStatic());
			Box2DXDebug.Assert(def.Joint2.GetBody1().IsStatic());

			_revolute1 = null;
			_prismatic1 = null;
			_revolute2 = null;
			_prismatic2 = null;

			float coordinate1, coordinate2;

			_ground1 = def.Joint1.GetBody1();
			_body1 = def.Joint1.GetBody2();
			if (type1 == JointType.RevoluteJoint)
			{
				_revolute1 = (RevoluteJoint)def.Joint1;
				_groundAnchor1 = _revolute1._localAnchor1;
				_localAnchor1 = _revolute1._localAnchor2;
				coordinate1 = _revolute1.JointAngle;
			}
			else
			{
				_prismatic1 = (PrismaticJoint)def.Joint1;
				_groundAnchor1 = _prismatic1._localAnchor1;
				_localAnchor1 = _prismatic1._localAnchor2;
				coordinate1 = _prismatic1.JointTranslation;
			}

			_ground2 = def.Joint2.GetBody1();
			_body2 = def.Joint2.GetBody2();
			if (type2 == JointType.RevoluteJoint)
			{
				_revolute2 = (RevoluteJoint)def.Joint2;
				_groundAnchor2 = _revolute2._localAnchor1;
				_localAnchor2 = _revolute2._localAnchor2;
				coordinate2 = _revolute2.JointAngle;
			}
			else
			{
				_prismatic2 = (PrismaticJoint)def.Joint2;
				_groundAnchor2 = _prismatic2._localAnchor1;
				_localAnchor2 = _prismatic2._localAnchor2;
				coordinate2 = _prismatic2.JointTranslation;
			}

			_ratio = def.Ratio;

			_constant = coordinate1 + _ratio * coordinate2;

			_impulse = 0.0f;
		}