CharacterControllerGizmo.cs 1.5 KB

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