Browse Source

Feature: Tweaked move handle to be more responsive and handles very large or very small scales better

BearishSun 8 years ago
parent
commit
dbe4bda475

+ 9 - 3
Source/BansheeEditor/Handles/BsHandleSlider.cpp

@@ -124,9 +124,15 @@ namespace bs
 		Vector2I diffStart = pointerStart - handleStart2D;
 		Vector2I diffEnd = pointerEnd - handleStart2D;
 
-		float mag = sqrt((float)sqrdMag);
-		float tStart = handleDir2D.dot(diffStart) / mag;
-		float tEnd = handleDir2D.dot(diffEnd) / mag;
+		float tStart = (float)handleDir2D.dot(diffStart);
+		float tEnd = (float)handleDir2D.dot(diffEnd);
+
+		// Smaller magnitude means the direction axis is at a steeper angle from the camera's perspective, meaning we
+		// want the movement to be larger. Largest maginitude is when the direction is perpendicular to the view direction.
+		float invMag = 1.0f / sqrt((float)sqrdMag);
+
+		tStart *= invMag;
+		tEnd *= invMag;
 
 		float arbitraryScale = 1.0f / 100.0f;
 		return negate * (tEnd - tStart) * arbitraryScale;

+ 1 - 1
Source/BansheeEditor/Handles/BsHandleSlider.h

@@ -84,7 +84,7 @@ namespace bs
 		/**	Sets the scale of the slider. */
 		void setScale(const Vector3& scale);
 
-		/**	Enables or disabled the slider, making it interactable or not. */
+		/**	Enables or disables the slider, making it interactable or not. */
 		void setEnabled(bool enabled);
 
 		/**	Gets the world position of the slider. */

+ 8 - 1
Source/BansheeEditor/Handles/BsHandleSliderLine.cpp

@@ -7,6 +7,7 @@
 #include "Math/BsLineSegment3.h"
 #include "Math/BsSphere.h"
 #include "Math/BsRay.h"
+#include "Renderer/BsCamera.h"
 
 namespace bs
 {
@@ -79,5 +80,11 @@ namespace bs
 
 		Vector3 worldDir = getRotation().rotate(mDirection);
 		mDelta = calcDelta(camera, mStartPosition, worldDir, mStartPointerPos, mCurrentPointerPos);
+
+		// Movement in screen space will cover larger range in world space if the camera is further away
+		float dist = (camera->getTransform().getPosition() - mStartPosition).length();
+
+		float arbitraryScale = 1.0f / 5.0f;
+		mDelta *= dist * arbitraryScale;
 	}
-}
+}

+ 12 - 12
Source/BansheeUtility/Math/BsLine2.h

@@ -11,23 +11,23 @@ namespace bs
 	 *  @{
 	 */
 
-    /** A line in 2D space represented with an origin and direction. */
-    class BS_UTILITY_EXPORT Line2
-    {
-    public:
-        Line2()
+	/** A line in 2D space represented with an origin and direction. */
+	class BS_UTILITY_EXPORT Line2
+	{
+	public:
+		Line2()
 			:mOrigin(Vector2::ZERO), mDirection(Vector2::UNIT_X) 
 		{ }
 
-        Line2(const Vector2& origin, const Vector2& direction)
-            :mOrigin(origin), mDirection(direction) 
+		Line2(const Vector2& origin, const Vector2& direction)
+			:mOrigin(origin), mDirection(direction) 
 		{ }
 
-        void setOrigin(const Vector2& origin) { mOrigin = origin; } 
-        const Vector2& getOrigin(void) const { return mOrigin; } 
+		void setOrigin(const Vector2& origin) { mOrigin = origin; } 
+		const Vector2& getOrigin(void) const { return mOrigin; } 
 
-        void setDirection(const Vector2& dir) { mDirection = dir; } 
-        const Vector2& getDirection(void) const {return mDirection;} 
+		void setDirection(const Vector2& dir) { mDirection = dir; } 
+		const Vector2& getDirection(void) const {return mDirection;} 
 
 		/** Gets the position of a point t units along the line. */
 		Vector2 getPoint(float t) const 
@@ -47,7 +47,7 @@ namespace bs
 	protected:
 		Vector2 mOrigin;
 		Vector2 mDirection;
-    };
+	};
 
 	/** @} */
 }

+ 24 - 24
Source/BansheeUtility/Math/BsRay.h

@@ -11,23 +11,23 @@ namespace bs
 	 *  @{
 	 */
 
-    /** A ray in 3D space represented with an origin and direction. */
-    class BS_UTILITY_EXPORT Ray
-    {
-    public:
-        Ray()
+	/** A ray in 3D space represented with an origin and direction. */
+	class BS_UTILITY_EXPORT Ray
+	{
+	public:
+		Ray()
 			:mOrigin(Vector3::ZERO), mDirection(Vector3::UNIT_Z) 
 		{ }
 
-        Ray(const Vector3& origin, const Vector3& direction)
-            :mOrigin(origin), mDirection(direction) 
+		Ray(const Vector3& origin, const Vector3& direction)
+			:mOrigin(origin), mDirection(direction) 
 		{ }
 
-        void setOrigin(const Vector3& origin) { mOrigin = origin; } 
-        const Vector3& getOrigin(void) const { return mOrigin; } 
+		void setOrigin(const Vector3& origin) { mOrigin = origin; } 
+		const Vector3& getOrigin(void) const { return mOrigin; } 
 
-        void setDirection(const Vector3& dir) { mDirection = dir; } 
-        const Vector3& getDirection(void) const {return mDirection;} 
+		void setDirection(const Vector3& dir) { mDirection = dir; } 
+		const Vector3& getDirection(void) const {return mDirection;} 
 
 		/** Gets the position of a point t units along the ray. */
 		Vector3 getPoint(float t) const 
@@ -60,24 +60,24 @@ namespace bs
 		/** Ray/axis aligned box intersection, returns boolean result and distance to nearest intersection point. */
 		std::pair<bool, float> intersects(const AABox& box) const;
 
-        /**
-         * Ray/triangle intersection, returns boolean result and distance to intersection point.
-         *
-         * @param[in]	a				Triangle first vertex.
-         * @param[in]	b				Triangle second vertex.
-         * @param[in]	c				Triangle third vertex.
-         * @param[in]	normal			The normal of the triangle. Doesn't need to be normalized.
-         * @param[in]	positiveSide	(optional) Should intersections with the positive side (normal facing) count.
-         * @param[in]	negativeSide	(optional) Should intersections with the negative side (opposite of normal facing) count.
-         * @return						Boolean result if intersection happened and distance to intersection point.
-         */
-        std::pair<bool, float> intersects(const Vector3& a, const Vector3& b, const Vector3& c, 
+		/**
+		 * Ray/triangle intersection, returns boolean result and distance to intersection point.
+		 *
+		 * @param[in]	a				Triangle first vertex.
+		 * @param[in]	b				Triangle second vertex.
+		 * @param[in]	c				Triangle third vertex.
+		 * @param[in]	normal			The normal of the triangle. Doesn't need to be normalized.
+		 * @param[in]	positiveSide	(optional) Should intersections with the positive side (normal facing) count.
+		 * @param[in]	negativeSide	(optional) Should intersections with the negative side (opposite of normal facing) count.
+		 * @return						Boolean result if intersection happened and distance to intersection point.
+		 */
+		std::pair<bool, float> intersects(const Vector3& a, const Vector3& b, const Vector3& c, 
 			const Vector3& normal, bool positiveSide = true, bool negativeSide = true) const;
 
 	protected:
 		Vector3 mOrigin;
 		Vector3 mDirection;
-    };
+	};
 
 	/** @} */
 }