mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-23 16:32:49 +00:00
fix the camera for real this time
This commit is contained in:
parent
8422fea462
commit
c9b38ad52c
3 changed files with 15 additions and 44 deletions
|
|
@ -205,12 +205,13 @@ class CameraController extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
public function updateFixed() {
|
||||
var dt = (1 / 60.0);
|
||||
// Math.min(1, 1 - Math.pow(0.6, dt / 0.032)); // hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600));
|
||||
public function update(currentTime:Float, dt:Float) {
|
||||
// camera.position.set(marblePosition.x, marblePosition.y, marblePosition.z).sub(directionVector.clone().multiplyScalar(2.5));
|
||||
// this.level.scene.camera.target = marblePosition.add(cameraVerticalTranslation);
|
||||
// camera.position.add(cameraVerticalTranslation);
|
||||
var camera = level.scene.camera;
|
||||
|
||||
CameraPitch = nextCameraPitch;
|
||||
CameraYaw = nextCameraYaw;
|
||||
var lerpt = 1 - Math.pow(0.5, dt / 0.016); // Math.min(1, 1 - Math.pow(0.6, dt / 0.032)); // hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600));
|
||||
|
||||
var gamepadX = applyNonlinearScale(rescaleDeadZone(Gamepad.getAxis(Settings.gamepadSettings.cameraXAxis), Settings.gamepadSettings.axisDeadzone));
|
||||
var gamepadY = rescaleDeadZone(Gamepad.getAxis(Settings.gamepadSettings.cameraYAxis), Settings.gamepadSettings.axisDeadzone);
|
||||
|
|
@ -292,27 +293,12 @@ class CameraController extends Object {
|
|||
nextCameraYaw += deltaX;
|
||||
nextCameraPitch += deltaY;
|
||||
nextCameraPitch = Math.max(-Math.PI / 2 + Math.PI / 4, Math.min(Math.PI / 2 - 0.0001, nextCameraPitch));
|
||||
}
|
||||
|
||||
var accumulatedTime:Float = 0.0;
|
||||
|
||||
public function update(currentTime:Float, dt:Float) {
|
||||
// camera.position.set(marblePosition.x, marblePosition.y, marblePosition.z).sub(directionVector.clone().multiplyScalar(2.5));
|
||||
// this.level.scene.camera.target = marblePosition.add(cameraVerticalTranslation);
|
||||
// camera.position.add(cameraVerticalTranslation);
|
||||
var camera = level.scene.camera;
|
||||
|
||||
accumulatedTime += dt;
|
||||
while (accumulatedTime >= 1 / 60.0) {
|
||||
updateFixed();
|
||||
accumulatedTime -= 1 / 60.0;
|
||||
}
|
||||
CameraYaw = Util.lerp(CameraYaw, nextCameraYaw, lerpt);
|
||||
CameraPitch = Util.lerp(CameraPitch, nextCameraPitch, lerpt);
|
||||
|
||||
CameraPitch = Util.clamp(CameraPitch, -0.35, 1.5); // Util.clamp(CameraPitch, -Math.PI / 12, Math.PI / 2);
|
||||
|
||||
var cameraYaw = Util.lerp(CameraYaw, nextCameraYaw, accumulatedTime / (1 / 60.0));
|
||||
var cameraPitch = Util.lerp(CameraPitch, nextCameraPitch, accumulatedTime / (1 / 60.0));
|
||||
|
||||
function getRotQuat(v1:Vector, v2:Vector) {
|
||||
function orthogonal(v:Vector) {
|
||||
var x = Math.abs(v.x);
|
||||
|
|
@ -364,8 +350,8 @@ class CameraController extends Object {
|
|||
this.level.replay.recordCameraState(CameraPitch, CameraYaw);
|
||||
}
|
||||
} else {
|
||||
cameraPitch = this.level.replay.currentPlaybackFrame.cameraPitch;
|
||||
cameraYaw = this.level.replay.currentPlaybackFrame.cameraYaw;
|
||||
CameraPitch = this.level.replay.currentPlaybackFrame.cameraPitch;
|
||||
CameraYaw = this.level.replay.currentPlaybackFrame.cameraYaw;
|
||||
}
|
||||
|
||||
var marblePosition = this.finish ? level.marble.collider.transform.getPosition() : level.marble.getAbsPos().getPosition();
|
||||
|
|
@ -389,10 +375,10 @@ class CameraController extends Object {
|
|||
var cameraVerticalTranslation = new Vector(0, 0, 0.55);
|
||||
|
||||
var q1 = new Quat();
|
||||
q1.initRotateAxis(0, 1, 0, cameraPitch);
|
||||
q1.initRotateAxis(0, 1, 0, CameraPitch);
|
||||
directionVector.transform(q1.toMatrix());
|
||||
// cameraVerticalTranslation.transform(q1.toMatrix());
|
||||
q1.initRotateAxis(0, 0, 1, cameraYaw);
|
||||
q1.initRotateAxis(0, 0, 1, CameraYaw);
|
||||
directionVector.transform(q1.toMatrix());
|
||||
// cameraVerticalTranslation.transform(q1.toMatrix());
|
||||
directionVector.transform(orientationQuat.toMatrix());
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ class Settings {
|
|||
jump: Key.SPACE,
|
||||
powerup: Key.MOUSE_LEFT,
|
||||
freelook: Key.MOUSE_MIDDLE,
|
||||
alwaysFreeLook: true,
|
||||
alwaysFreeLook: false,
|
||||
cameraSensitivity: 1.135,
|
||||
invertYAxis: false,
|
||||
respawn: Key.BACKSPACE,
|
||||
|
|
|
|||
|
|
@ -68,9 +68,6 @@ class CameraInput {
|
|||
prevMouse.y = e.relY;
|
||||
}
|
||||
|
||||
var accumulator = 0.0;
|
||||
var accumulatedVec = new Vector(0, 0);
|
||||
|
||||
interactive.onMove = (e) -> {
|
||||
e.propagate = true;
|
||||
if (!enabled)
|
||||
|
|
@ -105,25 +102,14 @@ class CameraInput {
|
|||
}
|
||||
|
||||
var dt = MarbleGame.instance.world.timeState.dt;
|
||||
accumulator += dt;
|
||||
|
||||
accumulatedVec.x += inpX;
|
||||
accumulatedVec.y += inpY;
|
||||
|
||||
if (accumulator >= (1 / 60.0)) {
|
||||
MarbleGame.instance.world.marble.camera.orbit(applyNonlinearScale(accumulatedVec.x) * (1 / 60.0) * 30,
|
||||
applyNonlinearScale(accumulatedVec.y) * (1 / 60.0) * 30, true);
|
||||
accumulator -= (1 / 60.0);
|
||||
accumulatedVec.x = 0;
|
||||
accumulatedVec.y = 0;
|
||||
}
|
||||
MarbleGame.instance.world.marble.camera.orbit(applyNonlinearScale((inpX / dt) * (1 / 60.0)) * (1 / 60.0) * 20,
|
||||
applyNonlinearScale((inpY / dt) * (1 / 60.0)) * (1 / 60.0) * 20, true);
|
||||
|
||||
if (inpX != 0)
|
||||
prevMouse.x = e.relX;
|
||||
if (inpY != 0)
|
||||
prevMouse.y = e.relY;
|
||||
} else {
|
||||
accumulator = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +123,6 @@ class CameraInput {
|
|||
|
||||
pressed = false;
|
||||
this.identifier = -1;
|
||||
accumulator = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue