Table of Contents

Struct Viewport

Namespace
Stride.Graphics
Assembly
Stride.Graphics.dll

Defines the viewport dimensions of a render-target surface onto which a 3D volume projects.

public struct Viewport : IEquatable<Viewport>
Implements
Extension Methods

Constructors

Viewport(Rectangle)

Initializes a new instance of the 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)

Initializes a new instance of the Viewport struct.

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

Parameters

x int

The X coordinate of the upper-left corner of the viewport in pixels.

y int

The Y coordinate of the upper-left corner of the viewport in pixels.

width int

The width of the viewport in pixels.

height int

The height of the viewport in pixels.

Viewport(float, float, float, float)

Initializes a new instance of the Viewport struct.

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

Parameters

x float

The X coordinate of the upper-left corner of the viewport in pixels.

y float

The Y coordinate of the upper-left corner of the viewport in pixels.

width float

The width of the viewport in pixels.

height float

The height of the viewport in pixels.

Fields

Empty

Empty value for an undefined viewport.

public static readonly Viewport Empty

Field Value

Viewport

Height

Height dimension of the viewport on the render-target surface, in pixels.

public float Height

Field Value

float

MaxDepth

Maximum depth of the clip volume.

public float MaxDepth

Field Value

float

MinDepth

Minimum depth of the clip volume.

public float MinDepth

Field Value

float

Width

Width dimension of the viewport on the render-target surface, in pixels.

public float Width

Field Value

float

X

X coordinate of the upper-left corner of the viewport on the render-target surface, in pixels.

public float X

Field Value

float

Y

Y coordinate of the upper-left corner of the viewport on the render-target surface, in pixels.

public float Y

Field Value

float

Properties

AspectRatio

Gets the aspect ratio of the viewport, i.e. Width / Height.

public readonly float AspectRatio { get; }

Property Value

float

Bounds

Gets a rectangle with the location and size of the viewport.

public Rectangle Bounds { readonly get; set; }

Property Value

Rectangle

Size

Gets the size of the viewport.

public readonly Vector2 Size { get; }

Property Value

Vector2

Methods

Equals(Viewport)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(Viewport other)

Parameters

other Viewport

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Project(Vector3, Matrix, Matrix, Matrix)

Projects a 3D vector from object space into screen space.

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

Parameters

source Vector3

The vector 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.

public override readonly string ToString()

Returns

string

Unproject(Vector3, Matrix, Matrix, Matrix)

Converts a screen space point into a corresponding point in world space.

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

Parameters

source Vector3

The vector to unproject.

projection Matrix

The projection matrix.

view Matrix

The view matrix.

world Matrix

The world matrix.

Returns

Vector3

Unproject(Vector3, ref readonly Matrix)

Converts a screen space point into a corresponding point in world space.

public readonly Vector3 Unproject(Vector3 source, ref readonly Matrix worldViewProjection)

Parameters

source Vector3

The vector to unproject.

worldViewProjection Matrix

The World-View-Projection matrix.

Returns

Vector3

Operators

operator ==(Viewport, Viewport)

public static bool operator ==(Viewport left, Viewport right)

Parameters

left Viewport
right Viewport

Returns

bool

operator !=(Viewport, Viewport)

public static bool operator !=(Viewport left, Viewport right)

Parameters

left Viewport
right Viewport

Returns

bool