BsHandleSliderPlane.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. std::array<Vector3, 2> axes = { mDirection1, mDirection2 };
  14. std::array<float, 2> extents = { length, length };
  15. mCollider = Rect3(Vector3::ZERO, axes, extents);
  16. HandleSliderManager& sliderManager = HandleManager::instance().getSliderManager();
  17. sliderManager._registerSlider(this);
  18. }
  19. HandleSliderPlane::~HandleSliderPlane()
  20. {
  21. HandleSliderManager& sliderManager = HandleManager::instance().getSliderManager();
  22. sliderManager._unregisterSlider(this);
  23. }
  24. bool HandleSliderPlane::intersects(const Ray& ray, float& t) const
  25. {
  26. Ray localRay = ray;
  27. localRay.transform(getTransformInv());
  28. auto intersect = mCollider.intersects(localRay);
  29. if (intersect.first)
  30. {
  31. t = intersect.second;
  32. return true;
  33. }
  34. return false;
  35. }
  36. void HandleSliderPlane::handleInput(const CameraHandlerPtr& camera, const Vector2I& inputDelta)
  37. {
  38. assert(getState() == State::Active);
  39. mCurrentPointerPos += inputDelta;
  40. Vector3 worldDir1 = getRotation().rotate(mDirection1);
  41. Vector3 worldDir2 = getRotation().rotate(mDirection2);
  42. mDelta.x = calcDelta(camera, mStartPosition, worldDir1, mStartPointerPos, mCurrentPointerPos);
  43. mDelta.y = calcDelta(camera, mStartPosition, worldDir2, mStartPointerPos, mCurrentPointerPos);
  44. }
  45. }