BsHandleSliderPlane.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "BsHandleSliderPlane.h"
  2. #include "BsHandleManager.h"
  3. #include "BsHandleSliderManager.h"
  4. #include "BsVector3.h"
  5. #include "BsRay.h"
  6. namespace BansheeEngine
  7. {
  8. HandleSliderPlane::HandleSliderPlane(const Vector3& dir1, const Vector3& dir2, float length, bool fixedScale)
  9. :HandleSlider(fixedScale), mLength(length)
  10. {
  11. mDirection1 = Vector3::normalize(dir1);
  12. mDirection2 = Vector3::normalize(dir2);
  13. float halfLength = length * 0.5f;
  14. std::array<Vector3, 2> axes = { mDirection1, mDirection2 };
  15. std::array<float, 2> extents = { halfLength, halfLength };
  16. Vector3 center = (dir1 * length + dir2 * length) * 0.5f;
  17. mCollider = Rect3(center, axes, extents);
  18. HandleSliderManager& sliderManager = HandleManager::instance().getSliderManager();
  19. sliderManager._registerSlider(this);
  20. }
  21. HandleSliderPlane::~HandleSliderPlane()
  22. {
  23. HandleSliderManager& sliderManager = HandleManager::instance().getSliderManager();
  24. sliderManager._unregisterSlider(this);
  25. }
  26. bool HandleSliderPlane::intersects(const Ray& ray, float& t) const
  27. {
  28. Ray localRay = ray;
  29. localRay.transform(getTransformInv());
  30. auto intersect = mCollider.intersects(localRay);
  31. if (intersect.first)
  32. {
  33. t = intersect.second;
  34. return true;
  35. }
  36. return false;
  37. }
  38. void HandleSliderPlane::handleInput(const CameraHandlerPtr& camera, const Vector2I& inputDelta)
  39. {
  40. assert(getState() == State::Active);
  41. mCurrentPointerPos += inputDelta;
  42. Vector3 worldDir1 = getRotation().rotate(mDirection1);
  43. Vector3 worldDir2 = getRotation().rotate(mDirection2);
  44. mDelta.x = calcDelta(camera, mStartPosition, worldDir1, mStartPointerPos, mCurrentPointerPos);
  45. mDelta.y = calcDelta(camera, mStartPosition, worldDir2, mStartPointerPos, mCurrentPointerPos);
  46. }
  47. }