| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include "BsHandleSliderPlane.h"
- #include "BsHandleManager.h"
- #include "BsHandleSliderManager.h"
- #include "BsVector3.h"
- #include "BsRay.h"
- namespace BansheeEngine
- {
- HandleSliderPlane::HandleSliderPlane(const Vector3& dir1, const Vector3& dir2, float length, bool fixedScale)
- :HandleSlider(fixedScale), mLength(length)
- {
- mDirection1 = Vector3::normalize(dir1);
- mDirection2 = Vector3::normalize(dir2);
- float halfLength = length * 0.5f;
- std::array<Vector3, 2> axes = { mDirection1, mDirection2 };
- std::array<float, 2> extents = { halfLength, halfLength };
- Vector3 center = (dir1 * length + dir2 * length) * 0.5f;
- mCollider = Rect3(center, axes, extents);
- HandleSliderManager& sliderManager = HandleManager::instance().getSliderManager();
- sliderManager._registerSlider(this);
- }
- HandleSliderPlane::~HandleSliderPlane()
- {
- HandleSliderManager& sliderManager = HandleManager::instance().getSliderManager();
- sliderManager._unregisterSlider(this);
- }
- bool HandleSliderPlane::intersects(const Ray& ray, float& t) const
- {
- Ray localRay = ray;
- localRay.transform(getTransformInv());
- auto intersect = mCollider.intersects(localRay);
- if (intersect.first)
- {
- t = intersect.second;
- return true;
- }
- return false;
- }
- void HandleSliderPlane::handleInput(const CameraHandlerPtr& camera, const Vector2I& inputDelta)
- {
- assert(getState() == State::Active);
- mCurrentPointerPos += inputDelta;
- Vector3 worldDir1 = getRotation().rotate(mDirection1);
- Vector3 worldDir2 = getRotation().rotate(mDirection2);
- mDelta.x = calcDelta(camera, mStartPosition, worldDir1, mStartPointerPos, mCurrentPointerPos);
- mDelta.y = calcDelta(camera, mStartPosition, worldDir2, mStartPointerPos, mCurrentPointerPos);
- }
- }
|