diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index 68a0331e..c077ca21 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -472,12 +472,12 @@ class App extends iron.Trait { // ui.button("Preferences...", Left); } else if (menuCategory == 2) { - if (ui.button("Front", Left, "1")) { ViewportUtil.setView(0, -3, 0, Math.PI / 2, 0, 0); } - if (ui.button("Back", Left, "Ctrl+1")) { ViewportUtil.setView(0, 3, 0, Math.PI / 2, 0, Math.PI); } - if (ui.button("Right", Left, "3")) { ViewportUtil.setView(3, 0, 0, Math.PI / 2, 0, Math.PI / 2); } - if (ui.button("Left", Left, "Ctrl+3")) { ViewportUtil.setView(-3, 0, 0, Math.PI / 2, 0, -Math.PI / 2); } - if (ui.button("Top", Left, "7")) { ViewportUtil.setView(0, 0, 3, 0, 0, 0); } - if (ui.button("Bottom", Left, "Ctrl+7")) { ViewportUtil.setView(0, 0, -3, Math.PI, 0, Math.PI); } + if (ui.button("Front", Left, "1")) { ViewportUtil.setView(0, -1, 0, Math.PI / 2, 0, 0); } + if (ui.button("Back", Left, "Ctrl+1")) { ViewportUtil.setView(0, 1, 0, Math.PI / 2, 0, Math.PI); } + if (ui.button("Right", Left, "3")) { ViewportUtil.setView(1, 0, 0, Math.PI / 2, 0, Math.PI / 2); } + if (ui.button("Left", Left, "Ctrl+3")) { ViewportUtil.setView(-1, 0, 0, Math.PI / 2, 0, -Math.PI / 2); } + if (ui.button("Top", Left, "7")) { ViewportUtil.setView(0, 0, 1, 0, 0, 0); } + if (ui.button("Bottom", Left, "Ctrl+7")) { ViewportUtil.setView(0, 0, -1, Math.PI, 0, Math.PI); } if (ui.button("Reset", Left, "0")) { ViewportUtil.resetViewport(); ViewportUtil.scaleToBounds(); } ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL); if (ui.button("Distract Free", Left, "F11")) { diff --git a/Sources/arm/trait/OrbitCamera.hx b/Sources/arm/trait/OrbitCamera.hx index 65fa87c7..a5d3ffef 100644 --- a/Sources/arm/trait/OrbitCamera.hx +++ b/Sources/arm/trait/OrbitCamera.hx @@ -7,6 +7,8 @@ class OrbitCamera extends iron.Trait { public static var inst:OrbitCamera; var redraws = 0; + var first = true; + var dist = 0.0; public function new() { super(); @@ -27,15 +29,24 @@ class OrbitCamera extends iron.Trait { var camera = iron.Scene.active.camera; + if (first) { + first = false; + reset(); + } + if (mouse.wheelDelta != 0) { redraws = 2; - camera.transform.move(camera.look(), mouse.wheelDelta * (-0.1)); + var f = mouse.wheelDelta * (-0.1); + camera.transform.move(camera.look(), f); + dist -= f; } if (mouse.down("middle") || (mouse.down("right") && kb.down("space"))) { redraws = 2; if (kb.down("control")) { - camera.transform.move(camera.look(), mouse.movementX / 75); + var f = mouse.movementX / 75; + camera.transform.move(camera.look(), f); + dist -= f; } else { var look = camera.transform.look().normalize().mult(mouse.movementY / 150); @@ -47,23 +58,19 @@ class OrbitCamera extends iron.Trait { } if (mouse.down("right") || (mouse.down("left") && kb.down("control"))) { - var dist = camera.transform.loc.length(); redraws = 2; camera.transform.move(camera.lookWorld(), dist); camera.transform.rotate(new iron.math.Vec4(0, 0, 1), -mouse.movementX / 100); - camera.transform.move(camera.lookWorld(), -dist); // Rotate Y if (!kb.down("shift")) { - camera.transform.move(camera.lookWorld(), dist); camera.transform.rotate(camera.rightWorld(), -mouse.movementY / 100); - if (camera.upWorld().z < 0) { camera.transform.rotate(camera.rightWorld(), mouse.movementY / 100); } - - camera.transform.move(camera.lookWorld(), -dist); } + + camera.transform.move(camera.lookWorld(), -dist); } if (redraws > 0) { @@ -72,4 +79,9 @@ class OrbitCamera extends iron.Trait { } }); } + + public function reset() { + var camera = iron.Scene.active.camera; + dist = camera.transform.loc.length(); + } } diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index e2f9cfa1..6965f705 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -553,18 +553,18 @@ class UITrait extends iron.Trait { } else if (kb.started("1")) { ctrl ? - ViewportUtil.setView(0, 3, 0, Math.PI / 2, 0, Math.PI) : - ViewportUtil.setView(0, -3, 0, Math.PI / 2, 0, 0); + ViewportUtil.setView(0, 1, 0, Math.PI / 2, 0, Math.PI) : + ViewportUtil.setView(0, -1, 0, Math.PI / 2, 0, 0); } else if (kb.started("3")) { ctrl ? - ViewportUtil.setView(-3, 0, 0, Math.PI / 2, 0, -Math.PI / 2) : - ViewportUtil.setView(3, 0, 0, Math.PI / 2, 0, Math.PI / 2); + ViewportUtil.setView(-1, 0, 0, Math.PI / 2, 0, -Math.PI / 2) : + ViewportUtil.setView(1, 0, 0, Math.PI / 2, 0, Math.PI / 2); } else if (kb.started("7")) { ctrl ? - ViewportUtil.setView(0, 0, -3, Math.PI, 0, Math.PI) : - ViewportUtil.setView(0, 0, 3, 0, 0, 0); + ViewportUtil.setView(0, 0, -1, Math.PI, 0, Math.PI) : + ViewportUtil.setView(0, 0, 1, 0, 0, 0); } } } diff --git a/Sources/arm/util/ViewportUtil.hx b/Sources/arm/util/ViewportUtil.hx index 52f2fc84..8c446eae 100644 --- a/Sources/arm/util/ViewportUtil.hx +++ b/Sources/arm/util/ViewportUtil.hx @@ -35,6 +35,7 @@ class ViewportUtil { cam.buildProjection(); UITrait.inst.selectedObject.transform.reset(); UITrait.inst.ddirty = 2; + arm.trait.OrbitCamera.inst.reset(); break; } } @@ -44,10 +45,12 @@ class ViewportUtil { UITrait.inst.selectedObject.transform.reset(); var scene = iron.Scene.active; var cam = scene.camera; - cam.transform.loc.set(x, y, z); + var dist = cam.transform.loc.length(); + cam.transform.loc.set(x * dist, y * dist, z * dist); cam.transform.rot.fromEuler(rx, ry, rz); cam.transform.buildMatrix(); cam.buildProjection(); UITrait.inst.ddirty = 2; + arm.trait.OrbitCamera.inst.reset(); } }