Example #1
0
File: Registro.cs Project: Cdrix/SM
    /// <summary>
    /// Taken a list of vectors 3 will find NW, NE, and SW and from there will create a new rectangle
    /// Returns a rectangle in our system where North is on the higher Y value always
    ///
    /// Y val flipped at the end
    /// </summary>
    public static Rect FromALotOfVertexToRect(List <Vector3> list)
    {
        List <float> xS = UList.ReturnAxisList(list, H.X);
        List <float> zS = UList.ReturnAxisList(list, H.Z);

        float minX = UMath.ReturnMinimum(xS);
        float maxX = UMath.ReturnMax(xS);

        float minZ = UMath.ReturnMinimum(zS);
        float maxZ = UMath.ReturnMax(zS);

        //Poly List that only need a valid NW, NE, and SW
        Vector3 NW = new Vector3(minX, 0, maxZ);
        Vector3 NE = new Vector3(maxX, 0, maxZ);
        Vector3 SE = new Vector3(maxX, 0, minZ);
        Vector3 SW = new Vector3(minX, 0, minZ);

        List <Vector3> poly = new List <Vector3>()
        {
            NW, NE, SE, SW
        };

        //here i find the Rect from this poly and then
        // I invert the Y of the recatangle... other wise this big rectangle
        //is not overlapping anything will be far off in the Cordinates...
        //Due to North(up) is bigger here say 100,, and South(down) less say 0 all this on World Z axis
        //As long as MeshManager Hover Current Vertices is big as is its now 9 Lots (each lot 5x5 real polys)
        //the Rect of the buildings will work flawlessly
        return(U2D.ReturnRectYInverted(U2D.FromPolyToRect(poly)));
    }
Example #2
0
File: Way.cs Project: Cdrix/SM
    /// <summary>
    /// If the minimun of the both path is higher than _minHeightToSpawn is true
    /// </summary>
    bool FindIFWayAboveWater()
    {
        bool  res      = false;
        float minYVert = 0;
        float minYHor  = 0;

        if (_verticPathNew.Count > 0)
        {
            var vertYs = UList.ReturnAxisList(_verticPathNew, H.Y);
            minYVert = UMath.ReturnMinimum(vertYs);
            if (minYVert > _minHeightToSpawn)
            {
                res = true;
            }
        }
        if (_horPathNew.Count > 0)
        {
            var horYs = UList.ReturnAxisList(_horPathNew, H.Y);
            minYHor = UMath.ReturnMinimum(horYs);
            if (minYHor > _minHeightToSpawn)
            {
                res = true;
            }
        }
        if (_verticPathNew.Count > 0 && _horPathNew.Count > 0)
        {
            var min = UMath.ReturnMinimum(minYVert, minYHor);
            if (min > _minHeightToSpawn)
            {
                res = true;
            }
        }

        return(res);
    }
Example #3
0
File: SubPolyr.cs Project: Cdrix/SM
    //Returns first row list based on the rotation facer
    private List <Vector3> ReturnFirstRow(List <Vector3> listSelected, int rotationFacer)
    {
        List <Vector3> res = new List <Vector3>();

        if (rotationFacer == 0)
        {
            List <float> allZ = UList.ReturnAxisList(listSelected, H.Z);
            float        zMax = UMath.ReturnMax(allZ);
            res = FirstRowLoop(listSelected, zMax, H.Z);
        }
        else if (rotationFacer == 1)
        {
            List <float> allX = UList.ReturnAxisList(listSelected, H.X);
            float        xMax = UMath.ReturnMax(allX);
            res = FirstRowLoop(listSelected, xMax, H.X);
        }
        else if (rotationFacer == 2)
        {
            List <float> allZ = UList.ReturnAxisList(listSelected, H.Z);
            float        zMin = UMath.ReturnMinimum(allZ);
            res = FirstRowLoop(listSelected, zMin, H.Z);
        }
        else if (rotationFacer == 3)
        {
            List <float> allX = UList.ReturnAxisList(listSelected, H.X);
            float        xMin = UMath.ReturnMinimum(allX);
            res = FirstRowLoop(listSelected, xMin, H.X);
        }
        return(res);
    }
Example #4
0
    /// <summary>
    /// Only evaluates X and Z axis... only works for the type of 90 degrees abanico
    /// implementado aqui
    /// </summary>
    /// <param name="list"></param>
    /// <param name="stone"></param>
    /// <returns></returns>
    public static Vector3 FindClosestPos(List <Vector3> list, Vector3 stone)
    {
        List <float> distances = new List <float>();

        for (int i = 0; i < list.Count; i++)
        {
            float dist = Vector3.Distance(stone, list[i]);
            distances.Add(dist);
            //General cloneTexto = General.Create(Root.texto3d, list[i]);
            //cloneTexto.GetComponent<TextMesh>().text = i.ToString();
        }

        int   indexRes = -1;
        float min      = UMath.ReturnMinimum(distances);

        for (int i = 0; i < distances.Count; i++)
        {
            if (distances[i] == min)
            {
                indexRes = i;
            }
        }

        return(list[indexRes]);
    }
