Esempio n. 1
0
        private void DrawSimplifyPreview()
        {
            var lineRenderer = target as LineRenderer;

            if (!showSimplifyPreview || m_IsMultiEditing || !lineRenderer.enabled)
            {
                return;
            }

            if (m_PreviewPoints == null && lineRenderer.positionCount > 2)
            {
                m_PreviewPoints = new Vector3[lineRenderer.positionCount];
                lineRenderer.GetPositions(m_PreviewPoints);
                var simplePoints = new List <Vector3>();
                LineUtility.Simplify(m_PreviewPoints.ToList(), simplifyTolerance, simplePoints);
                if (lineRenderer.loop)
                {
                    simplePoints.Add(simplePoints[0]);
                }
                m_PreviewPoints = simplePoints.ToArray();
            }

            if (m_PreviewPoints != null)
            {
                Handles.color = Color.yellow;
                var oldMatrix = Handles.matrix;
                if (!lineRenderer.useWorldSpace)
                {
                    Handles.matrix = lineRenderer.transform.localToWorldMatrix;
                }
                Handles.DrawAAPolyLine(10, m_PreviewPoints.Length, m_PreviewPoints);
                Handles.matrix = oldMatrix;
            }
        }
    void Start()
    {
        // Get the points.
        var lineRenderer = GetComponent <LineRenderer>();

        //lineRenderer.positionCount = 100;
        //for (int i = 0; i < 100; i++)
        //{
        //    lineRenderer.SetPosition(i, new Vector3(0, Random.Range(0, 5f), transform.position.z + i));
        //}


        int pointsBefore = lineRenderer.positionCount;
        var points       = new Vector3[pointsBefore];

        lineRenderer.GetPositions(points);



        // Simplify.
        var simplifiedPoints = new List <Vector3>();

        LineUtility.Simplify(points.ToList(), tolerance, simplifiedPoints);

        // Assign back to the line renderer.
        lineRenderer.positionCount = simplifiedPoints.Count;
        lineRenderer.SetPositions(simplifiedPoints.ToArray());

        Debug.Log("Line reduced from " + pointsBefore + " to " + lineRenderer.positionCount);
    }
Esempio n. 3
0
    public Guardian SimplifyPolygon(Guardian guardian)
    {
        List <Vector2> sample = guardian.points;

        sample.RemoveAt(sample.Count - 1);
        LineUtility.Simplify(sample.ToList(), tolerance, sample);

        Vector2 midPoint = sample[Mathf.RoundToInt(sample.Count / 2)];
        int     index    = guardian.points.IndexOf(midPoint);

        List <Vector2> firstHalf  = guardian.points.GetRange(0, index);
        List <Vector2> secondHalf = guardian.points.GetRange(index, guardian.points.Count - index);

        firstHalf.Add(secondHalf[0]);
        secondHalf.Add(firstHalf[0]);

        LineUtility.Simplify(firstHalf.ToList(), tolerance, firstHalf);
        firstHalf.RemoveAt(firstHalf.Count - 1);
        LineUtility.Simplify(secondHalf.ToList(), tolerance, secondHalf);

        guardian.points = firstHalf;
        guardian.points.AddRange(secondHalf);

        Debug.Log("Simplified guardian to " + guardian.points.Count + " points");

        return(guardian);
    }
Esempio n. 4
0
        private void CalculatePoints(float lineSimplifyTolerance)
        {
            cachedPoints.Clear();
            for (var index = 0; index < knots.Length - 1; index++)
            {
                var knot     = knots[index];
                var nextKnot = knots[index + 1];

                // Ignore knots in the same position
                if (Vector3.Distance(knot.Position, nextKnot.Position) < Mathf.Epsilon)
                {
                    continue;
                }

                // Calculate linear distance between points
                var overestimatedLength = Vector3.Distance(knot.Position, nextKnot.Position);

                // Calculate positions on the Bezier curve
                var overestimatesPointsCount = Mathf.RoundToInt(overestimatedLength * 1.0f / lineSimplifyTolerance);
                var pointsCandidates         = new List <Vector3>(overestimatesPointsCount);
                for (var i = 0; i < overestimatesPointsCount; i++)
                {
                    pointsCandidates.Add(GetPoint(index, 1.0f * (i + 1) / overestimatesPointsCount));
                }

                // Simplify control points list, minimizing precached data
                var controlPositions = new List <Vector3>();
                LineUtility.Simplify(pointsCandidates, lineSimplifyTolerance, controlPositions);

                //Check if there are any calculated control positions
                var previousPoint = knot;
                if (controlPositions.Count == 0)
                {
                    return;
                }

                // Calculate distances between control points and cache them
                ApproximatedLength = Vector3.Distance(previousPoint.Position, controlPositions[0]);
                for (var i = 0; i < controlPositions.Count - 1; i++)
                {
                    ApproximatedLength += Vector3.Distance(controlPositions[i], controlPositions[i + 1]);
                }

                // Create control and key points
                for (var i = 0; i < controlPositions.Count; i++)
                {
                    var point = i == controlPositions.Count - 1 ? nextKnot.Clone() : nextKnot.GetControlPoint();
                    //Rotate to next position, keep previous angle at the last control point
                    point.Position = controlPositions[i];
                    var angle = Quaternion.LookRotation(controlPositions[i] - previousPoint.Position).eulerAngles;
                    point.Angle = angle;
                    var waypoint = (T)point;
                    cachedPoints.Add(waypoint);
                    previousPoint = waypoint;
                }
            }
        }
    public void UpdateTrajectory(Vector3 force, int iterations, float physicsTimescale = 1)
    {
        // run the sim
        List <Vector3> points = simulant.SimulateImpulse(force, iterations, physicsTimescale);

        // reduce the number of points to use in the line before loading them in
        LineUtility.Simplify(points, 0.01f, simplifiedPoints);
        // set the line
        lineRenderer.positionCount = simplifiedPoints.Count;
        lineRenderer.SetPositions(simplifiedPoints.ToArray());
    }
