Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace GameTemplate
- {
- public class Camera2d
- {
- protected float _zoom;
- public Matrix _transform;
- public Vector2 _pos;
- protected float _rotation;
- public Camera2d()
- {
- _zoom = 1.0f;
- _rotation = 0.0f;
- _pos = Vector2.Zero;
- }
- public float Zoom
- {
- get {return _zoom; }
- set { _zoom = value; if (_zoom < 0.1f) _zoom = 0.1f; }
- }
- public float Rotation
- {
- get { return _rotation; }
- set { _rotation = value; }
- }
- public void Move(Vector2 amount)
- {
- _pos += amount;
- }
- public Vector2 Pos
- {
- get { return _pos; }
- set { _pos = value; }
- }
- public Matrix Get_transformation(GraphicsDeviceManager graphicsDevice)
- {
- _transform =
- Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
- Matrix.CreateRotationZ(Rotation) *
- Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
- Matrix.CreateTranslation(new Vector3(graphicsDevice.PreferredBackBufferWidth*0.5f, graphicsDevice.PreferredBackBufferHeight*0.5f, 0));
- return _transform;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement