Browse Source

Fixing incorrect normals with disc slider

Marko Pintera 10 years ago
parent
commit
fa5e36a9fe

+ 3 - 1
BansheeEditor/Source/BsHandleSliderDisc.cpp

@@ -8,6 +8,7 @@
 
 
 // DEBUG ONLY
 // DEBUG ONLY
 #include "BsDebug.h"
 #include "BsDebug.h"
+#include "BsGizmoManager.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -164,7 +165,8 @@ namespace BansheeEngine
 		mStartAngle = pointOnCircleToAngle(mNormal, mStartPosition);
 		mStartAngle = pointOnCircleToAngle(mNormal, mStartPosition);
 		mStartPosition = getTransform().multiplyAffine(mStartPosition);
 		mStartPosition = getTransform().multiplyAffine(mStartPosition);
 
 
-		Vector3 worldNormal = getTransform().multiplyAffine(mNormal);
+		Vector3 worldNormal = getTransform().multiplyDirection(mNormal);
+		worldNormal.normalize();
 
 
 		Vector3 toStart = mStartPosition - getPosition();
 		Vector3 toStart = mStartPosition - getPosition();
 		mDirection = worldNormal.cross(toStart);
 		mDirection = worldNormal.cross(toStart);

+ 28 - 28
BansheeUtility/Include/BsMatrix4.h

@@ -344,6 +344,26 @@ namespace BansheeEngine
                 0, 0, 0, 1);
                 0, 0, 0, 1);
         }
         }
 
 
+        /**
+         * @brief	Transform a plane by this matrix.
+         * 			
+         * @note	Matrix must be affine.
+         */
+        Plane multiplyAffine(const Plane& p) const
+        {
+			Vector4 localNormal(p.normal.x, p.normal.y, p.normal.z, 0.0f);
+			Vector4 localPoint = localNormal * p.d;
+			localPoint.w = 1.0f;
+
+			Matrix4 itMat = inverse().transpose();
+			Vector4 worldNormal = itMat.multiplyAffine(localNormal);
+			Vector4 worldPoint = multiplyAffine(localPoint);
+
+			float d = worldNormal.dot(worldPoint);
+
+			return Plane(worldNormal.x, worldNormal.y, worldNormal.z, d);
+        }
+
         /**
         /**
          * @brief	Transform a 3D point by this matrix.
          * @brief	Transform a 3D point by this matrix.
          * 			
          * 			
@@ -371,24 +391,15 @@ namespace BansheeEngine
                 v.w);
                 v.w);
         }
         }
 
 
-        /**
-         * @brief	Transform a plane by this matrix.
-         * 			
-         * @note	Matrix must be affine.
+		/**
+         * @brief	Transform a 3D direction by this matrix.
          */
          */
-        Plane multiplyAffine(const Plane& p) const
+        Vector3 multiplyDirection(const Vector3& v) const
         {
         {
-			Vector4 localNormal(p.normal.x, p.normal.y, p.normal.z, 0.0f);
-			Vector4 localPoint = localNormal * p.d;
-			localPoint.w = 1.0f;
-
-			Matrix4 itMat = inverse().transpose();
-			Vector4 worldNormal = itMat.multiplyAffine(localNormal);
-			Vector4 worldPoint = multiplyAffine(localPoint);
-
-			float d = worldNormal.dot(worldPoint);
-
-			return Plane(worldNormal.x, worldNormal.y, worldNormal.z, d);
+            return Vector3(
+                    m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z, 
+                    m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z,
+                    m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z);
         }
         }
 
 
         /**
         /**
@@ -399,7 +410,7 @@ namespace BansheeEngine
          * 			
          * 			
 		 *			If your matrix doesn't contain projection components use "multiplyAffine" method as it is faster.
 		 *			If your matrix doesn't contain projection components use "multiplyAffine" method as it is faster.
          */
          */
-        Vector3 multiply(const Vector3 &v) const
+        Vector3 multiply(const Vector3& v) const
         {
         {
             Vector3 r;
             Vector3 r;
 
 
@@ -412,17 +423,6 @@ namespace BansheeEngine
             return r;
             return r;
         }
         }
 
 
-		/**
-         * @brief	Transform a 3D direction by this matrix.
-         */
-        Vector3 multiplyDirection(const Vector3& v) const
-        {
-            return Vector3(
-                    m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z, 
-                    m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z,
-                    m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z);
-        }
-
         /**
         /**
          * @brief	Transform a 4D vector by this matrix.  
          * @brief	Transform a 4D vector by this matrix.  
          *
          *

+ 7 - 7
MBansheeEditor/EditorApplication.cs

@@ -107,12 +107,12 @@ namespace BansheeEditor
 
 
             // DEBUG ONLY
             // DEBUG ONLY
 
 
-            SceneObject newDbgObject = new SceneObject("NewDbgObject");
-            dbgComponent = newDbgObject.AddComponent<Debug_Component1>();
-            newDbgObject.AddComponent<Debug_Component2>();
+            //SceneObject newDbgObject = new SceneObject("NewDbgObject");
+            //dbgComponent = newDbgObject.AddComponent<Debug_Component1>();
+            //newDbgObject.AddComponent<Debug_Component2>();
 
 
-            SceneObject gizmoDbgObject = new SceneObject("GizmoDebug");
-            gizmoDbgObject.AddComponent<DbgGizmoComponent>();
+            //SceneObject gizmoDbgObject = new SceneObject("GizmoDebug");
+           // gizmoDbgObject.AddComponent<DbgGizmoComponent>();
             //ProgressBar.Show("Test", 0.5f);
             //ProgressBar.Show("Test", 0.5f);
             //ColorPicker.Show();
             //ColorPicker.Show();
 
 
@@ -130,8 +130,8 @@ namespace BansheeEditor
 
 
             // DEBUG ONLY
             // DEBUG ONLY
 
 
-            if (dbgComponent != null)
-                dbgComponent.intArray[0] = dbgComponent.intArray[0] + 1;
+            //if (dbgComponent != null)
+            //    dbgComponent.intArray[0] = dbgComponent.intArray[0] + 1;
 
 
             // DEBUG ONLY END
             // DEBUG ONLY END
         }
         }

+ 2 - 0
MBansheeEditor/Scene/RotateHandle.cs

@@ -82,6 +82,8 @@ namespace BansheeEditor
             }
             }
 
 
             delta = Quaternion.FromEuler(xValue, yValue, zValue);
             delta = Quaternion.FromEuler(xValue, yValue, zValue);
+
+            Debug.Log("ROTATION: " + Rotation);
         }
         }
 
 
         protected override void Draw()
         protected override void Draw()

+ 0 - 1
TODO.txt

@@ -61,7 +61,6 @@ Polish stage 1
 Handles:
 Handles:
 In some cases it's really hard to rotate or the rotation twitches
 In some cases it's really hard to rotate or the rotation twitches
 When rotating the handle (and sometimes immediately in global mode) the rotation direction is opposite of move movement
 When rotating the handle (and sometimes immediately in global mode) the rotation direction is opposite of move movement
-Distance of camera from rotation handle seems to effect the rotation speed. When very close it is extremely small.
 Move plane handles could be more precise
 Move plane handles could be more precise
 Investigate scale and its issues
 Investigate scale and its issues
 Check multi-select move/Rotate/scale
 Check multi-select move/Rotate/scale