BsHandleSliderDisc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * @param layer Layer that allows filtering of which sliders are interacted with from a specific camera.
  23. */
  24. HandleSliderDisc(const Vector3& normal, float radius, bool fixedScale, UINT64 layer);
  25. ~HandleSliderDisc();
  26. /**
  27. * @copydoc HandleSlider::intersects
  28. */
  29. bool intersects(const Ray& ray, float& t) const override;
  30. /**
  31. * @copydoc HandleSlider::handleInput
  32. */
  33. void handleInput(const CameraPtr& camera, const Vector2I& inputDelta) override;
  34. /**
  35. * @brief Enables or disables a cut-off plane that can allow the disc to be intersected
  36. * with only in an 180 degree arc.
  37. *
  38. * @param angle Angle at which to start the cut-off. Points on the dist at the specified angle and the next
  39. * 180 degrees won't be interactable.
  40. */
  41. void setCutoffPlane(Degree angle, bool enabled);
  42. /**
  43. * @brief Returns a delta value that is the result of dragging/sliding the pointer
  44. * along the disc. This changes every frame and will be zero unless the slider is active.
  45. */
  46. Radian getDelta() const { return mDelta; }
  47. /**
  48. * @brief Gets the initial angle at which the drag/slide operation started. This is only
  49. * valid when the slider is active.
  50. */
  51. Radian getStartAngle() const { return mStartAngle; }
  52. protected:
  53. /**
  54. * @copydoc HandleSlider::activate
  55. */
  56. void activate(const CameraPtr& camera, const Vector2I& pointerPos) override;
  57. /**
  58. * @copydoc HandleSlider::reset
  59. */
  60. void reset() override { mDelta = 0.0f; }
  61. /**
  62. * @brief Calculates the closest point on an arc from a ray.
  63. *
  64. * @param inputRay Ray to use for determining the point.
  65. * @param center Center of the arc.
  66. * @param up Normal vector of the arc. Must be normalized.
  67. * @param radius Radius of the arc.
  68. * @param startAngle Starting angle of the arc.
  69. * @param angleAmount Length of the arc.
  70. *
  71. * @return A point on the arc closest to the provided ray.
  72. */
  73. Vector3 calculateClosestPointOnArc(const Ray& inputRay, const Vector3& center, const Vector3& up,
  74. float radius, Degree startAngle, Degree angleAmount);
  75. /**
  76. * @brief Determines an angle of a point on a circle.
  77. *
  78. * @param up Normal vector of the circle. Must be normalized.
  79. * @param point Point to try to find the angle for. Caller must ensure the
  80. * point is actually somewhere on the circle otherwise the result
  81. * is undefined.
  82. *
  83. * @return Angle at which the provided point lies on the circle.
  84. */
  85. Degree pointOnCircleToAngle(Vector3 up, Vector3 point);
  86. static const float TORUS_RADIUS;
  87. Vector3 mNormal;
  88. float mRadius;
  89. bool mHasCutoffPlane;
  90. Plane mCutoffPlane;
  91. Vector3 mDirection;
  92. Vector3 mStartPosition;
  93. Degree mStartAngle;
  94. Degree mDelta;
  95. Torus mCollider;
  96. };
  97. }