LightGizmos.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using BansheeEngine;
  2. namespace BansheeEditor
  3. {
  4. /// <summary>
  5. /// Handles drawing of gizmos for the <see cref="Light"/> component.
  6. /// </summary>
  7. internal class LightGizmos
  8. {
  9. /// <summary>
  10. /// Method called by the runtime when gizmos are meant to be drawn.
  11. /// </summary>
  12. /// <param name="light">Light to draw gizmos for.</param>
  13. [DrawGizmo(DrawGizmoFlags.Selected)]
  14. private static void Draw(Light light)
  15. {
  16. Vector3 position = light.SceneObject.Position;
  17. Gizmos.Color = Color.Yellow;
  18. switch (light.Type)
  19. {
  20. case LightType.Directional:
  21. {
  22. Vector3 right = light.SceneObject.Rotation.Rotate(Vector3.XAxis);
  23. Vector3 up = light.SceneObject.Rotation.Rotate(Vector3.YAxis);
  24. Vector3 forward = light.SceneObject.Forward;
  25. Vector3 topLeft = position - right + up;
  26. Vector3 topRight = position + right + up;
  27. Vector3 botLeft = position - right - up;
  28. Vector3 botRight = position + right - up;
  29. Gizmos.DrawLine(topLeft, topRight);
  30. Gizmos.DrawLine(topRight, botRight);
  31. Gizmos.DrawLine(botRight, botLeft);
  32. Gizmos.DrawLine(botLeft, topLeft);
  33. Gizmos.DrawLine(topLeft, topLeft + forward*5.0f);
  34. Gizmos.DrawLine(topRight, topRight + forward*5.0f);
  35. Gizmos.DrawLine(botRight, botRight + forward*5.0f);
  36. Gizmos.DrawLine(botLeft, botLeft + forward*5.0f);
  37. }
  38. break;
  39. case LightType.Point:
  40. Gizmos.DrawWireSphere(position, light.Range);
  41. break;
  42. case LightType.Spot:
  43. {
  44. Vector3 right = light.SceneObject.Rotation.Rotate(Vector3.XAxis);
  45. Vector3 up = light.SceneObject.Rotation.Rotate(Vector3.YAxis);
  46. Vector3 forward = light.SceneObject.Forward;
  47. float discRadius = light.Range*MathEx.Tan(light.SpotAngle*0.5f);
  48. Gizmos.DrawLine(position, position + forward * light.Range + up * discRadius);
  49. Gizmos.DrawLine(position, position + forward * light.Range - up * discRadius);
  50. Gizmos.DrawLine(position, position + forward * light.Range + right * discRadius);
  51. Gizmos.DrawLine(position, position + forward * light.Range - right * discRadius);
  52. float falloffDiscRadius = light.Range * MathEx.Tan(light.SpotFalloffAngle * 0.5f);
  53. Gizmos.DrawWireDisc(position + forward * light.Range, forward, discRadius);
  54. Gizmos.DrawWireDisc(position + forward * light.Range, forward, falloffDiscRadius);
  55. }
  56. break;
  57. }
  58. }
  59. }
  60. }