Example #1
0
        /// <summary>
        ///     Creates an edge chain with the specified parameters. A chain consists in fact of multiple edge fixtures with
        ///     neighborhood information, which avoid collisions with inner vertices. Note that is not actually Box2D's
        ///     implementation of a chain, but simply a factory for creating a single edge fixture per chain link.
        /// </summary>
        /// <param name="manager">The manager to create the object in.</param>
        /// <param name="vertices">The vertices relative to the body's local origin.</param>
        /// <param name="worldAngle">The initial world angle of the body.</param>
        /// <param name="friction">The friction of the fixture.</param>
        /// <param name="restitution">The restitution of the fixture.</param>
        /// <param name="isSensor">
        ///     if set to <c>true</c> the created fixture is marked as a sensor (i.e. it will fire collision events but the
        ///     collision will not be handled by the solver).
        /// </param>
        /// <param name="collisionCategory">The collision groups for the fixture.</param>
        /// <param name="collisionMask">The collision groups to collide with.</param>
        /// <returns>A proxy object that may be used to interact with the created chain.</returns>
        public static Chain AddChain(
            this IManager manager,
            IList <LocalPoint> vertices,
            float worldAngle       = 0,
            float friction         = 0.2f,
            float restitution      = 0,
            bool isSensor          = false,
            uint collisionCategory = 1,
            uint collisionMask     = 0xFFFFFFFF)
        {
            FixtureFactory.ValidateVertices(vertices, 2);

            var body = manager.AddBody(WorldPoint.Zero, worldAngle);

            return(manager.AttachChainUnchecked(body, vertices, friction, restitution, isSensor, collisionCategory, collisionMask));
        }
Example #2
0
        /// <summary>
        ///     Creates an edge loop with the specified parameters. A loop consists in fact of multiple edge fixtures with
        ///     neighborhood information, which avoid collisions with inner vertices. Note that is not actually Box2D's
        ///     implementation of a chain, but simply a factory for creating a single edge fixture per chain link.
        /// </summary>
        /// <param name="manager">The manager to create the object in.</param>
        /// <param name="vertices">The vertices relative to the body's local origin.</param>
        /// <param name="worldPosition">The initial world position of the body.</param>
        /// <param name="worldAngle">The initial world angle of the body.</param>
        /// <param name="friction">The friction of the fixture.</param>
        /// <param name="restitution">The restitution of the fixture.</param>
        /// <param name="isSensor">
        ///     if set to <c>true</c> the created fixture is marked as a sensor (i.e. it will fire collision events but the
        ///     collision will not be handled by the solver).
        /// </param>
        /// <param name="collisionCategory">The collision groups for the fixture.</param>
        /// <param name="collisionMask">The collision groups to collide with.</param>
        /// <returns>The created body.</returns>
        public static Body AddLoop(
            this IManager manager,
            IList <LocalPoint> vertices,
            WorldPoint worldPosition,
            float worldAngle       = 0,
            float friction         = 0.2f,
            float restitution      = 0,
            bool isSensor          = false,
            uint collisionCategory = 1,
            uint collisionMask     = 0xFFFFFFFF)
        {
            FixtureFactory.ValidateVertices(vertices, 3);

            var body = manager.AddBody(worldPosition, worldAngle);

            manager.AttachLoopUnchecked(body, vertices, friction, restitution, isSensor, collisionCategory, collisionMask);

            return(body);
        }