Handles.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. public sealed class Handles
  6. {
  7. public static bool MoveHandleSnapActive
  8. {
  9. get { return EditorSettings.MoveHandleSnapActive; }
  10. set { EditorSettings.MoveHandleSnapActive = value; }
  11. }
  12. public static bool RotateHandleSnapActive
  13. {
  14. get { return EditorSettings.RotateHandleSnapActive; }
  15. set { EditorSettings.RotateHandleSnapActive = value; }
  16. }
  17. public static float MoveSnapAmount
  18. {
  19. get { return EditorSettings.MoveHandleSnapAmount; }
  20. set { EditorSettings.MoveHandleSnapAmount = value; }
  21. }
  22. public static Degree RotateSnapAmount
  23. {
  24. get { return EditorSettings.RotateHandleSnapAmount; }
  25. set { EditorSettings.RotateHandleSnapAmount = value; }
  26. }
  27. public static float SnapValue(float value, float snapAmount)
  28. {
  29. if (snapAmount > 0)
  30. return MathEx.RoundToInt(value / snapAmount) * snapAmount;
  31. return value;
  32. }
  33. public static Degree SnapValue(Degree value, Degree snapAmount)
  34. {
  35. return SnapValue(value.Degrees, snapAmount.Degrees);
  36. }
  37. public static float GetHandleSize(Camera camera, Vector3 position)
  38. {
  39. Vector3 cameraPos = camera.SceneObject.Position;
  40. Vector3 diff = position - cameraPos;
  41. float distAlongViewDir = Math.Abs(Vector3.Dot(diff, camera.SceneObject.Rotation.Forward));
  42. return distAlongViewDir * EditorSettings.DefaultHandleSize;
  43. }
  44. }
  45. }