示例#1
0
        /// <summary>
        /// Creates a rope.
        /// </summary>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="mass">The mass.</param>
        /// <param name="pinStart">if set to <c>true</c> [pin start].</param>
        /// <param name="pinEnd">if set to <c>true</c> [pin end].</param>
        /// <param name="type">The joint/spring type.</param>
        /// <returns></returns>
        public Path CreateRope(Vector2 start, Vector2 end, float width, float height, float mass, bool pinStart,
                               bool pinEnd, LinkType type)
        {
            Path path = new Path(width, height, mass, false); // create the path
            path.Add(start); // add starting point
            path.Add(Path.FindMidpoint(start, end));
            // add midpoint of line (must have this because my code needs at least 3 control points)
            path.Add(end); // add end point

            path.Update(); // call update to create all the bodies

            path.LinkBodies(type, Min, Max, SpringConstant, DampingConstant, SpringRestLengthFactor); // link bodies together

            if (pinStart)
                path.Add(JointFactory.Instance.CreateFixedRevoluteJoint(path.Bodies[0], start));
            if (pinEnd)
                path.Add(JointFactory.Instance.CreateFixedRevoluteJoint(path.Bodies[path.Bodies.Count - 1],
                                                                        path.ControlPoints[2]));

            foreach (Joint j in path.Joints)      // ropes need a little give ;)
            {
                j.BiasFactor = 0.01f;
                j.Softness = 0.05f;
            }

            return (path);
        }
示例#2
0
        /// <summary>
        /// Creates a track.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="mass">The mass.</param>
        /// <param name="endless">if set to <c>true</c> [endless].</param>
        /// <param name="collisionGroup">Collision group for the chain.</param>
        /// <param name="type">The joint/spring type.</param>
        /// <returns></returns>
        public Path CreateTrack(Vertices points, float width, float height, float mass, bool endless, int collisionGroup, LinkType type)
        {
            Path path = new Path(width, height, mass, endless); // create the path

            foreach (Vector2 v in points)
                path.Add(v); // add all the points to the path

            path.Update(); // update the path

            Geom geom;
            for (int i = 0; i < path.Bodies.Count; i++)
            {
                geom = GeomFactory.Instance.CreateRectangleGeom(path.Bodies[i], width, height);
                geom.CollisionGroup = collisionGroup;
                path.Add(geom); // add a geom to the chain
            }
            path.LinkBodies(type, Min, Max, SpringConstant, DampingConstant); // link bodies together

            return path;
        }
示例#3
0
        /// <summary>
        /// Creates a rope.
        /// </summary>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="mass">The mass.</param>
        /// <param name="pinStart">if set to <c>true</c> [pin start].</param>
        /// <param name="pinEnd">if set to <c>true</c> [pin end].</param>
        /// <param name="collisionGroup">Collision group for the chain.</param>
        /// <param name="type">The joint/spring type.</param>
        /// <returns></returns>
        public Path CreateRope(Vector2 start, Vector2 end, float width, float height, float mass, bool pinStart,
                               bool pinEnd, int collisionGroup, LinkType type)
        {
            Path path = new Path(width, height, mass, false); // create the path
            path.Add(start); // add starting point
            path.Add(Path.FindMidpoint(start, end));
            // add midpoint of line (must have this because my code needs at least 3 control points)
            path.Add(end); // add end point

            path.Update(); // call update to create all the bodies

            Geom geom;
            for (int i = 0; i < path.Bodies.Count; i++)
            {
                geom = GeomFactory.Instance.CreateRectangleGeom(path.Bodies[i], width, height);
                geom.collisionGroup = collisionGroup;
                path.Add(geom); // add a geom to the chain
            }
            path.LinkBodies(type, Min, Max, SpringConstant, DampingConstant); // link bodies together

            if (pinStart)
                path.Add(JointFactory.Instance.CreateFixedRevoluteJoint(path.Bodies[0], start));
            if (pinEnd)
                path.Add(JointFactory.Instance.CreateFixedRevoluteJoint(path.Bodies[path.Bodies.Count - 1],
                                                                        path.ControlPoints[2]));

            foreach (Joint j in path.Joints)      // ropes need a little give ;)
            {
                j.BiasFactor = 0.01f;
                j.Softness = 0.05f;
            }

            return (path);
        }