public static List <Vector3> FindVectorsOnSameRange(List <Vector3> list, float compare, H axis, float epsilon) { List <Vector3> res = new List <Vector3>(); for (int i = 0; i < list.Count; i++) { if (axis == H.X) { if (UMath.nearlyEqual(list[i].x, compare, epsilon)) { res.Add(list[i]); } } else if (axis == H.Y) { if (UMath.nearlyEqual(list[i].y, compare, epsilon)) { res.Add(list[i]); } } else if (axis == H.Z) { if (UMath.nearlyEqual(list[i].z, compare, epsilon)) { res.Add(list[i]); } } } return(res); }
//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); }
public bool RedoItemsIfOldInvIsDiff() { if (!UMath.nearlyEqual(_oldVolumeOccupied, Inv.CurrentVolumeOcuppied(), 0.01f) || _oldItemsAmt != Inv.InventItems.Count)//0.001 { _oldItemsAmt = Inv.InventItems.Count; UpdateToThisInv(Inv); return(true); } return(false); }
public static List <Vector3> FindVectorsOnSameHeight(List <Vector3> list, float height, float epsilon) { List <Vector3> res = new List <Vector3>(); for (int i = 0; i < list.Count; i++) { if (UMath.nearlyEqual(list[i].y, height, epsilon)) { res.Add(list[i]); } } return(res); }
//initializes the List Vector3 wholeMalla, nextStart, and zLot by ref //in this class initializes the fields,StepX , StepZ, Columns, Rows public void InitializeMallaStats(Vector3[] vertices, ref List <Vector3> wholeMalla, ref Vector3 nextStart, ref float zLot) { if (StepX != 0) { return; } if (vertices == null) { return; } wholeMalla = UPoly.ReturnWholeMallaAs1Poly(Program.gameScene.controllerMain.MeshController.Vertices); nextStart = wholeMalla[0]; zLot = wholeMalla[0].z; //UVisHelp.CreateHelpers(wholeMalla[0], Root.redSphereHelp); //UVisHelp.CreateHelpers(wholeMalla[2], Root.redSphereHelp); _lenght = wholeMalla[0].x - wholeMalla[1].x; _height = wholeMalla[3].z - wholeMalla[0].z; _mathCenter = m.Vertex.BuildVertexWithXandZ((wholeMalla[0].x + wholeMalla[1].x) / 2, (wholeMalla[3].z + wholeMalla[0].z) / 2); float epsi = 0.001f; for (int i = 0; i < vertices.Length; i++) { bool eq = UMath.nearlyEqual(vertices[i].x, wholeMalla[0].x, epsi); if (eq) { Columns++; } eq = UMath.nearlyEqual(vertices[i].z, wholeMalla[0].z, epsi); if (eq) { Rows++; } } StepX = _lenght / Columns; StepZ = _height / Rows; //print("Columns:" + Columns); //print("Rows:" + Rows); }
private void OnApplicationQuit() { var x = dragRectTransform.localScale.x; var y = dragRectTransform.localScale.y; var z = dragRectTransform.localScale.z; //All values must be the same to be saved if (UMath.nearlyEqual(x, y, 0.01f) && UMath.nearlyEqual(z, y, 0.01f)) { //Save PlayerPrefs.SetFloat(_name + ".localScale", dragRectTransform.localScale.x); } else { Debug.Log("cant save localScale:" + _name); } }
//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); }
/// <summary> /// Returns the axis in where the Vector3 are in same position /// Doesnt evaluate Y by default /// </summary> /// <param name="one"></param> /// <param name="two"></param> /// <param name="evalY">Will eval Y if is true</param> /// <returns></returns> H RetCommonAxis(Vector3 one, Vector3 two, float epsilon, bool evalY = false) { H res = H.None; bool x = UMath.nearlyEqual(one.x, two.x, epsilon); bool y = UMath.nearlyEqual(one.y, two.y, epsilon); bool z = UMath.nearlyEqual(one.z, two.z, epsilon); if (x) { res = H.X; } else if (y && evalY) { res = H.Y; } else if (z) { res = H.Z; } return(res); }
/// <summary> /// Tells u in which side a hit point landed on ppoly /// </summary> public static Dir TellMeWhenHitLanded(List <Vector3> poly, Vector3 hitVector3) { float ep = 0.01f; if (UMath.nearlyEqual(hitVector3.x, poly[0].x, ep) && UMath.nearlyEqual(hitVector3.x, poly[3].x, ep)) { return(Dir.W); } if (UMath.nearlyEqual(hitVector3.x, poly[1].x, ep) && UMath.nearlyEqual(hitVector3.x, poly[2].x, ep)) { return(Dir.E); } if (UMath.nearlyEqual(hitVector3.z, poly[0].z, ep) && UMath.nearlyEqual(hitVector3.z, poly[1].z, ep)) { return(Dir.N); } if (UMath.nearlyEqual(hitVector3.z, poly[3].z, ep) && UMath.nearlyEqual(hitVector3.z, poly[2].z, ep)) { return(Dir.S); } return(Dir.None); }
//The loop for the first row private List <Vector3> FirstRowLoop(List <Vector3> listSelected, float valToAlign, H axis) { bool nearEq = false; List <Vector3> res = new List <Vector3>(); for (int i = 0; i < listSelected.Count; i++) { if (axis == H.X) { nearEq = UMath.nearlyEqual(valToAlign, listSelected[i].x, 0.001f); } else if (axis == H.Z) { nearEq = UMath.nearlyEqual(valToAlign, listSelected[i].z, 0.001f); } if (nearEq) { res.Add(listSelected[i]); } } return(res); }