static void DrawRotateGizmo(Transform objectToRotate, Vector3 point, float angle, Vector3 axis, float halfAxisLenght, float offset, bool showPoints) { if (!objectToRotate) { return; } Vector3 binormal = Vector3.zero; Vector3 tangent = Vector3.zero; Vector3.OrthoNormalize(ref axis, ref binormal, ref tangent); Vector3 directionFromPointToObject = point - objectToRotate.position; Vector3 distanceBetweenPointAndPivotBelongAxis = Vector3.Project(directionFromPointToObject, axis.normalized); Vector3 pivot = point - distanceBetweenPointAndPivotBelongAxis; Quaternion pendicularQ0 = Quaternion.AngleAxis(0, -axis.normalized); Quaternion pendicularQ90 = Quaternion.AngleAxis(90, -axis.normalized); float radius = (objectToRotate.position - pivot).magnitude + offset; Vector3 dir = axis.normalized; Color startColor = ColorsAndDirections.GetColors((BaseVectorDirection)0) [0]; Color endColor = ColorsAndDirections.GetColors((BaseVectorDirection)7) [1]; int iterations = 200; List <Quaternion> points = new List <Quaternion> (iterations); List <Color> colors = new List <Color> (iterations); Vector3 direction = binormal; Gizmos.DrawRay(pivot - axis.normalized * halfAxisLenght * halfAxisLenght, axis.normalized * halfAxisLenght * halfAxisLenght * 2); for (int i = 0; i < iterations; i++) { float t = i * 4 / (float)iterations; points.Add(Quaternion.SlerpUnclamped(pendicularQ0, pendicularQ0 * pendicularQ90, t)); colors.Add(Color.Lerp(startColor, endColor, t * 0.25f)); } for (int i = 0; i < iterations - 1; i++) { if (i % 2 == 0) { Gizmos.color = colors [i]; Gizmos.DrawLine(pivot + points [i] * direction * radius, pivot + points [i + 1] * direction * radius); } } if (showPoints) { GizmosForVector.ShowVectorValue(point, "point", point, Color.red); GizmosForVector.ShowVectorValue(pivot, "pivot", pivot, Color.green); Gizmos.color = Color.red; Gizmos.DrawSphere(point, 0.2f); Gizmos.color = Color.green; Gizmos.DrawSphere(pivot, 0.2f); } }
public static void LookAt(Transform origin, Vector3 worldPosition, Vector3 worldUp = default(Vector3), float lenght = 5) { if (!origin) { return; } worldUp = worldUp == default(Vector3) ? Vector3.up : worldUp; Vector3 originV = origin.position; Vector3 forwardDirection = worldPosition - originV; GizmosForQuaternion.LookRotation(originV, forwardDirection, worldUp, lenght); GizmosForVector.ShowVectorValue(worldPosition, "worldPosition", worldPosition, Color.red); Color temp = Gizmos.color; Gizmos.color = Color.red; Gizmos.DrawSphere(worldPosition, 0.2f); Gizmos.color = temp; }