Esempio n. 6
0
    private void SimpleLine()
    {
        List <int> keep = new List <int>();

        LineUtility.Simplify(clip.points.Select(x => x.vector3).ToList(), tolerance, keep);

        for (int k = 0; k < keep.Count; k++)
        {
            int index = keep[k];
            clip.points[index].isSimple = true;
        }

        childObject.simple.positionCount = keep.Count;
        childObject.simple.SetPositions(clip.points.Where(x => x.isSimple == true).Select(x => x.vector3).ToArray());
    }
Esempio n. 7
0
 public void ObjectGenerator() //call RenderPoints() function to draw line renderer between all points if Line Bool is true.
 {
     if (Line)
     {
         if (!UseRotation)
         {
             orbitalpositions.Clear();                                           //clear any previously saved positions
             var simplifiedpoints = new List <Vector3>();
             LineUtility.Simplify(RawPositions, newtolerance, simplifiedpoints); //simplify list of raw positions to optimise line rendering if needed
             for (int i = 0; i < simplifiedpoints.Count; i++)
             {
                 Vector3 LocalPos = new Vector3(simplifiedpoints[i].x + CurrentPosition.x, simplifiedpoints[i].y + CurrentPosition.y, simplifiedpoints[i].z + CurrentPosition.z);
                 orbitalpositions.Add(LocalPos);
             }
             RenderPoints();
         }
         if (UseRotation)
         {
             orbitalobjects.Clear();
             var simplifiedpoints = new List <Vector3>();
             LineUtility.Simplify(RawPositions, newtolerance, simplifiedpoints);
             for (int i = 0; i < simplifiedpoints.Count; i++)
             {
                 Vector3    LocalPos     = new Vector3(simplifiedpoints[i].x + CurrentPosition.x, simplifiedpoints[i].y + CurrentPosition.y, simplifiedpoints[i].z + CurrentPosition.z);
                 GameObject orbitalchild = Instantiate(orbitalindicator, LocalPos, Quaternion.identity) as GameObject;
                 orbitalchild.transform.parent = this.gameObject.transform;
                 orbitalobjects.Add(orbitalchild);
             }
             RenderPoints();
         }
     }
     else
     {
         if (!UseRotation)
         {
             orbitalpositions.Clear();
         }
         if (UseRotation)
         {
             orbitalobjects.Clear();
         }
         LR.enabled = false;
         SetOrbiterColourModel();
         return;
     }
 }
Esempio n. 8
0
    void Start()
    {
        handTarget = new GameObject("Hand Target");

        string[] splitted    = data.text.Split(new char[] { ' ', ',', '[', ']' }, System.StringSplitOptions.RemoveEmptyEntries);
        int      nbPositions = splitted.Length / SimulationData.nbParametersMocap;

        rawPositions = new List <Vector3>(nbPositions);
        List <Vector3> filteredPositions = new List <Vector3>();

        for (int i = 0; i < nbPositions; i++)
        {
            rawPositions.Add(new Vector3(float.Parse(splitted[SimulationData.nbParametersMocap * i + 1]),
                                         float.Parse(splitted[SimulationData.nbParametersMocap * i + 2]),
                                         float.Parse(splitted[SimulationData.nbParametersMocap * i + 3])));
        }

        LineUtility.Simplify(rawPositions, simplifyTrajectoryTolerance, filteredPositions);
        nbPositions = filteredPositions.Count;

        Transform[] targets = new Transform[nbPositions];

        GameObject targetParent = new GameObject("Targets");

        // Read positions from parsed file
        for (int i = 0; i < nbPositions; i++)
        {
            GameObject target = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            Destroy(target.GetComponent <Collider>());
            target.name = "Target " + i.ToString();
            target.transform.localScale = 0.5f * SimulationData.DroneSize * Vector3.one;

            target.transform.parent   = targetParent.transform;
            target.transform.position = filteredPositions[i];

            target.GetComponent <Renderer>().material = targetMaterial;

            targets[i] = target.transform;
        }

        droneKeypointControl.keypoints = targets;
    }
    private void ResetLineRenderer()
    {
        if (points.Count > 0)
        {
            //uiLineRenderer.Points = ScaledPoints(useSimplification ? DouglasPeuckerLineSimplification(points.ToArray(), simplificationAmt) : points.ToArray());

            List <Vector2> simplifiedPointList = new List <Vector2>();



            LineUtility.Simplify(GetPointList(), simplificationAmt, simplifiedPointList);

            uiLineRenderer.Points = useSimplification ? simplifiedPointList.ToArray() : GetPointList().ToArray();

            if (scalePoints)
            {
                uiLineRenderer.Points = ScaledPoints(uiLineRenderer.Points);
            }
        }
    }
