LightGizmos.cs 3.3 KB

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