Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save INeatFreak/175e229da2fe35a7e13483445d02d44a to your computer and use it in GitHub Desktop.
Save INeatFreak/175e229da2fe35a7e13483445d02d44a to your computer and use it in GitHub Desktop.
Draws camera oriented wire sphere using Handles.
void DrawCameraOrientedWireSphere(Vector3 position, float radius, Color color) {
UnityEditor.Handles.matrix = Matrix4x4.TRS(Vector3.zero, transform.rotation, Vector3.one);
UnityEditor.Handles.color = color;
UnityEditor.Handles.DrawWireDisc(position, Vector3.right, radius);
UnityEditor.Handles.DrawWireDisc(position, Vector3.up, radius);
UnityEditor.Handles.DrawWireDisc(position, Vector3.forward, radius);
if(Camera.current.orthographic) {
Vector3 normal = position - UnityEditor.Handles.inverseMatrix.MultiplyVector(Camera.current.transform.forward);
float sqrMagnitude = normal.sqrMagnitude;
float num0 = radius * radius;
UnityEditor.Handles.DrawWireDisc(position - num0 * normal / sqrMagnitude, normal, radius);
} else {
Vector3 normal = position - UnityEditor.Handles.inverseMatrix.MultiplyPoint(Camera.current.transform.position);
float sqrMagnitude = normal.sqrMagnitude;
float num0 = radius * radius;
float num1 = num0 * num0 / sqrMagnitude;
float num2 = Mathf.Sqrt(num0 - num1);
UnityEditor.Handles.DrawWireDisc(position - num0 * normal / sqrMagnitude, normal, num2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment