BsHandleSliderDisc.h 3.7 KB

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