source: 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Camera/Camera.cs @ 5581

Revision 5581, 1.5 KB checked in by mijoilmo, 5 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Microsoft.Xna.Framework;
5using Microsoft.Xna.Framework.Content;
6using Microsoft.Xna.Framework.Graphics;
7
8namespace WindowsGame1
9{
10    public class Camera
11    {
12        public Vector2 offset = Vector2.Zero;
13        public float zoomFactor = 1;
14        public float pitch = -45;
15        public float yaw = 0;
16        public Camera()
17        {
18
19        }
20        public Matrix getMatrix(Vector2 gridSize, Vector2 mapSize, Vector2 screenSize)
21        {
22            viewPortBounds();
23
24            Vector3 pixelMapSize = new Vector3((gridSize.X * mapSize.X / 2), (gridSize.Y * mapSize.Y / 2), 0);
25            return Matrix.CreateTranslation(new Vector3(-pixelMapSize.X + offset.X, -pixelMapSize.Y + offset.Y, 0)) *
26                Matrix.CreateRotationZ(MathHelper.ToRadians(45 + yaw)) *
27                Matrix.CreateRotationX(MathHelper.ToRadians(pitch)) *
28                Matrix.CreateScale(zoomFactor, zoomFactor, 0) *
29                Matrix.CreateTranslation(new Vector3(screenSize.X / 2, screenSize.Y / 2, 0));
30        }
31        void viewPortBounds()
32        {
33            //rajoittaa viewporttia
34
35            //if (yaw < -70) { yaw = -70; } else if (yaw > 70) { yaw = 70; }//rajoita pyörittämistä (-70 - 70)
36            if (pitch < -88) { pitch = -88; } else if (pitch > -45) { pitch = -45; }//rajoittaa ylös-alas-liikettä
37            if (zoomFactor < 0.4f) { zoomFactor = 0.4f; } else if (zoomFactor > 3f) { zoomFactor = 3f; }//rajoittaa zoomia
38        }
39    }
40}
Note: See TracBrowser for help on using the repository browser.