Browse Source

Merge remote-tracking branch 'remotes/friesencr/orbit_center_all'

Lasse Öörni 12 years ago
parent
commit
9cbb412efe
1 changed files with 27 additions and 3 deletions
  1. 27 3
      Bin/Data/Scripts/Editor/EditorView.as

+ 27 - 3
Bin/Data/Scripts/Editor/EditorView.as

@@ -346,10 +346,11 @@ void UpdateView(float timeStep)
 
 
             Quaternion q = Quaternion(cameraPitch, cameraYaw, 0);
             Quaternion q = Quaternion(cameraPitch, cameraYaw, 0);
             cameraNode.rotation = q;
             cameraNode.rotation = q;
-            if (input.mouseButtonDown[MOUSEB_MIDDLE] && editNode !is null)
+            if (input.mouseButtonDown[MOUSEB_MIDDLE] && (selectedNodes.length > 0 || selectedComponents.length > 0))
             {
             {
-                Vector3 d = cameraNode.worldPosition - editNode.worldPosition;
-                cameraNode.worldPosition = editNode.worldPosition - q * Vector3(0.0, 0.0, d.length);
+                Vector3 centerPoint = SelectedNodesCenterPoint();
+                Vector3 d = cameraNode.worldPosition - centerPoint;
+                cameraNode.worldPosition = centerPoint - q * Vector3(0.0, 0.0, d.length);
                 orbiting = true;
                 orbiting = true;
             }
             }
             
             
@@ -694,3 +695,26 @@ bool StopTestAnimation()
     testAnimState = null;
     testAnimState = null;
     return true;
     return true;
 }
 }
+
+Vector3 SelectedNodesCenterPoint()
+{
+    Vector3 centerPoint;
+    uint count = selectedNodes.length;
+    for (uint i = 0; i < selectedNodes.length; ++i)
+        centerPoint += selectedNodes[i].worldPosition;
+
+    for (uint i = 0; i < selectedComponents.length; ++i)
+    {
+        Drawable@ drawable = cast<Drawable>(selectedComponents[i]);
+        if (drawable !is null)
+        {
+            centerPoint += drawable.node.LocalToWorld(drawable.boundingBox.center);
+            count++;
+        }
+    }
+
+    if (count > 0)
+        return centerPoint / count;
+    else
+        return centerPoint;
+}