Advertisement
Guest User

Camera

a guest
Mar 5th, 2012
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8.  
  9. namespace Cerios.Miner.Cameras
  10. {
  11.     public class Camera
  12.     {
  13.         public Viewport Viewport
  14.         {
  15.             get;
  16.             private set;
  17.         }
  18.  
  19.         public Camera(Viewport viewport)
  20.         {
  21.             Viewport = viewport;
  22.             Origin = new Vector2(viewport.Width / 2.0f, viewport.Height / 2.0f);
  23.             Position = Vector2.Zero;
  24.             Zoom = 1f;
  25.         }
  26.  
  27.         public Vector2 Position { get; set; }
  28.         public float Rotation { get; set; }
  29.         public Vector2 Origin { get; set; }
  30.         public float Zoom { get; set; }
  31.  
  32.         public Matrix TransformMatrix
  33.         {
  34.             get
  35.             {
  36.                 return Matrix.CreateRotationZ(Rotation) * Matrix.CreateScale(Zoom) *
  37.                        Matrix.CreateTranslation(Position.X, Position.Y, 0);
  38.             }
  39.         }
  40.  
  41.         public Matrix GetParallaxMatrix(Vector2 parallax)
  42.         {
  43.             return Matrix.CreateTranslation(new Vector3(-Position * parallax, 0.0f)) *
  44.                    Matrix.CreateTranslation(new Vector3(-Origin, 0.0f)) *
  45.                    Matrix.CreateRotationZ(Rotation) *
  46.                    Matrix.CreateScale(Zoom, Zoom, 1) *
  47.                    Matrix.CreateTranslation(new Vector3(Origin, 0.0f));
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement