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 Pulleys()
		{
			Body ground = null;
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f);

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -10.0f);
				ground = _world.CreateBody(bd);
				ground.CreateShape(sd);
			}

			{
				float a = 2.0f;
				float b = 4.0f;
				float y = 16.0f;
				float L = 12.0f;

				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(a, b);
				sd.Density = 5.0f;

				BodyDef bd = new BodyDef();

				bd.Position.Set(-10.0f, y);
				Body body1 = _world.CreateBody(bd);
				body1.CreateShape(sd);
				body1.SetMassFromShapes();

				bd.Position.Set(10.0f, y);
				Body body2 = _world.CreateBody(bd);
				body2.CreateShape(sd);
				body2.SetMassFromShapes();

				PulleyJointDef pulleyDef = new PulleyJointDef();
				Vec2 anchor1 = new Vec2(-10.0f, y + b);
				Vec2 anchor2 = new Vec2(10.0f, y + b);
				Vec2 groundAnchor1 = new Vec2(-10.0f, y + b + L);
				Vec2 groundAnchor2 = new Vec2(10.0f, y + b + L);
				pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0f);

				_joint1 = (PulleyJoint)_world.CreateJoint(pulleyDef);
			}
		}
Example #4
0
        private void DrawJoint(Joint joint)
        {
            Body      b1  = joint.GetBody1();
            Body      b2  = joint.GetBody2();
            Transform xf1 = b1.GetTransform();
            Transform xf2 = b2.GetTransform();
            Vec2      x1  = xf1.Position;
            Vec2      x2  = xf2.Position;
            Vec2      p1  = joint.Anchor1;
            Vec2      p2  = joint.Anchor2;

            Color color = new Color(0.5f, 0.8f, 0.8f);

            switch (joint.GetType())
            {
            case JointType.DistanceJoint:
                _debugDraw.DrawSegment(p1, p2, color);
                break;

            case JointType.PulleyJoint:
            {
                PulleyJoint pulley = (PulleyJoint)joint;
                Vec2        s1     = pulley.GroundAnchor1;
                Vec2        s2     = pulley.GroundAnchor2;
                _debugDraw.DrawSegment(s1, p1, color);
                _debugDraw.DrawSegment(s2, p2, color);
                _debugDraw.DrawSegment(s1, s2, color);
            }
            break;

            case JointType.MouseJoint:
                // don't draw this
                break;

            default:
                _debugDraw.DrawSegment(x1, p1, color);
                _debugDraw.DrawSegment(p1, p2, color);
                _debugDraw.DrawSegment(x2, p2, color);
                break;
            }
        }
Example #5
0
        public Pulleys()
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = _world.CreateBody(bd);

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

            {
                float a = 2.0f;
                float b = 4.0f;
                float y = 16.0f;
                float L = 12.0f;

                PolygonShape shape = new PolygonShape();
                shape.SetAsBox(a, b);

                BodyDef bd = new BodyDef();

                bd.Position.Set(-10.0f, y);
                Body body1 = _world.CreateBody(bd);
                body1.CreateFixture(shape, 5.0f);

                bd.Position.Set(10.0f, y);
                Body body2 = _world.CreateBody(bd);
                body2.CreateFixture(shape, 5.0f);

                PulleyJointDef pulleyDef = new PulleyJointDef();
                Vec2 anchor1 = new Vec2(-10.0f, y + b);
                Vec2 anchor2 = new Vec2(10.0f, y + b);
                Vec2 groundAnchor1 = new Vec2(-10.0f, y + b + L);
                Vec2 groundAnchor2 = new Vec2(10.0f, y + b + L);
                pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0f);

                _joint1 = (PulleyJoint)_world.CreateJoint(pulleyDef);
            }
        }
Example #6
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;
 }