瀏覽代碼

Fixing handles so their deltas don't scale with distance of camera to handle

Marko Pintera 10 年之前
父節點
當前提交
25467d81a7

+ 6 - 3
BansheeEditor/Source/BsHandleSlider.cpp

@@ -1,6 +1,7 @@
 #include "BsHandleSlider.h"
 #include "BsCamera.h"
 #include "BsHandleManager.h"
+#include "BsDebug.h"
 
 namespace BansheeEngine
 {
@@ -114,9 +115,11 @@ namespace BansheeEngine
 		Vector2I diffStart = pointerStart - handleStart2D;
 		Vector2I diffEnd = pointerEnd - handleStart2D;
 
-		float tStart = handleDir2D.dot(diffStart) / (float)sqrdMag;
-		float tEnd = handleDir2D.dot(diffEnd) / (float)sqrdMag;
+		float mag = sqrt((float)sqrdMag);
+		float tStart = handleDir2D.dot(diffStart) / mag;
+		float tEnd = handleDir2D.dot(diffEnd) / mag;
 
-		return negate * (tEnd - tStart);
+		float arbitraryScale = 1.0f / 100.0f;
+		return negate * (tEnd - tStart) * arbitraryScale;
 	}
 }

+ 20 - 14
BansheeEngine/Source/BsShapeMeshes3D.cpp

@@ -499,34 +499,40 @@ namespace BansheeEngine
 	void ShapeMeshes3D::solidArc(const Vector3& center, float radius, const Vector3& normal, Degree startAngle, Degree amountAngle, 
 		UINT8* outVertices, UINT8* outNormals, UINT32 vertexOffset, UINT32 vertexStride, UINT32* outIndices, UINT32 indexOffset, UINT32 quality)
 	{
-		Vector3* centerVertex = (Vector3*)(outVertices + (vertexOffset * vertexStride));
-		*centerVertex = center;
+		outVertices += vertexOffset * vertexStride;
+		outNormals += vertexOffset * vertexStride;
+		outIndices += indexOffset;
+
+		bool reverseOrder = amountAngle.valueDegrees() < 0.0f;
+		Vector3 visibleNormal = normal;
+
+		outVertices = writeVector3(outVertices, vertexStride, center);
+		outNormals = writeVector3(outNormals, vertexStride, visibleNormal);
 
 		UINT32 numArcVertices = (quality + 1) * 5;
 		generateArcVertices(center, normal, radius, startAngle, amountAngle,
-			numArcVertices, outVertices, vertexOffset + 1, vertexStride);
+			numArcVertices, outVertices, vertexOffset, vertexStride);
 
-		UINT32 totalNumVertices = numArcVertices + 1;
-		outNormals += vertexOffset * vertexStride;
-		outVertices += vertexOffset * vertexStride;
+		UINT8* otherSideVertices = outVertices + (numArcVertices * vertexStride);
+		UINT8* otherSideNormals = outNormals + (numArcVertices * vertexStride);
+
+		otherSideVertices = writeVector3(otherSideVertices, vertexStride, center);
+		otherSideNormals = writeVector3(otherSideNormals, vertexStride, -visibleNormal);
 
-		UINT8* otherSideVertices = outVertices + (totalNumVertices * vertexStride);
-		UINT8* otherSideNormals = outNormals + (totalNumVertices * vertexStride);
-		for (UINT32 i = 0; i < totalNumVertices; i++)
+		for (UINT32 i = 0; i < numArcVertices; i++)
 		{
 			otherSideVertices = writeVector3(otherSideVertices, vertexStride, *(Vector3*)outVertices);
 			outVertices += vertexStride;
 
-			outNormals = writeVector3(outNormals, vertexStride, normal);
-			otherSideNormals = writeVector3(otherSideNormals, vertexStride, -normal);
+			outNormals = writeVector3(outNormals, vertexStride, visibleNormal);
+			otherSideNormals = writeVector3(otherSideNormals, vertexStride, -visibleNormal);
 		}
 
-		outIndices += indexOffset;
 		UINT32 numTriangles = numArcVertices - 1;
 
 		// If angle is negative the order of vertices is reversed so we need to reverse the indexes too
-		UINT32 frontSideOffset = vertexOffset + (amountAngle.valueDegrees() < 0.0f ? totalNumVertices : 0);
-		UINT32 backSideOffset = vertexOffset + (amountAngle.valueDegrees() >= 0.0f ? totalNumVertices : 0);
+		UINT32 frontSideOffset = vertexOffset + (reverseOrder ? (numArcVertices + 1) : 0);
+		UINT32 backSideOffset = vertexOffset + (!reverseOrder ? (numArcVertices + 1) : 0);
 
 		for (UINT32 i = 0; i < numTriangles; i++)
 		{

+ 1 - 1
BansheeUtility/Include/BsVector2I.h

@@ -5,7 +5,7 @@
 namespace BansheeEngine
 {
 	/**
-	 * @brief	A N dimensional vector with integer
+	 * @brief	A two dimensional vector with integer
 	 *			coordinates.
 	 */
 	struct BS_UTILITY_EXPORT Vector2I

+ 5 - 9
MBansheeEditor/Scene/DefaultHandleManager.cs

@@ -28,7 +28,7 @@ namespace BansheeEditor
         private bool isDragged;
         private Vector3 initialHandlePosition;
         private Quaternion initialHandleRotation;
-       
+
         protected override void PreInput()
         {
             SceneObject[] selectedSceneObjects = Selection.sceneObjects;
@@ -167,26 +167,22 @@ namespace BansheeEditor
                             // Make sure we transform relative to the handle position
                             SceneObject temporarySO = new SceneObject("Temp");
                             temporarySO.Position = activeHandle.Position;
+                            // TODO - Save initial handle scale
 
                             SceneObject[] originalParents = new SceneObject[activeSelection.Length];
                             for (int i = 0; i < activeSelection.Length; i++)
                             {
                                 originalParents[i] = activeSelection[i].so.Parent;
+                                activeSelection[i].so.LocalPosition = activeSelection[i].initialPosition;
+                                activeSelection[i].so.LocalRotation = activeSelection[i].initialRotation;
                                 activeSelection[i].so.LocalScale = activeSelection[i].initialScale;
                                 activeSelection[i].so.Parent = temporarySO;
                             }
 
-                            //temporarySO.LocalScale = Vector3.one + scaleHandle.Delta;
-                            temporarySO.LocalScale = Vector3.one*0.5f;
-                            Debug.Log("SCALE " + temporarySO.LocalScale + " - " + scaleHandle.Delta);
+                            temporarySO.LocalScale += scaleHandle.Delta;
 
                             for (int i = 0; i < activeSelection.Length; i++)
-                            {
-                                Debug.Log("POSITION A: " + activeSelection[i].so.Position);
                                 activeSelection[i].so.Parent = originalParents[i];
-                                Debug.Log("TFRM " + activeSelection[i].so.LocalScale + " - " +
-                                          activeSelection[i].so.Position);
-                            }
 
                             temporarySO.Destroy();
                         }

+ 1 - 0
TODO.txt

@@ -61,6 +61,7 @@ Polish stage 1
 Handles:
 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
+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
 Investigate scale and its issues
 Check multi-select move/Rotate/scale