BsHandleSliderDisc.h 3.7 KB

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