private void OnDrawGizmosSelected() { Gizmos.color = Color.yellow; Gizmos.DrawSphere(posPuntero, 0.25f); if (m_pointList != null && m_pointList.Count > 1) { DebugExtension.DebugLine(m_pointList, Colors.LightBlue, Colors.DarkBlue); } //if (optimacedPointList != null && optimacedPointList.Count > 0) // DebugExtension.DebugLine(optimacedPointList, Colors.Red, Colors.IndianRed); //if (normalizedPointList != null && normalizedPointList.Count > 0) // DebugExtension.DebugLine(normalizedPointList, Colors.LightGreen, Colors.Green); //if (simplifyPointList != null && simplifyPointList.Count > 0) //{ // Vector2 vP = new Vector2(0, 0); // for (int i = 0; i < simplifyPointList.Count; i++) // { // Debug.DrawLine(vP, simplifyPointList[i] + vP, Colors.Blue); // vP = vP + simplifyPointList[i]; // } //} }
private List <Vector2> NormalizeRune(List <Vector2> pointsList) { List <Vector2> normaliced = new List <Vector2>(pointsList); //Normalizamos la posicion Vector2 c = normaliced[0]; for (int i = 0; i < normaliced.Count; i++) { normaliced[i] = normaliced[i] - c; } if (debug) { DebugExtension.DebugLine(normaliced, Colors.LightGreen, 5); } //Normalizamos la rotacion //Sacamos el angulo que hay que rotarlo del original float angle = Vector2.Angle(pointsList[1] - pointsList[0], Vector2.up); if ((pointsList[1] - pointsList[0]).x < 0) { angle = 360 - angle; } //Rotamos la normalizada for (int i = 0; i < normaliced.Count; i++) { normaliced[i] = Rotate(normaliced[i], angle); } if (debug) { DebugExtension.DebugLine(normaliced, Colors.Green, 5); } //Normalizamos la Inversion if ((normaliced[2] - normaliced[1]).x < 0) { for (int i = 0; i < normaliced.Count; i++) { normaliced[i] = new Vector2(-normaliced[i].x, normaliced[i].y); } if (debug) { DebugExtension.DebugLine(normaliced, Colors.DarkGreen, 5); } } return(normaliced); }
private List <Vector2> optimizeGesture(List <Vector2> pointsList)//, List<Vector2> deltaList) { float pD = Screen.width * pointDistance; if (deltaTotal / deltaCount <= pD) { optimizedDistance = new List <Vector2> { pointsList[0] }; for (int i = 1; i < pointsList.Count; ++i) { if (Vector2.Distance(pointsList[i], optimizedDistance[optimizedDistance.Count - 1]) >= pD) { //optimizedDistance.Insert(optimizedDistance.Count - 2, pointsList[i]); optimizedDistance.Add(pointsList[i]); } else if (i == pointsList.Count - 1) { optimizedDistance[optimizedDistance.Count - 1] = pointsList[i]; } } } else { optimizedDistance = pointsList; } //Quitamos los puntos que no creen un cambio de direccion. optimizedDirection = new List <Vector2>(); Vector2 pointA = optimizedDistance[0]; for (int i = 1; i < optimizedDistance.Count - 1; ++i) { if (i >= optimizedDistance.Count - 2 && Vector2.Distance(optimizedDistance[i], pointA) > lineDistance) { optimizedDirection.Add(pointA); optimizedDirection.Add(optimizedDistance[i]); continue; } //if (Vector2.Distance(optimizedDistance[i], pointA) < pointDistance || Vector2.Distance(optimizedDistance[i], optimizedDistance[i + 1]) < pointDistance) // continue; Vector2 AB = optimizedDistance[i] - pointA; Vector2 CB = optimizedDistance[i] - optimizedDistance[i + 1]; float angle = Vector2.Angle(AB, CB); if (angle <= minimumAngle) { if (Vector2.Distance(optimizedDistance[i], pointA) > lineDistance) { optimizedDirection.Add(pointA); optimizedDirection.Add(optimizedDistance[i]); } pointA = optimizedDistance[i]; } } if (optimizedDirection.Count < 3) { return(optimizedDirection); } optimizedIntersection = new List <Vector2> { optimizedDirection[0] }; for (int i = 2; i < optimizedDirection.Count - 1; i += 2) { if (Vector2.Distance(optimizedDirection[i], optimizedDirection[i - 1]) < 1) { optimizedIntersection.Add(optimizedDirection[i]); } else { bool b = false; Vector2 v = GetIntersectionPointCoordinates(optimizedDirection[i - 2], optimizedDirection[i - 1], optimizedDirection[i], optimizedDirection[i + 1], out b); if (b) { optimizedIntersection.Add(v); } } } optimizedIntersection.Add(optimizedDirection[optimizedDirection.Count - 1]); if (debug) { DebugExtension.DebugLine(optimizedDirection, Colors.IndianRed, 5); DebugExtension.DebugLine(optimizedDistance, Colors.Red, 5); foreach (Vector2 v in optimizedIntersection) { DebugExtension.DebugWireSphere(v, Colors.DarkRed, 10, 5); } } return(optimizedIntersection); }