CharacterControllerGizmo.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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. Vector3 offset = so.Position;
  20. Quaternion rotation = Quaternion.FromToRotation(Vector3.YAxis, controller.Up);
  21. // Rotate around origin
  22. Matrix4 rotMatrix = Matrix4.TRS(offset, Quaternion.Identity, Vector3.One) *
  23. Matrix4.TRS(Vector3.Zero, rotation, Vector3.One) *
  24. Matrix4.TRS(-offset, Quaternion.Identity, Vector3.One);
  25. Gizmos.Color = Color.Green;
  26. Gizmos.Transform = so.WorldTransform * rotMatrix;
  27. Gizmos.DrawWireCapsule(offset, controller.Height, controller.Radius);
  28. }
  29. }
  30. }