CharacterControllerGizmo.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  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="CharacterController"/> component.
  8. /// </summary>
  9. internal class CharacterControllerGizmo
  10. {
  11. /// <summary>
  12. /// Method called by the runtime when gizmos are meant to be drawn.
  13. /// </summary>
  14. /// <param name="controller">Collider to draw gizmos for.</param>
  15. [DrawGizmo(DrawGizmoFlags.Selected)]
  16. private static void Draw(CharacterController controller)
  17. {
  18. SceneObject so = controller.SceneObject;
  19. Quaternion rotation = Quaternion.FromToRotation(Vector3.YAxis, controller.Up);
  20. // Rotate around origin
  21. Matrix4 rotMatrix = Matrix4.TRS(Vector3.Zero, rotation, Vector3.One);
  22. Gizmos.Color = Color.Green;
  23. Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One) * rotMatrix;
  24. Vector3 scale = so.Scale;
  25. float scaledHeight = controller.Height * 2.0f * scale.y;
  26. float scaledRadius = controller.Radius * MathEx.Max(scale.x, scale.z);
  27. Gizmos.DrawWireCapsule(Vector3.Zero, scaledHeight, scaledRadius);
  28. }
  29. }
  30. }