diff --git a/src/camera.zig b/src/camera.zig index bd055a62..f415bae2 100644 --- a/src/camera.zig +++ b/src/camera.zig @@ -60,7 +60,12 @@ pub const ViewBobbing = struct { // MARK: ViewBobber const xBob = @sin(time); const a = 0.5 * -@sin(2 * time); const zBob = ((a - a * a * a / 3) * 2 + 0.25 - 0.25 * @cos(2 * time)) * 0.8; - const bobVec = vec.rotateZ(Vec3d{xBob * magnitude * 0.05, 0, zBob * magnitude * 0.05}, -rotation[2]); + var bobVec = vec.rotateZ(Vec3d{xBob * magnitude * 1.05, 0, zBob * magnitude * 1.05}, -rotation[2]); + const eyeMin = game.Player.eyePos - game.Player.desiredEyePos + game.Player.eyeBox.min; + const eyeMax = game.Player.eyePos - game.Player.desiredEyePos + game.Player.eyeBox.max; + const eyeBoxSize = game.Player.eyeBox.max - game.Player.eyeBox.min; + const scaling = @as(Vec3d, @splat(1)) - @as(Vec3d, @splat(2)) * @abs(game.Player.eyePos) / eyeBoxSize; + bobVec = @max(eyeMin, @min(bobVec * scaling, eyeMax)); return bobVec; } diff --git a/src/game.zig b/src/game.zig index 9be1bfb9..426b16d9 100644 --- a/src/game.zig +++ b/src/game.zig @@ -328,7 +328,7 @@ pub const Player = struct { // MARK: Player .min = -outerBoundingBoxExtent, .max = outerBoundingBoxExtent, }; - const eyeBox: collision.Box = .{ + pub const eyeBox: collision.Box = .{ .min = -Vec3d{outerBoundingBoxExtent[0]*0.2, outerBoundingBoxExtent[1]*0.2, 0.6}, .max = Vec3d{outerBoundingBoxExtent[0]*0.2, outerBoundingBoxExtent[1]*0.2, 0.9 - 0.05}, }; @@ -722,8 +722,6 @@ pub fn update(deltaTime: f64) void { // MARK: update() main.Window.scrollOffset = 0; } - camera.ViewBobbing.update(deltaTime); - // This our model for movement on a single frame: // dv/dt = a - λ·v // dx/dt = v @@ -925,6 +923,7 @@ pub fn update(deltaTime: f64) void { // MARK: update() Player.eyePos = @max(Player.eyeBox.min, @min(Player.eyePos, Player.eyeBox.max)); Player.eyeCoyote -= deltaTime; + camera.ViewBobbing.update(deltaTime); camera.position = Player.getEyePosBlocking(); const biome = world.?.playerBiome.load(.monotonic);