public void Init(TypeLineFind typeLine, int index, bool isSketching) { isRun = true; this.typeLine = typeLine; this.dir = index == 0 ?-1:1; isCompleteSketching = isSketching; RaycastHit2D hit; if (typeLine == TypeLineFind.horizontal) { scaleCur = new Vector2(0, 1); hit = Physics2D.Linecast(transform.position, (Vector2)transform.position + Vector2.right * dir * 20000, layerMask); posTarget = hit.point; int posX = MathfExtension.FloorToInt(posTarget.x); Debug.Log("posTarGetX:" + posTarget.x + " point:" + hit.point + " posX:" + posX + " POSTARGET:" + posTarget); posTarget.x = posX + ((int)dir * GameConfig.SIZE_HALF_LINE); } else { scaleCur = new Vector2(1, 0); hit = Physics2D.Linecast(transform.position, (Vector2)transform.position + Vector2.up * dir * 20000, layerMask); posTarget = hit.point; int posY = MathfExtension.FloorToInt(posTarget.y); Debug.Log("posTarGetY:" + posTarget.x + " point:" + hit.point + " posY:" + posY + " POSTARGET:" + posTarget); posTarget.y = posY + ((int)dir * GameConfig.SIZE_HALF_LINE); } //Debug.Log("hit:"+transform.position+"=>"+posTarget); }
private void Update() { if (isRun == false) { return; } if (isCompleteSketching == false && GameplayController.Instance.isEndGame == false) { if (typeLine.Equals(TypeLineFind.vertical)) { scaleCur.y += GameConfig.SPEED_SCALE * Time.deltaTime * dir; if (Mathf.Abs(scaleCur.y) >= Mathf.Abs((posTarget.y - transform.position.y) / 100.0f)) { scaleCur.y = (posTarget.y - transform.position.y) / 100.0f; posTarget.y = MathfExtension.FloorToIntAbs(posTarget.y); CompleteSketching(posTarget); } } else if (typeLine.Equals(TypeLineFind.horizontal)) { scaleCur.x += GameConfig.SPEED_SCALE * Time.deltaTime * dir; if (Mathf.Abs(scaleCur.x) >= Mathf.Abs((posTarget.x - transform.position.x) / 100.0f)) { scaleCur.x = (posTarget.x - transform.position.x) / 100.0f; posTarget.x = MathfExtension.FloorToIntAbs(posTarget.x); CompleteSketching(posTarget); } } transform.localScale = scaleCur; } }
public ItemLineInfo(Vector2 point, TypeLine typeLine) { this.point = point; this.point.x = MathfExtension.FloorToIntAbs(point.x); this.point.y = MathfExtension.FloorToIntAbs(point.y); this.typeLine = typeLine; }
/* * Much math isn't it. Well here is what it does. * We can't use Sins.GetVertexHeight to get height info because it is used for vertex and a joint have a very big probability of not perpeticular on a vertice. * First find which triangle the joint falls under. To do that we floor and ceil both x and z coordinates of joint's position. * p1 and p2 of triangle always will be (xFloor, y, zCeil) and (xCeil, y, zFloor). p3 will be closest one of (xFloor, y, zFloor) or (xCeil, y, zFloor) * Then find which point on triangle joint falls under. Just find out of triangle's plane equation using triangle's normal then using these equation and x, z positions find out y position. */ public static float CalculateTrianglePointHeight(Vector3 position) { float xFloor = MathfExtension.Floor(position.x, 1); float zFloor = MathfExtension.Floor(position.z, 1); float xCeil = MathfExtension.Ceil(position.x, 1); float zCeil = MathfExtension.Ceil(position.z, 1); Vector3 p3Floor = new Vector3(xFloor, position.y, zFloor); Vector3 p3Ceil = new Vector3(xCeil, position.z, zCeil); Vector3 p3 = Vector3.Distance(position, p3Floor) < Vector3.Distance(position, p3Ceil) ? p3Floor : p3Ceil; p3.y = Sins.GetVertexHeight(p3.x, p3.z); Vector3 p1 = new Vector3(xFloor, Sins.GetVertexHeight(xFloor, zCeil), zCeil); Vector3 p2 = new Vector3(xCeil, Sins.GetVertexHeight(xCeil, zFloor), zFloor); Vector3 triangleNormal = Vector3.Cross(p2 - p1, p3 - p1).normalized; float d = Vector3.Dot(p1, triangleNormal) * -1; if (Mathf.Approximately(triangleNormal.y, 0)) { return(p1.y); } return((triangleNormal.x * position.x + triangleNormal.z * position.z + d) / triangleNormal.y * -1); }
private float GetEllipseLength(float degree, float itemCount) { if (itemCount > 4) { itemCount += itemCount % 2; } return(MathfExtension.EvaluateEllipse(degree, 60 + 10 * Mathf.Max(6, itemCount), 50 + 12 * Mathf.Max(3, itemCount))); }
public void ShowSubMenuAt(Vector2 position, MarkingMenuItem[] items, float from = 0, float to = 360) { int itemCount = items.Length; float degreeDelta = (to - from) / (itemCount - 1 == 0 ? 1 : itemCount - 1); for (int i = 0; i < itemCount; ++i) { float degree = from + degreeDelta * i; float length = MathfExtension.EvaluateEllipse(degree, 180, 100); items[i].Show(); items[i].Position = position + new Vector2(length * Mathf.Cos(degree * Mathf.Deg2Rad), length * Mathf.Sin(degree * Mathf.Deg2Rad)); items[i].Degree = degree; } shownItems.Push(items); }
void Update() { if (GameplayController.Instance.canCreateLine == false) { return; } if (Input.GetMouseButtonDown(0)) { originPos = Input.mousePosition; originPos = cam.ScreenToWorldPoint(originPos); } if (Input.GetMouseButtonUp(0)) { endPos = Input.mousePosition; endPos = cam.ScreenToWorldPoint(endPos); Vector2 posMouse = originPos; TypeLineFind typeSwipe = TypeLineFind.vertical; if (Mathf.Abs(endPos.x - originPos.x) >= Mathf.Abs(endPos.y - originPos.y)) { typeSwipe = TypeLineFind.horizontal; } for (int i = 0; i < GameplayController.Instance.pointsList.Count; i++) { Vector2[] points = GameplayController.Instance.GetPointsBoard(i); if (points.Length > 0 && Utilities.IsPointInPolygon(posMouse, points)) { RaycastHit2D hit = Physics2D.BoxCast(posMouse, Vector2.one * (GameplayController.Instance.sizeLine.x * 2), 0, Vector2.zero, 0); if (hit.collider == null) { posMouse.x = MathfExtension.FloorToInt(posMouse.x); posMouse.y = MathfExtension.FloorToInt(posMouse.y); posMouse = GameplayController.Instance.RoundPosCreateLine(i, (Vector2)posMouse); posMouse.x = MathfExtension.FloorToInt(posMouse.x); posMouse.y = MathfExtension.FloorToInt(posMouse.y); Debug.Log("posMouse:" + posMouse); GameplayController.Instance.indexMask = i; GameplayController.Instance.CreateLine(typeSwipe, posMouse); } } } } }