From 95677c8ff23c7fd0e5ba4dfd159e89b0c6f3ab98 Mon Sep 17 00:00:00 2001 From: Simon Holmberg Date: Fri, 28 Sep 2012 00:47:24 +0200 Subject: [PATCH] Zooming stuff. Barely. --- DepthsBelow/DepthsBelow/Camera.cs | 35 ++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/DepthsBelow/DepthsBelow/Camera.cs b/DepthsBelow/DepthsBelow/Camera.cs index 86a2af9..23b964b 100644 --- a/DepthsBelow/DepthsBelow/Camera.cs +++ b/DepthsBelow/DepthsBelow/Camera.cs @@ -18,6 +18,8 @@ namespace DepthsBelow private Core core; + private MouseState lastMouseState; + public Camera(Core core) { this.core = core; @@ -54,11 +56,34 @@ namespace DepthsBelow if (ms.Y > core.GraphicsDevice.Viewport.Height - 20) Position.Y += Speed * elapsed; - Transform = - Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) - * Matrix.CreateRotationZ(Rotation) - * Matrix.CreateScale(Zoom) - ; + int scrollChange = ms.ScrollWheelValue - lastMouseState.ScrollWheelValue; + + float preZoom = Zoom; + + if (scrollChange > 0) + Zoom *= 1.15f; + else if (scrollChange < 0) + Zoom /= 1.15f; + + Transform = Matrix.Identity + * Matrix.CreateRotationZ(Rotation) + * Matrix.CreateScale(Zoom) + * Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)); + + /*var mouseOffset = core.camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); + + if (scrollChange != 0) + { + Transform *= Matrix.CreateTranslation(new Vector3(-mouseOffset.X, -mouseOffset.Y, 0)) + * Matrix.CreateScale(Zoom) + * Matrix.CreateTranslation(new Vector3(mouseOffset.X, mouseOffset.Y, 0)); + } + else + { + Transform *= Matrix.CreateScale(Zoom) * Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)); ; + }*/ + + lastMouseState = ms; } } }