/
VisualPortManager.cs
104 lines (88 loc) · 2.24 KB
/
VisualPortManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Microsoft.Xna.Framework;
using System;
namespace Moggle
{
/// <summary>
/// Convierte puntos linealmente entre dos sistemas de coordenadas.
/// </summary>
[Obsolete]
public class VisualPortManager
{
/// <summary>
/// Tamaño
/// </summary>
public Point Tamaño { get { return ÁreaVisible.Size; } }
/// <summary>
/// Devuelve o establece el rectángulo universo.
/// </summary>
/// <value>The universo.</value>
public Rectangle Universo { get; set; }
/// <summary>
/// Devuelve o establece el rectángulo de salida.
/// </summary>
/// <value>The sistema salida.</value>
public Rectangle SistemaSalida { get; set; }
#region Transformaciones elementales
// T es de la forma AX+B
Vector2 _A;
Vector2 _B;
void RefreshIntValues ()
{
_A = new Vector2 (
(float)SistemaSalida.Width / Universo.Width,
(float)SistemaSalida.Height / Universo.Height);
_B = new Vector2 (
SistemaSalida.Left - _A.X * Universo.Left,
SistemaSalida.Top - _A.Y * Universo.Top);
}
#endregion
/// <summary>
/// Devuelve o establece el área visible
/// </summary>
public Rectangle ÁreaVisible { get; set; }
/// <summary>
/// Convierte de universo a ventana
/// </summary>
public Point UniversoAVentana (Point p)
{
return UniversoAVentana (p.ToVector2 ()).ToPoint ();
}
/// <summary>
/// Convierte de ventana a universo
/// </summary>
public Point VentanaAUniverso (Point p)
{
return VentanaAUniverso (p.ToVector2 ()).ToPoint ();
}
/// <summary>
/// Convierte de universo a ventana
/// </summary>
public Vector2 UniversoAVentana (Vector2 p)
{
return _A * p + _B;
}
/// <summary>
/// Convierte de ventana a universo
/// </summary>
public Vector2 VentanaAUniverso (Vector2 p)
{
return new Vector2 ((p.X - _B.X) / _A.X, (p.Y - _B.Y) / _A.Y);
}
/// <summary>
/// Convierte de universo a ventana
/// </summary>
public Rectangle UniversoAVentana (Rectangle rect)
{
return new Rectangle (
UniversoAVentana (rect.Location),
(_A * rect.Size.ToVector2 ()).ToPoint ());
}
/// <summary>
/// Convierte de ventana a universo
/// </summary>
public Rectangle VentanaAUniverso (Rectangle rect)
{
throw new NotImplementedException ();
}
}
}