LightGizmos.cs 3.3 KB

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