BsHandleSliderPlane.h 2.9 KB

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