//Is a point to the left or to the right of a vector going from a to b
    private void PointInRelationToVector(MyVector2 a, MyVector2 b, MyVector2 p)
    {
        //bool isToLeft = Geometry.IsPointLeftOfVector(a, b, p);

        //Debug.Log("Is to left: " + isToLeft);

        LeftOnRight value = _Geometry.IsPoint_Left_On_Right_OfVector(a, b, p);

        if (value == LeftOnRight.Left)
        {
            Debug.Log("Left");
        }
        if (value == LeftOnRight.On)
        {
            Debug.Log("On");
        }
        if (value == LeftOnRight.Right)
        {
            Debug.Log("Right");
        }

        //Display
        Vector3 a_3d = a.ToVector3();
        Vector3 b_3d = b.ToVector3();

        Gizmos.DrawLine(a_3d, b_3d);

        float arrowSize = 0.1f;

        TestAlgorithmsHelpMethods.DisplayArrow(a_3d, b_3d, arrowSize, Color.white);

        Gizmos.DrawWireSphere(p.ToVector3(), 0.1f);
    }
    //Is a triangle oriented clockwise
    private void IsTriangleOrientedClockwise(MyVector2 a, MyVector2 b, MyVector2 c)
    {
        Triangle2 t = new Triangle2(a, b, c);

        bool isOrientedClockwise = _Geometry.IsTriangleOrientedClockwise(t.p1, t.p2, t.p3);

        Debug.Log("Is oriented clockwise: " + isOrientedClockwise);

        //We can also test if changing orientation is working
        t.ChangeOrientation();

        bool isOrientedClockwiseAfterRotation = _Geometry.IsTriangleOrientedClockwise(t.p1, t.p2, t.p3);

        Debug.Log("Is oriented clockwise after changing orientation: " + isOrientedClockwiseAfterRotation);


        //Display the triangle
        Gizmos.color = Color.white;

        Gizmos.DrawLine(a.ToVector3(), b.ToVector3());
        Gizmos.DrawLine(b.ToVector3(), c.ToVector3());
        Gizmos.DrawLine(c.ToVector3(), a.ToVector3());

        //Arrows showing the direction of the triangle
        float arrowSize = 0.1f;

        TestAlgorithmsHelpMethods.DisplayArrow(a.ToVector3(), b.ToVector3(), arrowSize, Color.white);
        TestAlgorithmsHelpMethods.DisplayArrow(b.ToVector3(), c.ToVector3(), arrowSize, Color.white);
        TestAlgorithmsHelpMethods.DisplayArrow(c.ToVector3(), a.ToVector3(), arrowSize, Color.white);
    }
Example #3
0
    //Display a connected set of points, like a convex hull
    //Can also show direction by displaying a tiny arrow
    public static void DisplayConnectedPoints(List <Vector3> points, Color color, bool showDirection = false)
    {
        if (points == null)
        {
            return;
        }

        Gizmos.color = color;

        for (int i = 0; i < points.Count; i++)
        {
            Vector3 p1 = points[MathUtility.ClampListIndex(i - 1, points.Count)];
            Vector3 p2 = points[MathUtility.ClampListIndex(i + 0, points.Count)];

            //Direction is important so we should display an arrow show the order of the points
            if (i == 0 && showDirection)
            {
                TestAlgorithmsHelpMethods.DisplayArrow(p1, p2, 0.2f, color);
            }
            else
            {
                Gizmos.DrawLine(p1, p2);
            }

            Gizmos.DrawWireSphere(p1, 0.1f);
        }
    }
