示例#1
0
        /// <summary>
        /// Returns the position on the slider path at specified index and distance.
        /// </summary>
        Vector2 InterpolateVertices(int i, float d)
        {
            if (calculatedPath.Count == 0)
            {
                return(Vector2.zero);
            }
            if (i <= 0)
            {
                return(calculatedPath[0]);
            }
            if (i >= calculatedPath.Count)
            {
                return(calculatedPath[calculatedPath.Count - 1]);
            }

            Vector2 prevPoint    = calculatedPath[i - 1];
            Vector2 curPoint     = calculatedPath[i];
            float   prevDistance = cumulativeLength[i - 1];
            float   curDistance  = cumulativeLength[i];

            // Prevent division by zero exception
            if (MathUtils.AlmostEquals(prevDistance, curDistance))
            {
                return(prevPoint);
            }

            return(prevPoint + (curPoint - prevPoint) * (float)((d - prevDistance) / (curDistance - prevDistance)));
        }
 /// <summary>
 /// Whether specified control points are labelled PerfectCurve path type but it's actually linear in terms of coordinates.
 /// </summary>
 private bool IsLinearPerfectCurve(Vector2[] p)
 {
     return(MathUtils.AlmostEquals(
                0,
                (p[1].y - p[0].y) * (p[2].x - p[0].x) - (p[1].x - p[0].x) * (p[2].y - p[0].y)
                ));
 }
示例#3
0
        /// <summary>
        /// Returns the shortest difference in angle between this and the other line.
        /// </summary>
        public float GetAngleDiff(Line other)
        {
            if (MathUtils.AlmostEquals(Theta, other.Theta))
            {
                return(0f);
            }
            float otherDeg = other.Theta * Mathf.Rad2Deg;
            float deg      = Theta * Mathf.Rad2Deg;
            float diff     = (otherDeg - deg + 180) % 360 - 180;

            return((diff < -180f ? diff + 360 : diff) * Mathf.Deg2Rad);
        }
    public override void OnControllerColliderHit(ControllerColliderHit hitInfo)
    {
        //Check if the collision normal is almost horizontal
        float hitAngleFromUp = Vector3.Angle(hitInfo.normal, Vector3.up);

        if (!MathUtils.AlmostEquals(hitAngleFromUp, 90.0f, 1.0f))
        {
            return;
        }

        //Choose a random direction
        ChooseNewDirection();

        //Make sure the new direction isn't going into the wall
        Character.MoveAmount = MathUtils.ReflectIfAgainstNormal(Character.MoveAmount, hitInfo.normal);
    }
 public void TestAlmostEquals()
 {
     Assert.IsTrue(MathUtils.AlmostEquals(0.5, 2.0 / 4.0));
     Assert.IsTrue(!MathUtils.AlmostEquals(0.5, 2.1 / 4.0));
 }
 protected override bool EqualTo(double x, double y) => MathUtils.AlmostEquals(x, y);
 protected override bool EqualTo(float x, float y) => MathUtils.AlmostEquals(x, y);