BsHandleSliderPlane.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. */
  28. HandleSliderPlane(const Vector3& dir1, const Vector3& dir2, float length, bool fixedScale);
  29. ~HandleSliderPlane();
  30. /**
  31. * @copydoc HandleSlider::intersects
  32. */
  33. bool intersects(const Ray& ray, float& t) const override;
  34. /**
  35. * @copydoc HandleSlider::handleInput
  36. */
  37. void handleInput(const CameraPtr& camera, const Vector2I& inputDelta) override;
  38. /**
  39. * @brief Returns a delta value that is the result of dragging/sliding the pointer
  40. * along the plane. Returned movement is in terms of the two directions originally provided
  41. * when constructing the slider. This changes every frame and will be zero unless the slider
  42. * is active.
  43. */
  44. Vector2 getDelta() const { return mDelta; }
  45. protected:
  46. /**
  47. * @copydoc HandleSlider::activate
  48. */
  49. void activate(const CameraPtr& camera, const Vector2I& pointerPos) override;
  50. /**
  51. * @copydoc HandleSlider::reset
  52. */
  53. void reset() override { mDelta = Vector2::ZERO; }
  54. /**
  55. * @brief Returns the position on plane based on pointer position.
  56. *
  57. * @param camera Camera we're interacting through.
  58. * @param pointerPos Position of the pointer in pixels relative to the provided camera's viewport.
  59. */
  60. Vector3 getPositionOnPlane(const CameraPtr& camera, const Vector2I& pointerPos) const;
  61. Vector3 mDirection1;
  62. Vector3 mDirection2;
  63. float mLength;
  64. Rect3 mCollider;
  65. Vector2 mDelta;
  66. Vector3 mStartPlanePosition;
  67. Vector3 mStartClickPosition;
  68. };
  69. }