             if (limitRotation)
                 cameraPitch = Clamp(cameraPitch, -90.0, 90.0);
 
-            cameraNode.rotation = Quaternion(cameraPitch, cameraYaw, 0);
-            FadeUI();
-        }
-    }
+            Quaternion q = Quaternion(cameraPitch, cameraYaw, 0);
+            cameraNode.rotation = q;
+            if (input.mouseButtonDown[MOUSEB_MIDDLE] && editNode !is null)
+            {
+                Vector3 d = cameraNode.worldPosition - editNode.worldPosition;
+                cameraNode.worldPosition = editNode.worldPosition - q * Vector3(0.0, 0.0, d.length);
+                orbiting = true;
+            }
+            
+            FadeUI();
+        }
+    }
+    if (orbiting && !input.mouseButtonDown[MOUSEB_MIDDLE])
+        orbiting = false;
 
     // Move/rotate/scale object
     if (!editNodes.empty && editMode != EDIT_SELECT && ui.focusElement is null && input.keyDown[KEY_LCTRL])

        }
    }

    // Rotate camera
    if (input.mouseButtonDown[MOUSEB_RIGHT])
    {
        IntVector2 mouseMove = input.mouseMove;
        if (mouseMove.x != 0 || mouseMove.y != 0)

bool physicsDebug = false;
bool octreeDebug = false;
int pickMode = PICK_GEOMETRIES;
bool orbiting = false;

bool showGrid = true;
bool grid2DMode = false;
