BsHandleSliderPlane.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsHandleSlider.h"
  4. #include "BsRect3.h"
  5. #include "BsVector2.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Handle slider that returns a delta value as you drag the pointer
  10. * along a plane. For intersection purposes the line is internally
  11. * by a quadrilateral (a bounded plane).
  12. */
  13. class BS_ED_EXPORT HandleSliderPlane : public HandleSlider
  14. {
  15. public:
  16. /**
  17. * @brief Constructs a new plane slider. The plane is constructed from two
  18. * direction vectors.
  19. *
  20. * @param dir1 First direction of the plane. The x component of returned delta value will be in
  21. * this direction. Should be perpendicular to \p dir2.
  22. * @param dir2 Second direction of the plane. The y component of returned delta value will be in
  23. * this direction. Should be perpendicular to \p dir1.
  24. * @param length Determines size of the plane.
  25. * @param fixedScale If true the handle slider will always try to maintain the same visible
  26. * area in the viewport regardless of distance from camera.
  27. * @param layer Layer that allows filtering of which sliders are interacted with from a specific camera.
  28. */
  29. HandleSliderPlane(const Vector3& dir1, const Vector3& dir2, float length, bool fixedScale, UINT64 layer);
  30. ~HandleSliderPlane();
  31. /**
  32. * @copydoc HandleSlider::intersects
  33. */
  34. bool intersects(const Ray& ray, float& t) const override;
  35. /**
  36. * @copydoc HandleSlider::handleInput
  37. */
  38. void handleInput(const CameraPtr& camera, const Vector2I& inputDelta) override;
  39. /**
  40. * @brief Returns a delta value that is the result of dragging/sliding the pointer
  41. * along the plane. Returned movement is in terms of the two directions originally provided
  42. * when constructing the slider. This changes every frame and will be zero unless the slider
  43. * is active.
  44. */
  45. Vector2 getDelta() const { return mDelta; }
  46. protected:
  47. /**
  48. * @copydoc HandleSlider::activate
  49. */
  50. void activate(const CameraPtr& camera, const Vector2I& pointerPos) override;
  51. /**
  52. * @copydoc HandleSlider::reset
  53. */
  54. void reset() override { mDelta = Vector2::ZERO; }
  55. /**
  56. * @brief Returns the position on plane based on pointer position.
  57. *
  58. * @param camera Camera we're interacting through.
  59. * @param pointerPos Position of the pointer in pixels relative to the provided camera's viewport.
  60. */
  61. Vector3 getPositionOnPlane(const CameraPtr& camera, const Vector2I& pointerPos) const;
  62. Vector3 mDirection1;
  63. Vector3 mDirection2;
  64. float mLength;
  65. Rect3 mCollider;
  66. Vector2 mDelta;
  67. Vector3 mStartPlanePosition;
  68. Vector3 mStartClickPosition;
  69. };
  70. }