Handles.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 bool ScaleHandleSnapActive
  18. {
  19. get { return EditorSettings.ScaleHandleSnapActive; }
  20. set { EditorSettings.ScaleHandleSnapActive = value; }
  21. }
  22. public static float MoveSnapAmount
  23. {
  24. get { return EditorSettings.MoveHandleSnapAmount; }
  25. set { EditorSettings.MoveHandleSnapAmount = value; }
  26. }
  27. public static Degree RotateSnapAmount
  28. {
  29. get { return EditorSettings.RotateHandleSnapAmount; }
  30. set { EditorSettings.RotateHandleSnapAmount = value.GetDegrees(); }
  31. }
  32. public static float ScaleSnapAmount
  33. {
  34. get { return EditorSettings.ScaleHandleSnapAmount; }
  35. set { EditorSettings.MoveHandleSnapAmount = value; }
  36. }
  37. public static float SnapValue(float value, float snapAmount)
  38. {
  39. if (snapAmount > 0)
  40. return MathEx.RoundToInt(value / snapAmount) * snapAmount;
  41. return value;
  42. }
  43. public static float GetHandleSize(Camera camera, Vector3 position)
  44. {
  45. Vector3 cameraPos = camera.sceneObject.position;
  46. Vector3 diff = position - cameraPos;
  47. float distAlongViewDir = Math.Abs(Vector3.Dot(diff, camera.sceneObject.rotation.Forward));
  48. return distAlongViewDir * EditorSettings.DefaultHandleSize;
  49. }
  50. }
  51. }