Fix camera
This commit is contained in:
@@ -78,6 +78,7 @@ class App extends iron.Trait {
|
||||
iron.Scene.active.root.addTrait(new UIView2D());
|
||||
iron.Scene.active.root.addTrait(new arm.trait.FlyCamera());
|
||||
iron.Scene.active.root.addTrait(new arm.trait.OrbitCamera());
|
||||
iron.Scene.active.root.addTrait(new arm.trait.ArcBallCamera());
|
||||
iron.App.notifyOnInit(function() {
|
||||
iron.App.notifyOnRender2D(render); // Draw on top
|
||||
});
|
||||
|
||||
+2
-37
@@ -167,7 +167,7 @@ class UITrait extends iron.Trait {
|
||||
var lastBrushType = -1;
|
||||
|
||||
#if arm_editor
|
||||
public var cameraType = 1;
|
||||
public var cameraType = 2;
|
||||
#else
|
||||
public var cameraType = 0;
|
||||
#end
|
||||
@@ -616,44 +616,9 @@ class UITrait extends iron.Trait {
|
||||
}
|
||||
}
|
||||
|
||||
camBall();
|
||||
|
||||
for (p in Plugin.plugins) if (p.update != null) p.update();
|
||||
}
|
||||
|
||||
function camBall() {
|
||||
if (iron.system.Input.occupied) return;
|
||||
if (!arm.App.uienabled) return;
|
||||
if (UITrait.inst.isScrolling) return;
|
||||
if (arm.App.isDragging) return;
|
||||
if (UITrait.inst.cameraType != 0) return;
|
||||
//if (!selectedObject.visible) return;
|
||||
|
||||
var mouse = iron.system.Input.getMouse();
|
||||
var kb = iron.system.Input.getKeyboard();
|
||||
|
||||
// Paint bounds
|
||||
if (mouse.x < 0 || mouse.x > iron.App.w()) return;
|
||||
|
||||
if (mouse.down("right") || (mouse.down("left") && kb.down("control"))) {
|
||||
UITrait.inst.ddirty = 2;
|
||||
|
||||
// Rotate X
|
||||
// if (!kb.down("alt")) {
|
||||
selectedObject.transform.rotate(new iron.math.Vec4(0, 0, 1), mouse.movementX / 100);
|
||||
selectedObject.transform.buildMatrix();
|
||||
// }
|
||||
|
||||
// Rotate Y
|
||||
if (!kb.down("shift")) {
|
||||
var v = selectedObject.transform.right();
|
||||
v.normalize();
|
||||
selectedObject.transform.rotate(v, mouse.movementY / 100);
|
||||
selectedObject.transform.buildMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function makeStickerPreview() {
|
||||
if (stickerImage == null) stickerImage = kha.Image.createRenderTarget(512, 512);
|
||||
stickerPreview = true;
|
||||
@@ -1896,7 +1861,7 @@ void main() {
|
||||
var scene = iron.Scene.active;
|
||||
var cam = scene.cameras[0];
|
||||
ui.row([1/2,1/2]);
|
||||
cameraType = ui.combo(Id.handle({position: cameraType}), ["Orbit", "Fly"], "Camera");
|
||||
cameraType = ui.combo(Id.handle({position: cameraType}), ["ArcBall", "Orbit", "Fly"], "Camera");
|
||||
var fovHandle = Id.handle({value: Std.int(cam.data.raw.fov * 100) / 100});
|
||||
cam.data.raw.fov = ui.slider(fovHandle, "FoV", 0.3, 2.0, true);
|
||||
if (fovHandle.changed) {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package arm.trait;
|
||||
|
||||
import arm.UITrait;
|
||||
|
||||
class ArcBallCamera extends iron.Trait {
|
||||
|
||||
public static var inst:ArcBallCamera;
|
||||
|
||||
var redraws = 0;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
inst = this;
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
if (iron.system.Input.occupied) return;
|
||||
if (!arm.App.uienabled) return;
|
||||
if (UITrait.inst.isScrolling) return;
|
||||
if (arm.App.isDragging) return;
|
||||
if (UITrait.inst.cameraType != 0) return;
|
||||
|
||||
var mouse = iron.system.Input.getMouse();
|
||||
if (mouse.x < 0 || mouse.x > iron.App.w()) return;
|
||||
|
||||
var kb = iron.system.Input.getKeyboard();
|
||||
var camera = iron.Scene.active.camera;
|
||||
|
||||
if (mouse.wheelDelta != 0) {
|
||||
redraws = 2;
|
||||
camera.transform.move(camera.look(), mouse.wheelDelta * (-0.1));
|
||||
}
|
||||
|
||||
if (mouse.down("middle") || (mouse.down("right") && kb.down("space"))) {
|
||||
redraws = 2;
|
||||
camera.transform.loc.addf(-mouse.movementX / 150, 0.0, mouse.movementY / 150);
|
||||
camera.buildMatrix();
|
||||
}
|
||||
|
||||
if (mouse.down("right") || (mouse.down("left") && kb.down("control"))) {
|
||||
redraws = 2;
|
||||
|
||||
// Rotate X
|
||||
if (!kb.down("alt")) {
|
||||
var v = UITrait.inst.selectedObject.transform.up();
|
||||
v.normalize();
|
||||
UITrait.inst.selectedObject.transform.rotate(v, mouse.movementX / 100);
|
||||
}
|
||||
|
||||
// Rotate Y
|
||||
if (!kb.down("shift")) {
|
||||
var v = camera.rightWorld();
|
||||
v.normalize();
|
||||
UITrait.inst.selectedObject.transform.rotate(v, mouse.movementY / 100);
|
||||
UITrait.inst.selectedObject.transform.buildMatrix();
|
||||
|
||||
if (UITrait.inst.selectedObject.transform.up().z < 0) {
|
||||
UITrait.inst.selectedObject.transform.rotate(v, -mouse.movementY / 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (redraws > 0) {
|
||||
redraws--;
|
||||
UITrait.inst.ddirty = 2;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import arm.UITrait;
|
||||
class FlyCamera extends Trait {
|
||||
|
||||
public static var inst:FlyCamera;
|
||||
public var enabled = false;
|
||||
|
||||
static inline var speed = 2.0;
|
||||
var dir = new Vec4();
|
||||
@@ -32,7 +31,7 @@ class FlyCamera extends Trait {
|
||||
if (!arm.App.uienabled) return;
|
||||
if (UITrait.inst.isScrolling) return;
|
||||
if (arm.App.isDragging) return;
|
||||
if (UITrait.inst.cameraType != 1) return;
|
||||
if (UITrait.inst.cameraType != 2) return;
|
||||
|
||||
var keyboard = Input.getKeyboard();
|
||||
var gamepad = Input.getGamepad();
|
||||
@@ -77,13 +76,13 @@ class FlyCamera extends Trait {
|
||||
var d = Time.delta * speed * fast * ease;
|
||||
if (d > 0.0) {
|
||||
UITrait.inst.ddirty = 2;
|
||||
camera.move(dir, d);
|
||||
camera.transform.move(dir, d);
|
||||
}
|
||||
|
||||
if (mouse.down("right")) {
|
||||
UITrait.inst.ddirty = 2;
|
||||
camera.rotate(Vec4.zAxis(), -mouse.movementX / 200);
|
||||
camera.rotate(camera.right(), -mouse.movementY / 200);
|
||||
camera.transform.rotate(Vec4.zAxis(), -mouse.movementX / 200);
|
||||
camera.transform.rotate(camera.right(), -mouse.movementY / 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import arm.UITrait;
|
||||
class OrbitCamera extends iron.Trait {
|
||||
|
||||
public static var inst:OrbitCamera;
|
||||
public var enabled = false;
|
||||
|
||||
var redraws = 0;
|
||||
|
||||
@@ -18,25 +17,50 @@ class OrbitCamera extends iron.Trait {
|
||||
if (!arm.App.uienabled) return;
|
||||
if (UITrait.inst.isScrolling) return;
|
||||
if (arm.App.isDragging) return;
|
||||
if (UITrait.inst.cameraType != 0) return;
|
||||
if (UITrait.inst.cameraType != 1) return;
|
||||
|
||||
var mouse = iron.system.Input.getMouse();
|
||||
if (mouse.x < 0 || mouse.x > iron.App.w()) return;
|
||||
|
||||
var keyboard = iron.system.Input.getKeyboard();
|
||||
var kb = iron.system.Input.getKeyboard();
|
||||
var camera = iron.Scene.active.camera;
|
||||
|
||||
if (mouse.wheelDelta != 0) {
|
||||
redraws = 2;
|
||||
camera.move(camera.look(), mouse.wheelDelta * (-0.1));
|
||||
camera.transform.move(camera.look(), mouse.wheelDelta * (-0.1));
|
||||
}
|
||||
|
||||
if (mouse.down("middle") || (mouse.down("right") && keyboard.down("space"))) {
|
||||
if (mouse.down("middle") || (mouse.down("right") && kb.down("space"))) {
|
||||
redraws = 2;
|
||||
camera.transform.loc.addf(-mouse.movementX / 150, 0.0, mouse.movementY / 150);
|
||||
camera.buildMatrix();
|
||||
}
|
||||
|
||||
if (mouse.down("right") || (mouse.down("left") && kb.down("control"))) {
|
||||
redraws = 2;
|
||||
|
||||
// Rotate X
|
||||
if (!kb.down("alt")) {
|
||||
var d = camera.transform.loc.length();
|
||||
camera.transform.loc.set(0, 0, 0);
|
||||
camera.transform.rotate(new iron.math.Vec4(0, 0, 1), -mouse.movementX / 100);
|
||||
camera.transform.move(camera.lookWorld(), -d);
|
||||
}
|
||||
|
||||
// Rotate Y
|
||||
if (!kb.down("shift")) {
|
||||
var d = camera.transform.loc.length();
|
||||
camera.transform.loc.set(0, 0, 0);
|
||||
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(), -d);
|
||||
}
|
||||
}
|
||||
|
||||
if (redraws > 0) {
|
||||
redraws--;
|
||||
UITrait.inst.ddirty = 2;
|
||||
|
||||
Reference in New Issue
Block a user