Update camera

This commit is contained in:
luboslenco
2019-03-14 11:53:21 +01:00
parent 466a498b42
commit a6a4140d44
4 changed files with 36 additions and 21 deletions
+6 -6
View File
@@ -472,12 +472,12 @@ class App extends iron.Trait {
// ui.button("Preferences...", Left); // ui.button("Preferences...", Left);
} }
else if (menuCategory == 2) { else if (menuCategory == 2) {
if (ui.button("Front", Left, "1")) { ViewportUtil.setView(0, -3, 0, Math.PI / 2, 0, 0); } 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, 3, 0, Math.PI / 2, 0, Math.PI); } 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(3, 0, 0, Math.PI / 2, 0, Math.PI / 2); } 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(-3, 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, 3, 0, 0, 0); } 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, -3, Math.PI, 0, Math.PI); } 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(); } if (ui.button("Reset", Left, "0")) { ViewportUtil.resetViewport(); ViewportUtil.scaleToBounds(); }
ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL); ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL);
if (ui.button("Distract Free", Left, "F11")) { if (ui.button("Distract Free", Left, "F11")) {
+20 -8
View File
@@ -7,6 +7,8 @@ class OrbitCamera extends iron.Trait {
public static var inst:OrbitCamera; public static var inst:OrbitCamera;
var redraws = 0; var redraws = 0;
var first = true;
var dist = 0.0;
public function new() { public function new() {
super(); super();
@@ -27,15 +29,24 @@ class OrbitCamera extends iron.Trait {
var camera = iron.Scene.active.camera; var camera = iron.Scene.active.camera;
if (first) {
first = false;
reset();
}
if (mouse.wheelDelta != 0) { if (mouse.wheelDelta != 0) {
redraws = 2; 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"))) { if (mouse.down("middle") || (mouse.down("right") && kb.down("space"))) {
redraws = 2; redraws = 2;
if (kb.down("control")) { 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 { else {
var look = camera.transform.look().normalize().mult(mouse.movementY / 150); 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"))) { if (mouse.down("right") || (mouse.down("left") && kb.down("control"))) {
var dist = camera.transform.loc.length();
redraws = 2; redraws = 2;
camera.transform.move(camera.lookWorld(), dist); camera.transform.move(camera.lookWorld(), dist);
camera.transform.rotate(new iron.math.Vec4(0, 0, 1), -mouse.movementX / 100); camera.transform.rotate(new iron.math.Vec4(0, 0, 1), -mouse.movementX / 100);
camera.transform.move(camera.lookWorld(), -dist);
// Rotate Y // Rotate Y
if (!kb.down("shift")) { if (!kb.down("shift")) {
camera.transform.move(camera.lookWorld(), dist);
camera.transform.rotate(camera.rightWorld(), -mouse.movementY / 100); camera.transform.rotate(camera.rightWorld(), -mouse.movementY / 100);
if (camera.upWorld().z < 0) { if (camera.upWorld().z < 0) {
camera.transform.rotate(camera.rightWorld(), mouse.movementY / 100); camera.transform.rotate(camera.rightWorld(), mouse.movementY / 100);
} }
camera.transform.move(camera.lookWorld(), -dist);
} }
camera.transform.move(camera.lookWorld(), -dist);
} }
if (redraws > 0) { 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();
}
} }
+6 -6
View File
@@ -553,18 +553,18 @@ class UITrait extends iron.Trait {
} }
else if (kb.started("1")) { else if (kb.started("1")) {
ctrl ? ctrl ?
ViewportUtil.setView(0, 3, 0, Math.PI / 2, 0, Math.PI) : ViewportUtil.setView(0, 1, 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, 0);
} }
else if (kb.started("3")) { else if (kb.started("3")) {
ctrl ? ctrl ?
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(3, 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")) { else if (kb.started("7")) {
ctrl ? ctrl ?
ViewportUtil.setView(0, 0, -3, Math.PI, 0, Math.PI) : ViewportUtil.setView(0, 0, -1, Math.PI, 0, Math.PI) :
ViewportUtil.setView(0, 0, 3, 0, 0, 0); ViewportUtil.setView(0, 0, 1, 0, 0, 0);
} }
} }
} }
+4 -1
View File
@@ -35,6 +35,7 @@ class ViewportUtil {
cam.buildProjection(); cam.buildProjection();
UITrait.inst.selectedObject.transform.reset(); UITrait.inst.selectedObject.transform.reset();
UITrait.inst.ddirty = 2; UITrait.inst.ddirty = 2;
arm.trait.OrbitCamera.inst.reset();
break; break;
} }
} }
@@ -44,10 +45,12 @@ class ViewportUtil {
UITrait.inst.selectedObject.transform.reset(); UITrait.inst.selectedObject.transform.reset();
var scene = iron.Scene.active; var scene = iron.Scene.active;
var cam = scene.camera; 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.rot.fromEuler(rx, ry, rz);
cam.transform.buildMatrix(); cam.transform.buildMatrix();
cam.buildProjection(); cam.buildProjection();
UITrait.inst.ddirty = 2; UITrait.inst.ddirty = 2;
arm.trait.OrbitCamera.inst.reset();
} }
} }