Esempio n. 10
0
    public void ExportFromWaypoints()
    {
        float tollerance = 1.7f;
        var   root       = new GameObject("Root Export");
        int   i          = 0;

        // Simplify.
        var simplifiedPoints = new List <Vector3>();

        LineUtility.Simplify(points.ToList(), tollerance, simplifiedPoints);

        foreach (var point in simplifiedPoints)
        {
            var w = new GameObject("Point " + i);
            w.transform.position = point;
            w.transform.parent   = root.transform;

            i++;
        }
    }
Esempio n. 11
0
        private static List <List <IntPoint> > ConvertToIntPointList(Vector2[][] paths, float simplify)
        {
            simplify = Mathf.Clamp01(1 - (simplify * 0.01f + 0.99f));
            List <List <IntPoint> > intPointPaths = new List <List <IntPoint> >(paths.Length);

            for (int i = 0; i < paths.Length; i++)
            {
                List <Vector2> simplifiedPath = new List <Vector2>(paths.Length);
                LineUtility.Simplify(paths[i].ToList(), simplify, simplifiedPath);
                List <IntPoint> intPointPath = new List <IntPoint>(simplifiedPath.Count);

                for (int j = 0; j < simplifiedPath.Count; j++)
                {
                    Vector2 point = simplifiedPath[j] * FLOAT_TO_INT_SCALE;
                    intPointPath.Add(new IntPoint(Mathf.RoundToInt(point.x), Mathf.RoundToInt(point.y)));
                }

                intPointPaths.Add(intPointPath);
            }

            return(intPointPaths);
        }
