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