Example #5
0
File: UPoly.cs Project: Cdrix/SM
    //will even 1 poly  in Y.
    private List <Vector3> EvenInYPoly(List <Vector3> poly, ref Vector3[] vertices)
    {
        float maxY       = UMath.ReturnMax(poly[0].y, poly[1].y, poly[2].y, poly[3].y);
        float minY       = UMath.ReturnMinimum(poly[0].y, poly[1].y, poly[2].y, poly[3].y);
        float heightDiff = maxY - minY;

        //print(heightDiff + " heightDiff");

        for (int i = 0; i < poly.Count; i++)
        {
            Vector3 newModifiedYPos = poly[i];
            newModifiedYPos.y = minY;
            poly[i]           = newModifiedYPos;
        }

        float epsilon = 0.1f;

        for (int i = 0; i < vertices.Length; i++)
        {
            for (int j = 0; j < poly.Count; j++)
            {
                //if this are the same in X and Z we are updating
                bool x = UMath.nearlyEqual(vertices[i].x, poly[j].x, epsilon);
                bool z = UMath.nearlyEqual(vertices[i].z, poly[j].z, epsilon);
                if (x && z)
                {   //updating the whole vertices matrix
                    vertices[i] = poly[j];
                }
            }
        }
        return(poly);
    }
Example #6
0
    public static float ReturnMinFromVector3(Vector3 start, Vector3 end, H axis)
    {
        float min = 0;

        if (axis == H.X)
        {
            min = UMath.ReturnMinimum(start.x, end.x);
        }
        else if (axis == H.Z)
        {
            min = UMath.ReturnMinimum(start.z, end.z);
        }
        return(min);
    }
Example #7
0
File: UPoly.cs Project: Cdrix/SM
    //will even many polys in Y. this Method has a bug that
    //put all vertices toghether
    public List <Vector3> EvenInYManyPolys(List <Vector3> manyPoly, ref Vector3[] vertices, ref bool isToEven,
                                           float maxHeightForEven, ref float minY)
    {
        float maxY = UMath.ReturnMax(UList.ReturnAxisList(manyPoly, H.Y));

        minY = UMath.ReturnMinimum(UList.ReturnAxisList(manyPoly, H.Y));
        float heightDiff = maxY - minY;

        if (heightDiff >= maxHeightForEven)
        {
            isToEven = false;
            return(manyPoly);
        }

        isToEven = true;
        //print(heightDiff + " heightDiff");

        for (int i = 0; i < manyPoly.Count; i++)
        {
            Vector3 newModifiedYPos = manyPoly[i];
            newModifiedYPos.y = minY;
            manyPoly[i]       = newModifiedYPos;
        }

        float epsilon = 0.1f;

        for (int i = 0; i < vertices.Length; i++)
        {
            for (int j = 0; j < manyPoly.Count; j++)
            {
                //if this are the same in X and Z we are updating
                bool x = UMath.nearlyEqual(vertices[i].x, manyPoly[j].x, epsilon);
                bool z = UMath.nearlyEqual(vertices[i].z, manyPoly[j].z, epsilon);
                if (x && z)
                {   //updating the whole vertices matrix
                    vertices[i] = manyPoly[j];
                }
            }
        }
        return(manyPoly);
    }
Example #8
0
    private void DefineCurrentRow()
    {
        //_currRow.Add
        var xS = UList.FindXAxisCommonValues(_eaten, H.Descending);
        var zS = UList.FindZAxisCommonValues(_eaten, H.Descending);

        float find = 0;
        H     axis = H.None;

        //norht find the top value on z
        if (_direction == 0)
        {
            find = UMath.ReturnMax(zS);
            axis = H.Z;
        }
        //south
        else if (_direction == 2)
        {
            find = UMath.ReturnMinimum(zS);
            axis = H.Z;
        }
        //east
        else if (_direction == 1)
        {
            find = UMath.ReturnMax(xS);
            axis = H.X;
        }
        //west
        else if (_direction == 3)
        {
            find = UMath.ReturnMinimum(xS);
            axis = H.X;
        }

        _currRow = UList.FindVectorsOnSameRange(_eaten, find, axis, 0.05f);
    }
Example #9
0
File: Registro.cs Project: Cdrix/SM
    /// <summary>
    /// This one use Y as MathCenter
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    public static List <Vector3> FromALotOfVertexToPolyMathCenterY(List <Vector3> list)
    {
        List <float> xS = UList.ReturnAxisList(list, H.X);
        List <float> zS = UList.ReturnAxisList(list, H.Z);

        float minX = UMath.ReturnMinimum(xS);
        float maxX = UMath.ReturnMax(xS);

        float minZ = UMath.ReturnMinimum(zS);
        float maxZ = UMath.ReturnMax(zS);

        //Poly List that only need a valid NW, NE, and SW
        SMe m = new SMe();
        //throwing rays so we keep the exact Y values
        Vector3 NW = new Vector3(minX, m.IniTerr.MathCenter.y, maxZ);
        Vector3 NE = new Vector3(maxX, m.IniTerr.MathCenter.y, maxZ);
        Vector3 SE = new Vector3(maxX, m.IniTerr.MathCenter.y, minZ);
        Vector3 SW = new Vector3(minX, m.IniTerr.MathCenter.y, minZ);

        return(new List <Vector3>()
        {
            NW, NE, SE, SW
        });
    }