4 using System.Globalization;
5 using System.Runtime.InteropServices;
6 using SiliconStudio.Core.Mathematics;
8 namespace SiliconStudio.
Paradox.Graphics
13 [StructLayout(LayoutKind.Sequential, Pack = 4)]
46 public Viewport(
int x,
int y,
int width,
int height)
63 Height = bounds.Height;
71 get {
return new Rectangle((
int)X, (
int)Y, (
int)Width, (
int)Width); }
77 Height = value.Height;
83 return other.X.Equals(X) && other.
Y.Equals(Y) && other.Width.Equals(Width) && other.
Height.Equals(Height) && other.MinDepth.Equals(MinDepth) && other.
MaxDepth.Equals(MaxDepth);
86 public override bool Equals(
object obj)
88 if (ReferenceEquals(null, obj))
return false;
89 if (obj.GetType() != typeof (
Viewport))
return false;
97 int result = X.GetHashCode();
98 result = (result*397) ^ Y.GetHashCode();
99 result = (result*397) ^ Width.GetHashCode();
100 result = (result*397) ^ Height.GetHashCode();
101 result = (result*397) ^ MinDepth.GetHashCode();
102 result = (result*397) ^ MaxDepth.GetHashCode();
109 return left.Equals(right);
114 return !left.Equals(right);
120 return string.Format(CultureInfo.CurrentCulture,
"{{X:{0} Y:{1} Width:{2} Height:{3} MinDepth:{4} MaxDepth:{5}}}",
new object[] { X, Y, Width, Height, MinDepth, MaxDepth });
123 private static bool WithinEpsilon(
float a,
float b)
126 return ((-1.401298E-45f <= num) && (num <=
float.Epsilon));
136 Matrix matrix = Matrix.Multiply(Matrix.Multiply(world, view), projection);
137 Vector4 vector = Vector3.Transform(source, matrix);
138 float a = (((source.X * matrix.M14) + (source.Y * matrix.
M24)) + (source.Z * matrix.
M34)) + matrix.
M44;
139 if (!WithinEpsilon(a, 1f))
141 vector = (vector /
a);
143 vector.X = (((vector.X + 1f) * 0.5f) * Width) + X;
144 vector.Y = (((-vector.Y + 1f) * 0.5f) * Height) + Y;
145 vector.Z = (vector.Z * (MaxDepth - MinDepth)) + MinDepth;
146 return new Vector3(vector.
X, vector.
Y, vector.
Z);
156 Matrix matrix = Matrix.Invert(Matrix.Multiply(Matrix.Multiply(world, view), projection));
157 source.X = (((source.X - X) / Width) * 2f) - 1f;
158 source.Y = -((((source.Y - Y) / Height) * 2f) - 1f);
159 source.Z = (source.Z - MinDepth) / (MaxDepth - MinDepth);
160 Vector4 vector = Vector3.Transform(source, matrix);
161 float a = (((source.X * matrix.M14) + (source.Y * matrix.
M24)) + (source.Z * matrix.
M34)) + matrix.
M44;
162 if (!WithinEpsilon(a, 1f))
166 return new Vector3(vector.
X, vector.
Y, vector.
Z);
170 public float AspectRatio
174 if ( Width != 0 && Height != 0)
176 return ((
float) Width)/Height;
override bool Equals(object obj)
float Width
Gets or sets the width dimension of the viewport on the render-target surface, in pixels...
float Height
Gets or sets the height dimension of the viewport on the render-target surface, in pixels...
float X
The X component of the vector.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
bool Equals(Viewport other)
float MinDepth
Gets or sets the minimum depth of the clip volume.
Represents a three dimensional mathematical vector.
float MaxDepth
Gets or sets the maximum depth of the clip volume.
Vector3 Project(Vector3 source, Matrix projection, Matrix view, Matrix world)
Projects a 3D vector from object space into screen space.
float X
Gets or sets the pixel coordinate of the upper-left corner of the viewport on the render-target surfa...
float M44
Value at row 4 column 4 of the matrix.
Viewport(Rectangle bounds)
Creates an instance of this object.
Vector3 Unproject(Vector3 source, Matrix projection, Matrix view, Matrix world)
Converts a screen space point into a corresponding point in world space.
Represents a four dimensional mathematical vector.
Viewport(int x, int y, int width, int height)
Creates an instance of this object.
Defines the window dimensions of a render-target surface onto which a 3D volume projects.
float Y
Gets or sets the pixel coordinate of the upper-left corner of the viewport on the render-target surfa...
override string ToString()
Retrieves a string representation of this object.
float Y
The Y component of the vector.
System.Windows.Shapes.Rectangle Rectangle
static readonly Viewport Empty
Empty value for an undefined viewport.
float M34
Value at row 3 column 4 of the matrix.
SiliconStudio.Core.Mathematics.Vector3 Vector3
float Z
The Z component of the vector.
Structure using the same layout than System.Drawing.Rectangle
override int GetHashCode()
float M24
Value at row 2 column 4 of the matrix.
Represents a 4x4 mathematical matrix.