Advertisement
Wolvenspud

canera

Oct 18th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9.  
  10. namespace GameTemplate
  11. {
  12.     public class Camera2d
  13.     {
  14.         protected float _zoom;
  15.         public Matrix _transform;
  16.         public Vector2 _pos;
  17.         protected float _rotation;
  18.  
  19.         public Camera2d()
  20.         {
  21.             _zoom = 1.0f;
  22.             _rotation = 0.0f;
  23.             _pos = Vector2.Zero;
  24.         }
  25.  
  26.         public float Zoom
  27.         {
  28.             get {return _zoom; }
  29.             set { _zoom = value; if (_zoom < 0.1f) _zoom = 0.1f; }
  30.         }
  31.  
  32.         public float Rotation
  33.         {
  34.             get { return _rotation; }
  35.             set { _rotation = value; }
  36.         }
  37.  
  38.         public void Move(Vector2 amount)
  39.         {
  40.             _pos += amount;
  41.         }
  42.  
  43.         public Vector2 Pos
  44.         {
  45.             get { return _pos; }
  46.             set { _pos = value; }
  47.         }
  48.  
  49.         public Matrix Get_transformation(GraphicsDeviceManager graphicsDevice)
  50.         {
  51.             _transform =
  52.                 Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
  53.                 Matrix.CreateRotationZ(Rotation) *
  54.                 Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
  55.                 Matrix.CreateTranslation(new Vector3(graphicsDevice.PreferredBackBufferWidth*0.5f, graphicsDevice.PreferredBackBufferHeight*0.5f, 0));
  56.             return _transform;
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement