BsHandleSliderDisc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsHandleSlider.h"
  4. #include "BsTorus.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Handle slider that returns a delta value as you drag the pointer
  9. * along a disc. For intersection purposes the disc is internally
  10. * represented by a torus.
  11. */
  12. class BS_ED_EXPORT HandleSliderDisc : public HandleSlider
  13. {
  14. public:
  15. /**
  16. * @brief Constructs a new disc slider.
  17. *
  18. * @param normal Normal that determines the orientation of the disc.
  19. * @param radius Radius of the disc.
  20. * @param fixedScale If true the handle slider will always try to maintain the same visible
  21. * area in the viewport regardless of distance from camera.
  22. */
  23. HandleSliderDisc(const Vector3& normal, float radius, bool fixedScale);
  24. ~HandleSliderDisc();
  25. /**
  26. * @copydoc HandleSlider::intersects
  27. */
  28. bool intersects(const Ray& ray, float& t) const override;
  29. /**
  30. * @copydoc HandleSlider::handleInput
  31. */
  32. void handleInput(const CameraPtr& camera, const Vector2I& inputDelta) override;
  33. /**
  34. * @brief Enables or disables a cut-off plane that can allow the disc to be intersected
  35. * with only in an 180 degree arc.
  36. *
  37. * @param angle Angle at which to start the cut-off. Points on the dist at the specified angle and the next
  38. * 180 degrees won't be interactable.
  39. */
  40. void setCutoffPlane(Degree angle, bool enabled);
  41. /**
  42. * @brief Returns a delta value that is the result of dragging/sliding the pointer
  43. * along the disc. This changes every frame and will be zero unless the slider is active.
  44. */
  45. Radian getDelta() const { return mDelta; }
  46. /**
  47. * @brief Gets the initial angle at which the drag/slide operation started. This is only
  48. * valid when the slider is active.
  49. */
  50. Radian getStartAngle() const { return mStartAngle; }
  51. protected:
  52. /**
  53. * @copydoc HandleSlider::activate
  54. */
  55. void activate(const CameraPtr& camera, const Vector2I& pointerPos) override;
  56. /**
  57. * @copydoc HandleSlider::reset
  58. */
  59. void reset() override { mDelta = 0.0f; }
  60. /**
  61. * @brief Calculates the closest point on an arc from a ray.
  62. *
  63. * @param inputRay Ray to use for determining the point.
  64. * @param center Center of the arc.
  65. * @param up Normal vector of the arc. Must be normalized.
  66. * @param radius Radius of the arc.
  67. * @param startAngle Starting angle of the arc.
  68. * @param angleAmount Length of the arc.
  69. *
  70. * @return A point on the arc closest to the provided ray.
  71. */
  72. Vector3 calculateClosestPointOnArc(const Ray& inputRay, const Vector3& center, const Vector3& up,
  73. float radius, Degree startAngle, Degree angleAmount);
  74. /**
  75. * @brief Determines an angle of a point on a circle.
  76. *
  77. * @param up Normal vector of the circle. Must be normalized.
  78. * @param point Point to try to find the angle for. Caller must ensure the
  79. * point is actually somewhere on the circle otherwise the result
  80. * is undefined.
  81. *
  82. * @return Angle at which the provided point lies on the circle.
  83. */
  84. Degree pointOnCircleToAngle(Vector3 up, Vector3 point);
  85. static const float TORUS_RADIUS;
  86. Vector3 mNormal;
  87. float mRadius;
  88. bool mHasCutoffPlane;
  89. Plane mCutoffPlane;
  90. Vector3 mDirection;
  91. Vector3 mStartPosition;
  92. Degree mStartAngle;
  93. Degree mDelta;
  94. Torus mCollider;
  95. };
  96. }