LightGizmos.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.Radial:
  45. Gizmos.DrawWireSphere(position, light.AttenuationRadius);
  46. if (light.SourceRadius > 0.0f)
  47. {
  48. Gizmos.Color = light.Color;
  49. Gizmos.DrawSphere(position, light.SourceRadius);
  50. }
  51. break;
  52. case LightType.Spot:
  53. {
  54. Vector3 right = light.SceneObject.Rotation.Rotate(Vector3.XAxis);
  55. Vector3 up = light.SceneObject.Rotation.Rotate(Vector3.YAxis);
  56. Vector3 forward = light.SceneObject.Forward;
  57. float discRadius = light.AttenuationRadius * MathEx.Tan(light.SpotAngle * 0.5f);
  58. Gizmos.DrawLine(position, position + forward * light.AttenuationRadius + up * discRadius);
  59. Gizmos.DrawLine(position, position + forward * light.AttenuationRadius - up * discRadius);
  60. Gizmos.DrawLine(position, position + forward * light.AttenuationRadius + right * discRadius);
  61. Gizmos.DrawLine(position, position + forward * light.AttenuationRadius - right * discRadius);
  62. float falloffDiscRadius = light.AttenuationRadius * MathEx.Tan(light.SpotAngleFalloff * 0.5f);
  63. Gizmos.DrawWireDisc(position + forward * light.AttenuationRadius, forward, discRadius);
  64. Gizmos.DrawWireDisc(position + forward * light.AttenuationRadius, forward, falloffDiscRadius);
  65. if (light.SourceRadius > 0.0f)
  66. {
  67. Gizmos.Color = light.Color;
  68. Gizmos.DrawDisc(position, forward, light.SourceRadius);
  69. }
  70. }
  71. break;
  72. }
  73. }
  74. }
  75. /** @} */
  76. }