Esempio n. 12
0
    public void SetupPatrolPath()
    {
        RaycastHit raycastHit;
        float      size   = TerrainMeta.Size.x;
        float      single = 30f;
        int        num    = Mathf.CeilToInt(size * 2f * 3.14159274f / single);

        this.nodes = new List <Vector3>();
        float single1 = size;
        float single2 = 0f;

        for (int i = 0; i < num; i++)
        {
            float single3 = (float)i / (float)num * 360f;
            this.nodes.Add(new Vector3(Mathf.Sin(single3 * 0.0174532924f) * single1, single2, Mathf.Cos(single3 * 0.0174532924f) * single1));
        }
        float single4 = 2f;
        float single5 = 200f;
        float single6 = 150f;
        float single7 = 8f;
        bool  flag    = true;
        int   num1    = 1;
        float single8 = 20f;

        Vector3[] vector3 = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(single8, 0f, 0f), new Vector3(-single8, 0f, 0f), new Vector3(0f, 0f, single8), new Vector3(0f, 0f, -single8) };
        while (flag)
        {
            Debug.Log(string.Concat("Loop # :", num1));
            num1++;
            flag = false;
            for (int j = 0; j < num; j++)
            {
                Vector3 item     = this.nodes[j];
                int     num2     = (j == 0 ? num - 1 : j - 1);
                Vector3 item1    = this.nodes[(j == num - 1 ? 0 : j + 1)];
                Vector3 vector31 = this.nodes[num2];
                Vector3 vector32 = item;
                Vector3 vector33 = Vector3.zero - item;
                Vector3 vector34 = vector33.normalized;
                Vector3 vector35 = item + (vector34 * single4);
                if (Vector3.Distance(vector35, item1) <= single5 && Vector3.Distance(vector35, vector31) <= single5)
                {
                    bool flag1 = true;
                    for (int k = 0; k < (int)vector3.Length; k++)
                    {
                        Vector3 vector36 = vector35 + vector3[k];
                        if (this.GetWaterDepth(vector36) < single7)
                        {
                            flag1 = false;
                        }
                        Vector3 vector37 = vector34;
                        if (vector36 != Vector3.zero)
                        {
                            vector33 = vector36 - vector32;
                            vector37 = vector33.normalized;
                        }
                        if (Physics.Raycast(vector32, vector37, out raycastHit, single6, 1218511105))
                        {
                            flag1 = false;
                        }
                    }
                    if (flag1)
                    {
                        flag          = true;
                        this.nodes[j] = vector35;
                    }
                }
            }
        }
        List <int> nums = new List <int>();

        LineUtility.Simplify(this.nodes, 15f, nums);
        List <Vector3> vector3s = this.nodes;

        this.nodes = new List <Vector3>();
        foreach (int num3 in nums)
        {
            this.nodes.Add(vector3s[num3]);
        }
    }
    public static int Simplify_s(IntPtr l)
    {
        int result;

        try
        {
            int total = LuaDLL.lua_gettop(l);
            if (LuaObject.matchType(l, total, 1, typeof(List <Vector2>), typeof(float), typeof(List <int>)))
            {
                List <Vector2> points;
                LuaObject.checkType <List <Vector2> >(l, 1, out points);
                float tolerance;
                LuaObject.checkType(l, 2, out tolerance);
                List <int> pointsToKeep;
                LuaObject.checkType <List <int> >(l, 3, out pointsToKeep);
                LineUtility.Simplify(points, tolerance, pointsToKeep);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else if (LuaObject.matchType(l, total, 1, typeof(List <Vector2>), typeof(float), typeof(List <Vector2>)))
            {
                List <Vector2> points2;
                LuaObject.checkType <List <Vector2> >(l, 1, out points2);
                float tolerance2;
                LuaObject.checkType(l, 2, out tolerance2);
                List <Vector2> simplifiedPoints;
                LuaObject.checkType <List <Vector2> >(l, 3, out simplifiedPoints);
                LineUtility.Simplify(points2, tolerance2, simplifiedPoints);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else if (LuaObject.matchType(l, total, 1, typeof(List <Vector3>), typeof(float), typeof(List <int>)))
            {
                List <Vector3> points3;
                LuaObject.checkType <List <Vector3> >(l, 1, out points3);
                float tolerance3;
                LuaObject.checkType(l, 2, out tolerance3);
                List <int> pointsToKeep2;
                LuaObject.checkType <List <int> >(l, 3, out pointsToKeep2);
                LineUtility.Simplify(points3, tolerance3, pointsToKeep2);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else if (LuaObject.matchType(l, total, 1, typeof(List <Vector3>), typeof(float), typeof(List <Vector3>)))
            {
                List <Vector3> points4;
                LuaObject.checkType <List <Vector3> >(l, 1, out points4);
                float tolerance4;
                LuaObject.checkType(l, 2, out tolerance4);
                List <Vector3> simplifiedPoints2;
                LuaObject.checkType <List <Vector3> >(l, 3, out simplifiedPoints2);
                LineUtility.Simplify(points4, tolerance4, simplifiedPoints2);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else
            {
                LuaObject.pushValue(l, false);
                LuaDLL.lua_pushstring(l, "No matched override function Simplify to call");
                result = 2;
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Esempio n. 14
0
    IEnumerator ComputeAllProvinceBorderPointsCoroutine()
    {
        float timer = Time.realtimeSinceStartup;

        Color32[] pixels = ProvinceIdTex.GetPixels32();

        int width     = ProvinceIdTex.width;
        int height    = ProvinceIdTex.height;
        int numPixels = width * height;

        bool[] visited = new bool[numPixels];

        Queue <TraceStartIndex> startPointQueue = new Queue <TraceStartIndex>();

        int scanIndex  = 0;
        int traceIndex = 0;
        int spinIndex  = 4;        //starting from left

        bool complete = false;

        int borderCount = 0;

        //scan for first non-black pixel
        while (true)
        {
            if (ColorIDEquals(pixels[traceIndex], Color.black))
            {
                traceIndex++;
                continue;
            }

            break;
        }

        startPointQueue.Enqueue(new TraceStartIndex(traceIndex, spinIndex));

        //OPERATION LOOP
        while (true)
        {
            //TRACE STEP
            while (true)
            {
                //if we've run out of startpoints, terminate the loop.
                if (startPointQueue.Count == 0)
                {
                    break;
                }

                TraceStartIndex traceStartIndex = startPointQueue.Dequeue();

                int startingIndex = traceStartIndex.index;
                traceIndex = startingIndex;
                int startingSpin = traceStartIndex.fromDir;
                spinIndex = startingSpin;

                int lastX         = -1;
                int lastY         = -1;
                int lastSpinIndex = -1;

                //this starting index has already been visited, so skip it
                if (visited[startingIndex] == true)
                {
                    continue;
                }

                Color32       currentBordering = Color.white;
                List <float2> points           = new List <float2>();
                Border        border           = null;

                if (!ProvinceColorDict.TryGetValue(pixels[startingIndex], out Province currentProv))
                {
                    Debug.LogError("Couldn't find province with Color ID " + pixels[startingIndex].ToString());
                    yield break;
                }

                while (true)
                {
                    visited[traceIndex] = true;

                    int x = traceIndex % width;
                    int y = traceIndex / width;

                    int spinCount = 0;

                    //spin up to 8 times
                    while (true)
                    {
                        if (TryGetNeighborIndex(x, y, 1, (NEIGHBOR_DIR)spinIndex, out int neighborIndex, width, height))
                        {
                            //this pixel is same color as the traceIndex
                            if (ColorIDEquals(pixels[traceIndex], pixels[neighborIndex]))
                            {
                                //we've found the new trace index for the next loop
                                traceIndex = neighborIndex;
                                spinIndex  = GetPreviousSpinIndexClockwise(spinIndex);
                                break;
                            }
                            //this pixel is the bordering prov color we're currently operating on
                            else if (ColorIDEquals(pixels[neighborIndex], currentBordering))
                            {
                                //AND it's a direct neighbor
                                //AND it hasn't been visited
                                if (spinIndex % 2 == 0 && (visited[neighborIndex] == false))
                                {
                                    if (points.Count == 0)
                                    {
                                        //For the first point of a border, add an extra point in the corner of the pixel.
                                        float2 p0 = GetPixelBorderCornerUVsFromSpinBehind(spinIndex, x, y, width, height);
                                        points.Add(p0);
                                    }

                                    //add the points
                                    float2 p = GetPixelBorderUVsFromSpin(spinIndex, x, y, width, height);
                                    points.Add(p);

                                    lastX         = x;
                                    lastY         = y;
                                    lastSpinIndex = spinIndex;
                                }
                            }
                            //this pixel is neither our color nor the current operative color and it's a direct neighbor
                            else if (spinIndex % 2 == 0)
                            {
                                //flush the accrued points to the previous operative color province border
                                if (border != null && points.Count > 0)
                                {
                                    //Add a last pixel
                                    float2 pLast = GetPixelBorderCornerUVsFromSpinAhead(lastSpinIndex, lastX, lastY, width, height);
                                    points.Add(pLast);

                                    List <Vector2> simplifiedPoints = new List <Vector2>();
                                    LineUtility.Simplify(points.Select(val => new Vector2(val.x, val.y)).ToList(), simplifyTolerance, simplifiedPoints);
                                    points = simplifiedPoints.Select(val => new float2(val.x, val.y)).ToList();

                                    border.Points.Add(points);
                                    points = new List <float2>();
                                }

                                //Check to make sure this pixel isn't a lone pixel.
                                bool isLonePixel = true;

                                for (int i = 0; i < 4; i++)
                                {
                                    //Go through every direction and if this pixel has a direct bordering same colored pixel, it's not alone.
                                    if (TryGetNeighborIndex(neighborIndex, (NEIGHBOR_DIR)(i * 2), out int potentialStartPointNeighborIndex, width, height))
                                    {
                                        if (ColorIDEquals(pixels[neighborIndex], pixels[potentialStartPointNeighborIndex]))
                                        {
                                            isLonePixel = false;
                                        }
                                    }
                                }

                                if (isLonePixel == false)
                                {
                                    //make this color the new operative color
                                    currentBordering = pixels[neighborIndex];

                                    //try to find this province by color id
                                    if (ProvinceColorDict.TryGetValue(currentBordering, out Province borderingProv))
                                    {
                                        //province exists, get or create a border object
                                        if (!currentProv.Borders.TryGetValue(borderingProv.ID, out border))
                                        {
                                            border = new Border(borderCount++, currentProv.ID, borderingProv.ID);
                                            currentProv.Borders.Add(borderingProv.ID, border);
                                            borderingProv.Borders.Add(currentProv.ID, border);

                                            BorderList.Add(border);
                                        }
                                    }
                                    else
                                    {
                                        //province doesn't exist, break
                                        Debug.LogError("Couldn't province with Color ID " + currentBordering.ToString());
                                        yield break;
                                    }

                                    //enqueue a new starting point
                                    if (visited[neighborIndex] == false && !(traceIndex == startingIndex && spinIndex != startingSpin) && !ColorIDEquals(pixels[neighborIndex], Color.black))
                                    {
                                        TraceStartIndex newStartIndex = new TraceStartIndex(neighborIndex, GetOppositeSpinIndex(spinIndex));
                                        startPointQueue.Enqueue(newStartIndex);
                                    }

                                    //if this is a direct neighbor and it hasn't been visited, add points
                                    if (spinIndex % 2 == 0 && visited[neighborIndex] == false)
                                    {
                                        if (points.Count == 0)
                                        {
                                            //For the first point of a border, add an extra point in the corner of the pixel.
                                            float2 p0 = GetPixelBorderCornerUVsFromSpinBehind(spinIndex, x, y, width, height);
                                            points.Add(p0);
                                        }

                                        float2 p = GetPixelBorderUVsFromSpin(spinIndex, x, y, width, height);
                                        points.Add(p);

                                        lastX         = x;
                                        lastY         = y;
                                        lastSpinIndex = spinIndex;
                                    }
                                }
                            }
                        }
Esempio n. 15
0
    public void SetupPatrolPath()
    {
        // ISSUE: variable of the null type
        __Null x    = TerrainMeta.Size.x;
        int    num1 = Mathf.CeilToInt((float)(x * 2.0 * 3.14159274101257) / 30f);

        this.nodes = new List <Vector3>();
        float num2 = (float)x;
        float num3 = 0.0f;

        for (int index = 0; index < num1; ++index)
        {
            float num4 = (float)((double)index / (double)num1 * 360.0);
            this.nodes.Add(new Vector3(Mathf.Sin(num4 * ((float)Math.PI / 180f)) * num2, num3, Mathf.Cos(num4 * ((float)Math.PI / 180f)) * num2));
        }
        float num5  = 2f;
        float num6  = 200f;
        float num7  = 150f;
        float num8  = 8f;
        bool  flag1 = true;
        int   num9  = 1;
        float num10 = 20f;

        Vector3[] vector3Array = new Vector3[5]
        {
            new Vector3(0.0f, 0.0f, 0.0f),
            new Vector3(num10, 0.0f, 0.0f),
            new Vector3(-num10, 0.0f, 0.0f),
            new Vector3(0.0f, 0.0f, num10),
            new Vector3(0.0f, 0.0f, -num10)
        };
        while (flag1)
        {
            Debug.Log((object)("Loop # :" + (object)num9));
            ++num9;
            flag1 = false;
            for (int index1 = 0; index1 < num1; ++index1)
            {
                Vector3 node1      = this.nodes[index1];
                int     index2     = index1 == 0 ? num1 - 1 : index1 - 1;
                Vector3 node2      = this.nodes[index1 == num1 - 1 ? 0 : index1 + 1];
                Vector3 node3      = this.nodes[index2];
                Vector3 vector3_1  = node1;
                Vector3 vector3_2  = Vector3.op_Subtraction(Vector3.get_zero(), node1);
                Vector3 normalized = ((Vector3) ref vector3_2).get_normalized();
                Vector3 vector3_3  = Vector3.op_Addition(node1, Vector3.op_Multiply(normalized, num5));
                if ((double)Vector3.Distance(vector3_3, node2) <= (double)num6 && (double)Vector3.Distance(vector3_3, node3) <= (double)num6)
                {
                    bool flag2 = true;
                    for (int index3 = 0; index3 < vector3Array.Length; ++index3)
                    {
                        Vector3 pos = Vector3.op_Addition(vector3_3, vector3Array[index3]);
                        if ((double)this.GetWaterDepth(pos) < (double)num8)
                        {
                            flag2 = false;
                        }
                        Vector3 vector3_4 = normalized;
                        if (Vector3.op_Inequality(pos, Vector3.get_zero()))
                        {
                            vector3_2 = Vector3.op_Subtraction(pos, vector3_1);
                            vector3_4 = ((Vector3) ref vector3_2).get_normalized();
                        }
                        RaycastHit raycastHit;
                        if (Physics.Raycast(vector3_1, vector3_4, ref raycastHit, num7, 1218511105))
                        {
                            flag2 = false;
                        }
                    }
                    if (flag2)
                    {
                        flag1 = true;
                        this.nodes[index1] = vector3_3;
                    }
                }
            }
        }
        List <int> intList = new List <int>();

        LineUtility.Simplify(this.nodes, 15f, intList);
        List <Vector3> nodes = this.nodes;

        this.nodes = new List <Vector3>();
        foreach (int index in intList)
        {
            this.nodes.Add(nodes[index]);
        }
    }
Esempio n. 16
0
    public static List <Vector3> GenerateOceanPatrolPath(float minDistanceFromShore = 50f, float minWaterDepth = 8f)
    {
        RaycastHit raycastHit;
        object     obj = Interface.CallHook("OnBoatPathGenerate");

        if (obj is List <Vector3> )
        {
            return((List <Vector3>)obj);
        }
        float          size     = TerrainMeta.Size.x;
        float          single   = 30f;
        int            num      = Mathf.CeilToInt(size * 2f * 3.14159274f / single);
        List <Vector3> vector3s = new List <Vector3>();
        float          single1  = size;
        float          single2  = 0f;

        for (int i = 0; i < num; i++)
        {
            float single3 = (float)i / (float)num * 360f;
            vector3s.Add(new Vector3(Mathf.Sin(single3 * 0.0174532924f) * single1, single2, Mathf.Cos(single3 * 0.0174532924f) * single1));
        }
        float single4 = 4f;
        float single5 = 200f;
        bool  flag    = true;

        for (int j = 0; j < AI.ocean_patrol_path_iterations & flag; j++)
        {
            flag = false;
            for (int k = 0; k < num; k++)
            {
                Vector3 item     = vector3s[k];
                int     num1     = (k == 0 ? num - 1 : k - 1);
                Vector3 vector3  = vector3s[(k == num - 1 ? 0 : k + 1)];
                Vector3 item1    = vector3s[num1];
                Vector3 vector31 = item;
                Vector3 vector32 = Vector3.zero - item;
                Vector3 vector33 = vector32.normalized;
                Vector3 vector34 = item + (vector33 * single4);
                if (Vector3.Distance(vector34, vector3) <= single5 && Vector3.Distance(vector34, item1) <= single5)
                {
                    bool flag1 = true;
                    int  num2  = 16;
                    int  num3  = 0;
                    while (num3 < num2)
                    {
                        float single6 = (float)num3 / (float)num2 * 360f;
                        vector32 = new Vector3(Mathf.Sin(single6 * 0.0174532924f), single2, Mathf.Cos(single6 * 0.0174532924f));
                        Vector3 vector35 = vector34 + (vector32.normalized * 1f);
                        BaseBoat.GetWaterDepth(vector35);
                        Vector3 vector36 = vector33;
                        if (vector35 != Vector3.zero)
                        {
                            vector32 = vector35 - vector34;
                            vector36 = vector32.normalized;
                        }
                        if (!UnityEngine.Physics.SphereCast(vector31, 3f, vector36, out raycastHit, minDistanceFromShore, 1218511105))
                        {
                            num3++;
                        }
                        else
                        {
                            flag1 = false;
                            break;
                        }
                    }
                    if (flag1)
                    {
                        flag        = true;
                        vector3s[k] = vector34;
                    }
                }
            }
        }
        if (flag)
        {
            Debug.LogWarning("Failed to generate ocean patrol path");
            return(null);
        }
        List <int> nums = new List <int>();

        LineUtility.Simplify(vector3s, 5f, nums);
        List <Vector3> vector3s1 = vector3s;

        vector3s = new List <Vector3>();
        foreach (int num4 in nums)
        {
            vector3s.Add(vector3s1[num4]);
        }
        Debug.Log(string.Concat("Generated ocean patrol path with node count: ", vector3s.Count));
        return(vector3s);
    }
Esempio n. 17
0
    public static List <Vector3> GenerateOceanPatrolPath(
        float minDistanceFromShore = 50f,
        float minWaterDepth        = 8f)
    {
        // ISSUE: variable of the null type
        __Null         x            = TerrainMeta.Size.x;
        int            num1         = Mathf.CeilToInt((float)(x * 2.0 * 3.14159274101257) / 30f);
        List <Vector3> vector3List1 = new List <Vector3>();
        float          num2         = (float)x;
        float          num3         = 0.0f;

        for (int index = 0; index < num1; ++index)
        {
            float num4 = (float)((double)index / (double)num1 * 360.0);
            vector3List1.Add(new Vector3(Mathf.Sin(num4 * ((float)Math.PI / 180f)) * num2, num3, Mathf.Cos(num4 * ((float)Math.PI / 180f)) * num2));
        }
        float num5  = 4f;
        float num6  = 200f;
        bool  flag1 = true;

        for (int index1 = 0; index1 < AI.ocean_patrol_path_iterations & flag1; ++index1)
        {
            flag1 = false;
            for (int index2 = 0; index2 < num1; ++index2)
            {
                Vector3 vector3_1   = vector3List1[index2];
                int     index3      = index2 == 0 ? num1 - 1 : index2 - 1;
                int     index4      = index2 == num1 - 1 ? 0 : index2 + 1;
                Vector3 vector3_2   = vector3List1[index4];
                Vector3 vector3_3   = vector3List1[index3];
                Vector3 vector3_4   = vector3_1;
                Vector3 vector3_5   = Vector3.op_Subtraction(Vector3.get_zero(), vector3_1);
                Vector3 normalized1 = ((Vector3) ref vector3_5).get_normalized();
                Vector3 vector3_6   = Vector3.op_Addition(vector3_1, Vector3.op_Multiply(normalized1, num5));
                if ((double)Vector3.Distance(vector3_6, vector3_2) <= (double)num6 && (double)Vector3.Distance(vector3_6, vector3_3) <= (double)num6)
                {
                    bool flag2 = true;
                    int  num4  = 16;
                    for (int index5 = 0; index5 < num4; ++index5)
                    {
                        float num7 = (float)((double)index5 / (double)num4 * 360.0);
                        vector3_5 = new Vector3(Mathf.Sin(num7 * ((float)Math.PI / 180f)), num3, Mathf.Cos(num7 * ((float)Math.PI / 180f)));
                        Vector3 normalized2 = ((Vector3) ref vector3_5).get_normalized();
                        Vector3 pos         = Vector3.op_Addition(vector3_6, Vector3.op_Multiply(normalized2, 1f));
                        double  waterDepth  = (double)BaseBoat.GetWaterDepth(pos);
                        Vector3 vector3_7   = normalized1;
                        if (Vector3.op_Inequality(pos, Vector3.get_zero()))
                        {
                            vector3_5 = Vector3.op_Subtraction(pos, vector3_6);
                            vector3_7 = ((Vector3) ref vector3_5).get_normalized();
                        }
                        RaycastHit raycastHit;
                        if (Physics.SphereCast(vector3_4, 3f, vector3_7, ref raycastHit, minDistanceFromShore, 1218511105))
                        {
                            flag2 = false;
                            break;
                        }
                    }
                    if (flag2)
                    {
                        flag1 = true;
                        vector3List1[index2] = vector3_6;
                    }
                }
            }
        }
        if (flag1)
        {
            Debug.LogWarning((object)"Failed to generate ocean patrol path");
            return((List <Vector3>)null);
        }
        List <int> intList = new List <int>();

        LineUtility.Simplify(vector3List1, 5f, intList);
        List <Vector3> vector3List2 = vector3List1;
        List <Vector3> vector3List3 = new List <Vector3>();

        foreach (int index in intList)
        {
            vector3List3.Add(vector3List2[index]);
        }
        Debug.Log((object)("Generated ocean patrol path with node count: " + (object)vector3List3.Count));
        return(vector3List3);
    }
Esempio n. 18
0
    public static List <Vector3> GenerateOceanPatrolPath(float minDistanceFromShore = 50f, float minWaterDepth = 8f)
    {
        object obj = Interface.CallHook("OnBoatPathGenerate");

        if (obj is List <Vector3> )
        {
            return((List <Vector3>)obj);
        }
        float          x    = TerrainMeta.Size.x;
        float          num  = x * 2f * (float)Math.PI;
        float          num2 = 30f;
        int            num3 = Mathf.CeilToInt(num / num2);
        List <Vector3> list = new List <Vector3>();
        float          num4 = x;
        float          y    = 0f;

        for (int i = 0; i < num3; i++)
        {
            float num5 = (float)i / (float)num3 * 360f;
            list.Add(new Vector3(Mathf.Sin(num5 * ((float)Math.PI / 180f)) * num4, y, Mathf.Cos(num5 * ((float)Math.PI / 180f)) * num4));
        }
        float num6 = 4f;
        float num7 = 200f;
        bool  flag = true;

        for (int j = 0; j < AI.ocean_patrol_path_iterations && flag; j++)
        {
            flag = false;
            for (int k = 0; k < num3; k++)
            {
                Vector3 vector     = list[k];
                int     index      = ((k == 0) ? (num3 - 1) : (k - 1));
                int     index2     = ((k != num3 - 1) ? (k + 1) : 0);
                Vector3 b          = list[index2];
                Vector3 b2         = list[index];
                Vector3 origin     = vector;
                Vector3 normalized = (Vector3.zero - vector).normalized;
                Vector3 vector2    = vector + normalized * num6;
                if (Vector3.Distance(vector2, b) > num7 || Vector3.Distance(vector2, b2) > num7)
                {
                    continue;
                }
                bool flag2 = true;
                int  num8  = 16;
                for (int l = 0; l < num8; l++)
                {
                    float   num9        = (float)l / (float)num8 * 360f;
                    Vector3 normalized2 = new Vector3(Mathf.Sin(num9 * ((float)Math.PI / 180f)), y, Mathf.Cos(num9 * ((float)Math.PI / 180f))).normalized;
                    Vector3 vector3     = vector2 + normalized2 * 1f;
                    GetWaterDepth(vector3);
                    Vector3 direction = normalized;
                    if (vector3 != Vector3.zero)
                    {
                        direction = (vector3 - vector2).normalized;
                    }
                    RaycastHit hitInfo;
                    if (UnityEngine.Physics.SphereCast(origin, 3f, direction, out hitInfo, minDistanceFromShore, 1218511105))
                    {
                        flag2 = false;
                        break;
                    }
                }
                if (flag2)
                {
                    flag    = true;
                    list[k] = vector2;
                }
            }
        }
        if (flag)
        {
            Debug.LogWarning("Failed to generate ocean patrol path");
            return(null);
        }
        List <int> list2 = new List <int>();

        LineUtility.Simplify(list, 5f, list2);
        List <Vector3> list3 = list;

        list = new List <Vector3>();
        foreach (int item in list2)
        {
            list.Add(list3[item]);
        }
        Debug.Log("Generated ocean patrol path with node count: " + list.Count);
        return(list);
    }