| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using BansheeEngine;
- namespace BansheeEditor
- {
- /// <summary>
- /// Handles drawing of gizmos for the <see cref="Light"/> component.
- /// </summary>
- internal class LightGizmos
- {
- /// <summary>
- /// Method called by the runtime when gizmos are meant to be drawn.
- /// </summary>
- /// <param name="light">Light to draw gizmos for.</param>
- [DrawGizmo(DrawGizmoFlags.Selected)]
- private static void Draw(Light light)
- {
- Vector3 position = light.SceneObject.Position;
- Gizmos.Color = Color.Yellow;
- switch (light.Type)
- {
- case LightType.Directional:
- {
- Vector3 right = light.SceneObject.Rotation.Rotate(Vector3.XAxis);
- Vector3 up = light.SceneObject.Rotation.Rotate(Vector3.YAxis);
- Vector3 forward = light.SceneObject.Forward;
- Vector3 topLeft = position - right + up;
- Vector3 topRight = position + right + up;
- Vector3 botLeft = position - right - up;
- Vector3 botRight = position + right - up;
- Gizmos.DrawLine(topLeft, topRight);
- Gizmos.DrawLine(topRight, botRight);
- Gizmos.DrawLine(botRight, botLeft);
- Gizmos.DrawLine(botLeft, topLeft);
- Gizmos.DrawLine(topLeft, topLeft + forward*5.0f);
- Gizmos.DrawLine(topRight, topRight + forward*5.0f);
- Gizmos.DrawLine(botRight, botRight + forward*5.0f);
- Gizmos.DrawLine(botLeft, botLeft + forward*5.0f);
- }
- break;
- case LightType.Point:
- Gizmos.DrawWireSphere(position, light.Range);
- break;
- case LightType.Spot:
- {
- Vector3 right = light.SceneObject.Rotation.Rotate(Vector3.XAxis);
- Vector3 up = light.SceneObject.Rotation.Rotate(Vector3.YAxis);
- Vector3 forward = light.SceneObject.Forward;
- float discRadius = light.Range*MathEx.Tan(light.SpotAngle*0.5f);
- Gizmos.DrawLine(position, position + forward * light.Range + up * discRadius);
- Gizmos.DrawLine(position, position + forward * light.Range - up * discRadius);
- Gizmos.DrawLine(position, position + forward * light.Range + right * discRadius);
- Gizmos.DrawLine(position, position + forward * light.Range - right * discRadius);
- float falloffDiscRadius = light.Range * MathEx.Tan(light.SpotFalloffAngle * 0.5f);
- Gizmos.DrawWireDisc(position + forward * light.Range, forward, discRadius);
- Gizmos.DrawWireDisc(position + forward * light.Range, forward, falloffDiscRadius);
- }
- break;
- }
- }
- }
- }
|