瀏覽代碼

Line slider can now be dragged properly

Marko Pintera 11 年之前
父節點
當前提交
26d5fc2558

+ 3 - 0
BansheeEditor/Include/BsHandleSliderDisc.h

@@ -30,5 +30,8 @@ namespace BansheeEngine
 		Matrix4 mTorusRotation;
 		Matrix4 mTorusRotation;
 
 
 		Torus mCollider;
 		Torus mCollider;
+
+		float mDelta;
+		bool mHasLastPos;
 	};
 	};
 }
 }

+ 1 - 0
BansheeEditor/Include/BsHandleSliderLine.h

@@ -32,5 +32,6 @@ namespace BansheeEngine
 		Sphere mSphereCollider;
 		Sphere mSphereCollider;
 
 
 		float mDelta;
 		float mDelta;
+		bool mHasLastPos;
 	};
 	};
 }
 }

+ 3 - 0
BansheeEditor/Include/BsHandleSliderPlane.h

@@ -27,5 +27,8 @@ namespace BansheeEngine
 		float mLength;
 		float mLength;
 
 
 		Rect3 mCollider;
 		Rect3 mCollider;
+
+		float mDelta;
+		bool mHasLastPos;
 	};
 	};
 }
 }

+ 9 - 3
BansheeEditor/Source/BsHandleSliderDisc.cpp

@@ -10,7 +10,7 @@ namespace BansheeEngine
 	const float HandleSliderDisc::TORUS_RADIUS = 0.5f;
 	const float HandleSliderDisc::TORUS_RADIUS = 0.5f;
 
 
 	HandleSliderDisc::HandleSliderDisc(const Vector3& normal, float radius, float snapValue, bool fixedScale)
 	HandleSliderDisc::HandleSliderDisc(const Vector3& normal, float radius, float snapValue, bool fixedScale)
-		:HandleSlider(fixedScale, snapValue), mRadius(radius)
+		:HandleSlider(fixedScale, snapValue), mRadius(radius), mDelta(0.0f), mHasLastPos(false)
 	{
 	{
 		Vector3 x, z;
 		Vector3 x, z;
 		mNormal.orthogonalComplement(x, z);
 		mNormal.orthogonalComplement(x, z);
@@ -56,7 +56,8 @@ namespace BansheeEngine
 
 
 	void HandleSliderDisc::reset()
 	void HandleSliderDisc::reset()
 	{
 	{
-		// TODO - Clear delta
+		mDelta = 0.0f;
+		mHasLastPos = false;
 	}
 	}
 
 
 	void HandleSliderDisc::update(const HCamera& camera, const Vector2I& pointerPos, const Ray& ray)
 	void HandleSliderDisc::update(const HCamera& camera, const Vector2I& pointerPos, const Ray& ray)
@@ -66,6 +67,11 @@ namespace BansheeEngine
 		mLastPointerPos = mCurPointerPos;
 		mLastPointerPos = mCurPointerPos;
 		mCurPointerPos = pointerPos;
 		mCurPointerPos = pointerPos;
 
 
-		// TODO
+		if (mHasLastPos)
+		{
+			// TODO
+		}
+		
+		mHasLastPos = false;
 	}
 	}
 }
 }

+ 6 - 2
BansheeEditor/Source/BsHandleSliderLine.cpp

@@ -12,7 +12,7 @@ namespace BansheeEngine
 	const float HandleSliderLine::SPHERE_RADIUS = 0.2f;
 	const float HandleSliderLine::SPHERE_RADIUS = 0.2f;
 
 
 	HandleSliderLine::HandleSliderLine(const Vector3& direction, float length, float snapValue, bool fixedScale)
 	HandleSliderLine::HandleSliderLine(const Vector3& direction, float length, float snapValue, bool fixedScale)
-		:HandleSlider(fixedScale, snapValue), mLength(length), mDelta(0.0f)
+		:HandleSlider(fixedScale, snapValue), mLength(length), mDelta(0.0f), mHasLastPos(false)
 	{
 	{
 		mDirection = Vector3::normalize(direction);
 		mDirection = Vector3::normalize(direction);
 
 
@@ -70,12 +70,16 @@ namespace BansheeEngine
 		mLastPointerPos = mCurPointerPos;
 		mLastPointerPos = mCurPointerPos;
 		mCurPointerPos = pointerPos;
 		mCurPointerPos = pointerPos;
 
 
-		mDelta = calcDelta(camera, getPosition(), mDirection, mLastPointerPos, mCurPointerPos);
+		if (mHasLastPos)
+			mDelta = calcDelta(camera, getPosition(), mDirection, mLastPointerPos, mCurPointerPos);
+
+		mHasLastPos = true;
 	}
 	}
 
 
 	void HandleSliderLine::reset()
 	void HandleSliderLine::reset()
 	{
 	{
 		mDelta = 0.0f;
 		mDelta = 0.0f;
+		mHasLastPos = false;
 	}
 	}
 
 
 	Vector3 HandleSliderLine::getNewPosition() const
 	Vector3 HandleSliderLine::getNewPosition() const

+ 42 - 48
BansheeEditor/Source/BsHandleSliderManager.cpp