Example #4
0
    private void DisplayConnectedPoints(Transform parentToPoints, Color color)
    {
        List <Vector3> pointsOnHull = GetPointsFromParent(parentToPoints);

        if (pointsOnHull == null)
        {
            Debug.Log("We have no points on the hull");

            return;
        }

        //Debug.Log(pointsOnHull.Count);

        Gizmos.color = color;

        for (int i = 0; i < pointsOnHull.Count; i++)
        {
            Vector3 p1 = pointsOnHull[MathUtility.ClampListIndex(i - 1, pointsOnHull.Count)];
            Vector3 p2 = pointsOnHull[MathUtility.ClampListIndex(i + 0, pointsOnHull.Count)];

            //Direction is important so we should display an arrow show the order of the points
            if (i == 0)
            {
                TestAlgorithmsHelpMethods.DisplayArrow(p1, p2, 0.2f, color);
            }
            else
            {
                Gizmos.DrawLine(p1, p2);
            }

            Gizmos.DrawWireSphere(p1, 0.1f);
        }
    }
    private void BezierCubic(MyVector3 posA, MyVector3 posB, MyVector3 handleA, MyVector3 handleB)
    {
        //Store the interpolated values so we later can display them
        List <Vector3> interpolatedValues = new List <Vector3>();

        //Loop between 0 and 1 in steps, where 1 step is minimum
        //So if steps is 5 then the line will be cut in 5 sections
        int steps = 20;

        float stepSize = 1f / (float)steps;

        float t = 0f;

        //+1 becuase wa also have to include the first point
        for (int i = 0; i < steps + 1; i++)
        {
            //Debug.Log(t);

            MyVector3 interpolatedPos = _Interpolation.BezierCubic(posA, posB, handleA, handleB, t);

            interpolatedValues.Add(interpolatedPos.ToVector3());

            t += stepSize;
        }


        //Display the curve
        DisplayInterpolatedValues(interpolatedValues, useRandomColor: true);

        //Display the start and end values and the handle points
        DisplayHandle(handleA.ToVector3(), posA.ToVector3());
        DisplayHandle(handleB.ToVector3(), posB.ToVector3());


        //Display other related data
        //Get the orientation of the point at t
        BezierCubic bezierCubic = new BezierCubic(posA, posB, handleA, handleB);

        InterpolationTransform trans = bezierCubic.GetTransform(tSliderValue);

        //Multiply the orientation with a direction vector to rotate the direction
        Vector3 forwardDir = trans.Forward.ToVector3();
        //- right vector because in this test files we are looking from above
        //so -right looks like up even though in the actual coordinate system it is -right
        Vector3 upDir = -trans.Right.ToVector3();

        Vector3 slidePos = _Interpolation.BezierCubic(posA, posB, handleA, handleB, tSliderValue).ToVector3();

        TestAlgorithmsHelpMethods.DisplayArrow(slidePos, slidePos + forwardDir * 2f, 0.2f, Color.blue);
        TestAlgorithmsHelpMethods.DisplayArrow(slidePos, slidePos + upDir * 2f, 0.2f, Color.blue);

        Gizmos.color = Color.red;

        Gizmos.DrawWireSphere(slidePos, 0.15f);
    }
    private void PassedWaypoint(MyVector2 wp1, MyVector2 wp2, MyVector2 testPoint)
    {
        bool hasPassed = _Geometry.HasPassedWaypoint(wp1, wp2, testPoint);

        Debug.Log(hasPassed);


        //Diplay
        TestAlgorithmsHelpMethods.DisplayArrow(wp1.ToVector3(), wp2.ToVector3(), 0.5f, Color.white);

        Gizmos.color = hasPassed ? Color.red : Color.black;

        Gizmos.DrawWireSphere(testPoint.ToVector3(), 0.5f);
    }
    private void BezierQuadratic(MyVector3 posA, MyVector3 posB, MyVector3 handle)
    {
        //Store the interpolated values so we later can display them
        List <Vector3> interpolatedValues = new List <Vector3>();

        //Loop between 0 and 1 in steps, where 1 step is minimum
        //So if steps is 5 then the line will be cut in 5 sections
        int steps = 10;

        float stepSize = 1f / (float)steps;

        float t = 0f;

        //+1 becuase wa also have to include the first point
        for (int i = 0; i < steps + 1; i++)
        {
            //Debug.Log(t);

            MyVector3 interpolatedValue = _Interpolation.BezierQuadratic(posA, posB, handle, t);

            interpolatedValues.Add(interpolatedValue.ToVector3());

            t += stepSize;
        }


        //Display the curve
        DisplayInterpolatedValues(interpolatedValues, useRandomColor: true);

        //Display the start and end values and the handle points
        DisplayHandle(handle.ToVector3(), posA.ToVector3());
        DisplayHandle(handle.ToVector3(), posB.ToVector3());



        //Display other related data
        //Get the forwrd dir of the point at t and display it
        MyVector3 forwardDir = _Interpolation.BezierQuadraticForwardDir(posA, posB, handle, tSliderValue);

        MyVector3 slidePos = _Interpolation.BezierQuadratic(posA, posB, handle, tSliderValue);

        TestAlgorithmsHelpMethods.DisplayArrow(slidePos.ToVector3(), (slidePos + forwardDir * 2f).ToVector3(), 0.2f, Color.blue);

        Gizmos.color = Color.red;

        Gizmos.DrawWireSphere(slidePos.ToVector3(), 0.15f);
    }