BsHandleSliderPlane.h 2.9 KB

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