using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Fake3D { public static class Camera2D { public static Matrix GetTransformationCenter(Vector2 pos, float zoom, float rotation) { if (zoom < float.Epsilon) zoom = float.Epsilon; return Matrix.CreateTranslation(new Vector3(-pos.X, -pos.Y, 0)) * Matrix.CreateRotationZ(rotation) * Matrix.CreateScale(new Vector3(zoom, zoom, 1)) * Matrix.CreateTranslation(new Vector3(MainGame.graphics.PreferredBackBufferWidth * 0.5f, MainGame.graphics.PreferredBackBufferHeight * 0.5f, 0)); } public static Matrix GetTransformationTopLeft(Vector2 pos, float zoom, float rotation) { Vector2 newPos = new Vector2(pos.X + (MainGame.graphics.PreferredBackBufferWidth / 2f) / zoom, pos.Y + (MainGame.graphics.PreferredBackBufferHeight / 2f) / zoom); if (zoom < float.Epsilon) zoom = float.Epsilon; return Matrix.CreateTranslation(new Vector3(-newPos.X, -newPos.Y, 0)) * Matrix.CreateRotationZ(rotation) * Matrix.CreateScale(new Vector3(zoom, zoom, 1)) * Matrix.CreateTranslation(new Vector3(MainGame.graphics.PreferredBackBufferWidth * 0.5f, MainGame.graphics.PreferredBackBufferHeight * 0.5f, 0)); } } }