BsHandleSliderDisc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 CameraHandlerPtr& 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. (i.e. the plane will contain points
  38. * on the disc at angle and (angle + pi) and anything between those two angles
  39. * wont be interactable.
  40. *
  41. */
  42. void setCutoffPlane(Degree angle, bool enabled);
  43. /**
  44. * @brief Returns a delta value that is the result of dragging/sliding the pointer
  45. * along the disc. This changes every frame and will be zero unless the slider is active.
  46. */
  47. Radian getDelta() const { return mDelta; }
  48. /**
  49. * @brief Gets the initial angle at which the drag/slide operation started. This is only
  50. * valid when the slider is active.
  51. */
  52. Radian getStartAngle() const { return mStartAngle; }
  53. protected:
  54. /**
  55. * @copydoc HandleSlider::activate
  56. */
  57. void activate(const CameraHandlerPtr& camera, const Vector2I& pointerPos) override;
  58. /**
  59. * @copydoc HandleSlider::reset
  60. */
  61. void reset() override { mDelta = 0.0f; }
  62. /**
  63. * @brief Calculates the closest point on an arc from a ray.
  64. *
  65. * @param inputRay Ray to use for determining the point.
  66. * @param center Center of the arc.
  67. * @param up Normal vector of the arc. Must be normalized.
  68. * @param radius Radius of the arc.
  69. * @param startAngle Starting angle of the arc.
  70. * @param angleAmount Length of the arc.
  71. *
  72. * @return A point on the arc closest to the provided ray.
  73. */
  74. Vector3 calculateClosestPointOnArc(const Ray& inputRay, const Vector3& center, const Vector3& up,
  75. float radius, Degree startAngle, Degree angleAmount);
  76. /**
  77. * @brief Determines an angle of a point on a circle.
  78. *
  79. * @param up Normal vector of the circle. Must be normalized.
  80. * @param point Point to try to find the angle for. Caller must ensure the
  81. * point is actually somewhere on the circle otherwise the result
  82. * is undefined.
  83. *
  84. * @return Angle at which the provided point lies on the circle.
  85. */
  86. Degree pointOnCircleToAngle(Vector3 up, Vector3 point);
  87. static const float TORUS_RADIUS;
  88. Vector3 mNormal;
  89. float mRadius;
  90. bool mHasCutoffPlane;
  91. Plane mCutoffPlane;
  92. Vector3 mDirection;
  93. Vector3 mStartPosition;
  94. Degree mStartAngle;
  95. Degree mDelta;
  96. Torus mCollider;
  97. };
  98. }