@@ -26,77 +26,71 @@ namespace BansheeEngine
 
 
 	void HandleSliderManager::update(const HCamera& camera, const Vector2I& inputPos, const Ray& inputRay, bool pressed)
 	void HandleSliderManager::update(const HCamera& camera, const Vector2I& inputPos, const Ray& inputRay, bool pressed)
 	{
 	{
-		float nearestT = std::numeric_limits<float>::max();
-		HandleSlider* overSlider = nullptr;
-		for (auto& slider : mSliders)
+		if (!pressed)
 		{
 		{
-			float t;
-			if (slider->intersects(inputRay, t))
+			if (mActiveSlider != nullptr)
 			{
 			{
-				if (t < nearestT)
-				{
-					overSlider = slider;
-					nearestT = t;
-				}
+				mActiveSlider->setInactive();
+				mActiveSlider = nullptr;
 			}
 			}
-		}
 
 
-		if (overSlider != nullptr)
-		{
-			if (!pressed)
+			float nearestT = std::numeric_limits<float>::max();
+			HandleSlider* overSlider = nullptr;
+			for (auto& slider : mSliders)
 			{
 			{
-				if (mActiveSlider != nullptr)
+				float t;
+				if (slider->intersects(inputRay, t))
 				{
 				{
-					mActiveSlider->setInactive();
-					mActiveSlider = nullptr;
-				}
-
-				if (mHoverSlider != overSlider)
-				{
-					if (mHoverSlider != nullptr)
-						mHoverSlider->setInactive();
-
-					mHoverSlider = overSlider;
-					overSlider->setHover();
+					if (t < nearestT)
+					{
+						overSlider = slider;
+						nearestT = t;
+					}
 				}
 				}
 			}
 			}
-			else
+
+			if (mHoverSlider != overSlider)
 			{
 			{
 				if (mHoverSlider != nullptr)
 				if (mHoverSlider != nullptr)
-				{
 					mHoverSlider->setInactive();
 					mHoverSlider->setInactive();
-					mHoverSlider = nullptr;
-				}
 
 
-				if (mActiveSlider != overSlider)
-				{
-					if (mActiveSlider != nullptr)
-						mActiveSlider->setInactive();
+				mHoverSlider = overSlider;
 
 
-					mActiveSlider = overSlider;
-					overSlider->setActive(inputPos);
-				}
+				if (mHoverSlider != nullptr)
+					overSlider->setHover();
 			}
 			}
 		}
 		}
 		else
 		else
 		{
 		{
-			if (mActiveSlider != nullptr)
+			if (mActiveSlider == nullptr)
 			{
 			{
-				mActiveSlider->setInactive();
-				mActiveSlider = nullptr;
+				float nearestT = std::numeric_limits<float>::max();
+				HandleSlider* overSlider = nullptr;
+				for (auto& slider : mSliders)
+				{
+					float t;
+					if (slider->intersects(inputRay, t))
+					{
+						if (t < nearestT)
+						{
+							overSlider = slider;
+							nearestT = t;
+						}
+					}
+				}
+
+				if (overSlider != nullptr)
+				{
+					mActiveSlider = overSlider;
+					mActiveSlider->setActive(inputPos);
+				}
 			}
 			}
 
 
-			if (mHoverSlider != nullptr)
+			if (mActiveSlider != nullptr)
 			{
 			{
-				mHoverSlider->setInactive();
-				mHoverSlider = nullptr;
+				mActiveSlider->update(camera, inputPos, inputRay);
 			}
 			}
 		}
 		}
-
-		if (mActiveSlider != nullptr)
-		{
-			mActiveSlider->update(camera, inputPos, inputRay);
-		}
 	}
 	}
 
 
 	bool HandleSliderManager::isSliderActive() const
 	bool HandleSliderManager::isSliderActive() const

+ 9 - 3
BansheeEditor/Source/BsHandleSliderPlane.cpp

@@ -7,7 +7,7 @@
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	HandleSliderPlane::HandleSliderPlane(const Vector3& dir1, const Vector3& dir2, float length, float snapValue, bool fixedScale)
 	HandleSliderPlane::HandleSliderPlane(const Vector3& dir1, const Vector3& dir2, float length, float snapValue, bool fixedScale)
-		:HandleSlider(fixedScale, snapValue), mLength(length)
+		:HandleSlider(fixedScale, snapValue), mLength(length), mDelta(0.0f), mHasLastPos(false)
 	{
 	{
 		mDirection1 = Vector3::normalize(dir1);
 		mDirection1 = Vector3::normalize(dir1);
 		mDirection2 = Vector3::normalize(dir2);
 		mDirection2 = Vector3::normalize(dir2);
@@ -47,7 +47,8 @@ namespace BansheeEngine
 
 
 	void HandleSliderPlane::reset()
 	void HandleSliderPlane::reset()
 	{
 	{
-		// TODO - Clear delta
+		mDelta = 0.0f;
+		mHasLastPos = false;
 	}
 	}
 
 
 	void HandleSliderPlane::update(const HCamera& camera, const Vector2I& pointerPos, const Ray& ray)
 	void HandleSliderPlane::update(const HCamera& camera, const Vector2I& pointerPos, const Ray& ray)
@@ -57,6 +58,11 @@ namespace BansheeEngine
 		mLastPointerPos = mCurPointerPos;
 		mLastPointerPos = mCurPointerPos;
 		mCurPointerPos = pointerPos;
 		mCurPointerPos = pointerPos;
 
 
-		// TODO
+		if (mHasLastPos)
+		{
+			// TODO
+		}
+		
+		mHasLastPos = true;
 	}
 	}
 }
 }