MoveHandle.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using BansheeEngine;
  2. namespace BansheeEditor
  3. {
  4. public sealed class MoveHandle : DefaultHandle
  5. {
  6. private const float CONE_HEIGHT = 0.05f;
  7. private const float CONE_RADIUS = 0.05f;
  8. private Vector3 delta;
  9. private HandleSliderLine xAxis;
  10. private HandleSliderLine yAxis;
  11. private HandleSliderLine zAxis;
  12. public Vector3 Delta
  13. {
  14. get { return delta; }
  15. }
  16. public MoveHandle()
  17. {
  18. xAxis = new HandleSliderLine(this, Vector3.xAxis, 1.0f);
  19. yAxis = new HandleSliderLine(this, Vector3.yAxis, 1.0f);
  20. zAxis = new HandleSliderLine(this, Vector3.zAxis, 1.0f);
  21. }
  22. protected override void PreInput()
  23. {
  24. xAxis.Position = position;
  25. yAxis.Position = position;
  26. zAxis.Position = position;
  27. xAxis.Rotation = rotation;
  28. yAxis.Rotation = rotation;
  29. zAxis.Rotation = rotation;
  30. }
  31. protected override void PostInput()
  32. {
  33. delta = Vector3.zero;
  34. delta += xAxis.Delta * GetXDir();
  35. delta += yAxis.Delta * GetYDir();
  36. delta += zAxis.Delta * GetZDir();
  37. }
  38. protected override void Draw()
  39. {
  40. Vector3 center = position;
  41. Vector3 xEnd = center + GetXDir();
  42. Vector3 yEnd = center + GetYDir();
  43. Vector3 zEnd = center + GetZDir();
  44. if (xAxis.State == HandleSlider.StateType.Active)
  45. HandleDrawing.SetColor(Color.white);
  46. else if(xAxis.State == HandleSlider.StateType.Hover)
  47. HandleDrawing.SetColor(Color.red * 0.8f);
  48. else
  49. HandleDrawing.SetColor(Color.red);
  50. HandleDrawing.DrawLine(center, xEnd);
  51. HandleDrawing.DrawCone(xEnd - GetXDir()*CONE_HEIGHT, GetXDir(), CONE_HEIGHT, CONE_RADIUS);
  52. if (yAxis.State == HandleSlider.StateType.Active)
  53. HandleDrawing.SetColor(Color.white);
  54. else if (yAxis.State == HandleSlider.StateType.Hover)
  55. HandleDrawing.SetColor(Color.green * 0.8f);
  56. else
  57. HandleDrawing.SetColor(Color.green);
  58. HandleDrawing.DrawLine(center, yEnd);
  59. HandleDrawing.DrawCone(yEnd - GetYDir() * CONE_HEIGHT, GetYDir(), CONE_HEIGHT, CONE_RADIUS);
  60. if (zAxis.State == HandleSlider.StateType.Active)
  61. HandleDrawing.SetColor(Color.white);
  62. else if (zAxis.State == HandleSlider.StateType.Hover)
  63. HandleDrawing.SetColor(Color.blue * 0.8f);
  64. else
  65. HandleDrawing.SetColor(Color.blue);
  66. HandleDrawing.DrawLine(center, zEnd);
  67. HandleDrawing.DrawCone(zEnd - GetZDir() * CONE_HEIGHT, GetZDir(), CONE_HEIGHT, CONE_RADIUS);
  68. }
  69. private Vector3 GetXDir()
  70. {
  71. return rotation.Rotate(Vector3.xAxis);
  72. }
  73. private Vector3 GetYDir()
  74. {
  75. return rotation.Rotate(Vector3.yAxis);
  76. }
  77. private Vector3 GetZDir()
  78. {
  79. return rotation.Rotate(Vector3.zAxis);
  80. }
  81. }
  82. }