Table of Contents

Struct Viewport

Namespace
Microsoft.Xna.Framework.Graphics
Assembly
MonoGame.Framework.dll

Describes the view bounds for render-target surface.

[DataContract]
public struct Viewport
Inherited Members

Constructors

Viewport(Rectangle)

Creates a new instance of Viewport struct.

public Viewport(Rectangle bounds)

Parameters

bounds Rectangle

A Rectangle that defines the location and size of the Viewport in a render target.

Viewport(int, int, int, int)

Constructs a viewport from the given values. The MinDepth will be 0.0 and MaxDepth will be 1.0.

public Viewport(int x, int y, int width, int height)

Parameters

x int

The x coordinate of the upper-left corner of the view bounds in pixels.

y int

The y coordinate of the upper-left corner of the view bounds in pixels.

width int

The width of the view bounds in pixels.

height int

The height of the view bounds in pixels.

Viewport(int, int, int, int, float, float)

Constructs a viewport from the given values.

public Viewport(int x, int y, int width, int height, float minDepth, float maxDepth)

Parameters

x int

The x coordinate of the upper-left corner of the view bounds in pixels.

y int

The y coordinate of the upper-left corner of the view bounds in pixels.

width int

The width of the view bounds in pixels.

height int

The height of the view bounds in pixels.

minDepth float

The lower limit of depth.

maxDepth float

The upper limit of depth.

Properties

AspectRatio

Gets the aspect ratio of this Viewport, which is width / height.

public float AspectRatio { get; }

Property Value

float

Bounds

Gets or sets a boundary of this Viewport.

public Rectangle Bounds { get; set; }

Property Value

Rectangle

Height

The height of the bounds in pixels.

[DataMember]
public int Height { get; set; }

Property Value

int

MaxDepth

The upper limit of depth of this viewport.

[DataMember]
public float MaxDepth { get; set; }

Property Value

float

MinDepth

The lower limit of depth of this viewport.

[DataMember]
public float MinDepth { get; set; }

Property Value

float

TitleSafeArea

Returns the subset of the viewport that is guaranteed to be visible on a lower quality display.

public Rectangle TitleSafeArea { get; }

Property Value

Rectangle

Width

The width of the bounds in pixels.

[DataMember]
public int Width { get; set; }

Property Value

int

X

The x coordinate of the beginning of this viewport.

[DataMember]
public int X { get; set; }

Property Value

int

Y

The y coordinate of the beginning of this viewport.

[DataMember]
public int Y { get; set; }

Property Value

int

Methods

Project(Vector3, Matrix, Matrix, Matrix)

Projects a Vector3 from model space into screen space. The source point is transformed from model space to world space by the world matrix, then from world space to view space by the view matrix, and finally from view space to screen space by the projection matrix.

public Vector3 Project(Vector3 source, Matrix projection, Matrix view, Matrix world)

Parameters

source Vector3

The Vector3 to project.

projection Matrix

The projection Matrix.

view Matrix

The view Matrix.

world Matrix

The world Matrix.

Returns

Vector3

ToString()

Returns a string representation of this Viewport in the format: {X:[X] Y:[Y] Width:[Width] Height:[Height] MinDepth:[MinDepth] MaxDepth:[MaxDepth]}

public override string ToString()

Returns

string

A string representation of this Viewport.

Unproject(Vector3, Matrix, Matrix, Matrix)

Unprojects a Vector3 from screen space into model space. The source point is transformed from screen space to view space by the inverse of the projection matrix, then from view space to world space by the inverse of the view matrix, and finally from world space to model space by the inverse of the world matrix. Note source.Z must be less than or equal to MaxDepth.

public Vector3 Unproject(Vector3 source, Matrix projection, Matrix view, Matrix world)

Parameters

source Vector3

The Vector3 to unproject.

projection Matrix

The projection Matrix.

view Matrix

The view Matrix.

world Matrix

The world Matrix.

Returns

Vector3