AttachBodiesWithRevoluteJoint() public static méthode

Attaches the bodies with revolute joints.
public static AttachBodiesWithRevoluteJoint ( World world, List bodies, Vector2 localAnchorA, Vector2 localAnchorB, bool connectFirstAndLast, bool collideConnected ) : void
world FarseerPhysics.Dynamics.World The world.
bodies List The bodies.
localAnchorA Vector2 The local anchor A.
localAnchorB Vector2 The local anchor B.
connectFirstAndLast bool if set to true [connect first and last].
collideConnected bool if set to true [collide connected].
Résultat void
Exemple #1
0
        /// <summary>
        /// Creates a chain.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="linkWidth">The width.</param>
        /// <param name="linkHeight">The height.</param>
        /// <param name="fixStart">if set to <c>true</c> [fix start].</param>
        /// <param name="fixEnd">if set to <c>true</c> [fix end].</param>
        /// <param name="numberOfLinks">The number of links.</param>
        /// <param name="linkDensity">The link density.</param>
        /// <returns></returns>
        public static Path CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, bool fixStart, bool fixEnd, int numberOfLinks, float linkDensity)
        {
            // Chain start / end
            Path path = new Path();

            path.Add(start);
            path.Add(end);

            // A single chainlink
            PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight));

            // Use PathManager to create all the chainlinks based on the chainlink created before.
            List <Body> chainLinks = PathManager.EvenlyDistibuteShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks, linkDensity);

            if (fixStart)
            {
                // Fix the first chainlink to the world
                JointFactory.CreateFixedRevoluteJoint(world, chainLinks[0], new Vector2(0, -(linkHeight / 2)), chainLinks[0].Position);
            }

            if (fixEnd)
            {
                // Fix the last chainlink to the world
                JointFactory.CreateFixedRevoluteJoint(world, chainLinks[chainLinks.Count - 1], new Vector2(0, (linkHeight / 2)), chainLinks[chainLinks.Count - 1].Position);
            }

            // Attach all the chainlinks together with a revolute joint
            PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight), new Vector2(0, linkHeight),
                                                      false, false);

            return(path);
        }
        /// <summary>
        /// Creates the chain.
        /// </summary>
        /// <returns>The chain.</returns>
        /// <param name="world">World.</param>
        /// <param name="start">Start.</param>
        /// <param name="end">End.</param>
        /// <param name="linkWidth">Link width.</param>
        /// <param name="linkHeight">Link height.</param>
        /// <param name="numberOfLinks">Number of links.</param>
        /// <param name="linkDensity">Link density.</param>
        /// <param name="attachRopeJoint">Creates a rope joint between start and end. This enforces the length of the rope. Said in another way: it makes the rope less bouncy.</param>
        /// <param name="fixStart">If set to <c>true</c> fix start.</param>
        /// <param name="fixEnd">If set to <c>true</c> fix end.</param>
        public static List <Body> CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight,
                                              int numberOfLinks, float linkDensity, bool attachRopeJoint,
                                              bool fixStart = false, bool fixEnd = false)
        {
            Debug.Assert(numberOfLinks >= 2);

            // Chain start / end
            Path path = new Path();

            path.Add(start);
            path.Add(end);

            // A single chainlink
            PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight), linkDensity);

            // Use PathManager to create all the chainlinks based on the chainlink created before.
            List <Body> chainLinks =
                PathManager.EvenlyDistributeShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks);

            if (fixStart)
            {
                // Fix the first chainlink to the world
                Body axle = BodyFactory.CreateCircle(world, 0.1f, 1, chainLinks[0].Position);
                JointFactory.CreateRevoluteJoint(world, chainLinks[0], axle, new Vector2(0, -(linkHeight / 2)),
                                                 Vector2.Zero);
            }

            if (fixEnd)
            {
                // Fix the last chainlink to the world
                int  lastIndex = chainLinks.Count - 1;
                Body axle      = BodyFactory.CreateCircle(world, 0.1f, 1, chainLinks[lastIndex].Position);
                JointFactory.CreateRevoluteJoint(world, chainLinks[lastIndex], axle, new Vector2(0, -(linkHeight / 2)),
                                                 Vector2.Zero);
            }

            // Attach all the chainlinks together with a revolute joint
            PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight),
                                                      new Vector2(0, linkHeight), false, false);

            if (attachRopeJoint)
            {
                JointFactory.CreateRopeJoint(world, chainLinks[0], chainLinks[chainLinks.Count - 1], Vector2.Zero,
                                             Vector2.Zero);
            }

            return(chainLinks);
        }
Exemple #3
0
        /// <summary>
        /// Creates a chain.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="linkWidth">The width.</param>
        /// <param name="linkHeight">The height.</param>
        /// <param name="numberOfLinks">The number of links.</param>
        /// <param name="linkDensity">The link density.</param>
        /// <returns></returns>
        public static Path CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, int numberOfLinks, float linkDensity)
        {
            //Chain start / end
            Path path = new Path();

            path.Add(start);
            path.Add(end);

            //A single chainlink
            PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight), linkDensity);

            //Use PathManager to create all the chainlinks based on the chainlink created before.
            List <Body> chainLinks = PathManager.EvenlyDistributeShapesAlongPath(world, path, shape, BodyType.Dynamic,
                                                                                 numberOfLinks);

            //Attach all the chainlinks together with a revolute joint
            PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight),
                                                      new Vector2(0, linkHeight),
                                                      false, false);

            return(path);
        }