private void OnDrawGizmos() { //nodes = new List<Transform>(); //for (int i = 0; i < transform.childCount; i++) //{ // nodes.Add(transform.GetChild(i)); //} if (nodes.Count >= 2) { Transform node1 = nodes[0]; //while (node1 == null) //{ // nodes.RemoveAt(0); // node1 = nodes[0]; //} Transform node2 = nodes[1]; //while (node2 == null) //{ // nodes.RemoveAt(1); // node2 = nodes[1]; //} int k = 0; while (((node1 != nodes[0] || k == 0) && closed) || ((node2 != nodes[0]) && !closed)) { k++; Gizmos.color = Color.white; Vector3 previousPoint = node1.position; for (float i = 0; i <= numberOfPoints; i++) { Vector3 point = Beizer.Coordinates(node1.position, node1.GetChild(node1.childCount - 1).transform.position, node2.GetChild(0).transform.position, node2.position, i / numberOfPoints); Gizmos.DrawLine(previousPoint, point); Gizmos.DrawSphere(previousPoint, 0.1f); previousPoint = point; } DrawAuxiliaryLines(node1); node1 = node2; node2 = nodes[(k + 1) % nodes.Count]; //while (node2 == null) //{ // nodes.RemoveAt((k + 1) % nodes.Count); // node2 = nodes[(k + 1) % nodes.Count]; //} } DrawAuxiliaryLines(node1); } }
// Update is called once per frame void Update() { if (closed) { transform.position = Beizer.Coordinates(nodes[i].position, nodes[i].GetChild(nodes[i].childCount - 1).transform.position, nodes[(i+1)%nodes.Count].GetChild(0).transform.position, nodes[(i + 1) % nodes.Count].position, t)+deviation; transform.rotation = Quaternion.LookRotation(Beizer.firstDerivative(nodes[i].position, nodes[i].GetChild(nodes[i].childCount - 1).transform.position, nodes[(i + 1) % nodes.Count].GetChild(0).transform.position, nodes[(i + 1) % nodes.Count].position, t)); transform.Rotate(new Vector3(0, 1, 0), rotationY); /* * Равномерное движение if (uniformMotion) { oldPosition = transform.position; newPosition = Beizer.Coordinates(nodes[i].position, nodes[i].GetChild(nodes[i].childCount - 1).transform.position, nodes[(i + 1) % nodes.Count].GetChild(0).transform.position, nodes[(i + 1) % nodes.Count].position, t + speed); deltaPosition = Mathf.Sqrt(Mathf.Pow(newPosition.x - oldPosition.x, 2) + Mathf.Pow(newPosition.y - oldPosition.y, 2) + Mathf.Pow(newPosition.z - oldPosition.z, 2)); if (firstDeltaPosition != 0) { Debug.Log("DELTA " + deltaPosition); Debug.Log("DELTA FIRST " + firstDeltaPosition); if (deltaPosition > 1) { Debug.Log("!!!" + deltaPosition); } speed = (firstDeltaPosition / deltaPosition) * speed; } else firstDeltaPosition = deltaPosition; } */ t += speed; while (t > 1) { t--; i = (i + 1) % nodes.Count; } } }
public Vector3 GetVelocity(float t) { return(transform.TransformPoint(Beizer.GetFirstDerivative(points[0], points[1], points[2], t)) - transform.position); }
public Vector3 GetPoint(float t) { return(Beizer.GetPoint(points[0], points[1], points[2], t)); }
public Vector3 GetPoint(float t) { return(transform.TransformPoint(Beizer.GetPoint(points[0], points[1], points[2], t))); }