Exemple #1
0
        private LineJointTest()
        {
            Body ground;
            {
                PolygonShape shape = new PolygonShape(PolygonTools.CreateEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)), 0);


                ground = World.CreateBody();
                ground.CreateFixture(shape);
            }

            {
                PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 2.0f), 1);

                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(0.0f, 7.0f);

                body.CreateFixture(shape);

                Vector2 axis = new Vector2(2.0f, 1.0f);
                axis.Normalize();
                //LineJoint jd = new LineJoint(ground, body, new Vector2(0.0f, 8.5f),new Vector2(1.0f, 2.5f), axis);
                FixedLineJoint jd = new FixedLineJoint(body, /*ground, */ new Vector2(1.0f, 1.5f), new Vector2(10.0f, 8.5f), axis);
                jd.MotorSpeed    = 100.0f;
                jd.MaxMotorForce = 100.0f;
                jd.MotorEnabled  = false;
                jd.LowerLimit    = -4.0f;
                jd.UpperLimit    = 4.0f;
                jd.EnableLimit   = true;
                World.CreateJoint(jd);
                _jd = jd;
            }
        }
        public static Fixture CreateEdge(World world, Vector2 start, Vector2 end, float density)
        {
            Body         body           = BodyFactory.CreateBody(world);
            Vertices     edgeVertices   = PolygonTools.CreateEdge(start, end);
            PolygonShape rectangleShape = new PolygonShape(edgeVertices);

            return(body.CreateFixture(rectangleShape, density));
        }
Exemple #3
0
        public ConvexDecompositionTest()
        {
            {
                Body ground = World.CreateBody();

                Vertices     edge  = PolygonTools.CreateEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                PolygonShape shape = new PolygonShape(edge, 0);
                ground.CreateFixture(shape);
            }
        }
        // Contributed by Matthew Bettcher

        /// <summary>
        /// Convert a path into a set of edges and attaches them to the specified body.
        /// Note: use only for static edges.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="body">The body.</param>
        /// <param name="subdivisions">The subdivisions.</param>
        public static void ConvertPathToEdges(Path path, Body body, int subdivisions)
        {
            List <Vector2> verts = path.GetVertices(subdivisions);

            for (int i = 1; i < verts.Count; i++)
            {
                body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[i], verts[i - 1])), 0);
            }

            if (path.Closed)
            {
                body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[verts.Count - 1], verts[0])), 0);
            }
        }
Exemple #5
0
        private BuoyancyTest()
        {
            //Make a box
            //Bottom
            Body         ground = BodyFactory.CreateBody(World);
            Vertices     edge   = PolygonTools.CreateEdge(new Vector2(0.0f, 0.0f), new Vector2(40.0f, 0.0f));
            PolygonShape shape  = new PolygonShape(edge);

            ground.CreateFixture(shape);

            //Left side
            shape.Set(PolygonTools.CreateEdge(new Vector2(0.0f, 0.0f), new Vector2(00.0f, 15.0f)));
            ground.CreateFixture(shape);

            //Right side
            shape.Set(PolygonTools.CreateEdge(new Vector2(40.0f, 0.0f), new Vector2(40.0f, 15.0f)));
            ground.CreateFixture(shape);

            //Buoyancy controller
            _aabbContainer = new AABBFluidContainer(new Vector2(0, 0), 40, 10);
            _waveContainer = new WaveContainer(new Vector2(0, 0), 40, 10);
            _waveContainer.WaveGeneratorStep = 0;

            FluidDragController buoyancyController = new FluidDragController(_waveContainer, 4f, 0.98f, 0.2f,
                                                                             World.Gravity);

            buoyancyController.Entry += EntryEventHandler;

            Vector2 offset = new Vector2(5, 0);

            //Bunch of balls
            for (int i = 0; i < 4; i++)
            {
                Fixture fixture = FixtureFactory.CreateCircle(World, 1, 1, new Vector2(15, 1) + offset * i);
                fixture.Body.BodyType = BodyType.Dynamic;
                buoyancyController.AddGeom(fixture);
            }

            World.Add(buoyancyController);
        }
 /// <summary>
 /// Set this as a single edge.
 /// </summary>
 /// <param name="start">The start.</param>
 /// <param name="end">The end.</param>
 public void SetAsEdge(Vector2 start, Vector2 end)
 {
     Set(PolygonTools.CreateEdge(start, end));
 }