sf::View Class Reference

2D camera that defines what region is shown on screen More...

#include <View.hpp>

List of all members.

Public Member Functions

 View ()
 Default constructor.
 View (const FloatRect &rectangle)
 Construct the view from a rectangle.
 View (const Vector2f &center, const Vector2f &size)
 Construct the view from its center and size.
void SetCenter (float x, float y)
 Set the center of the view.
void SetCenter (const Vector2f &center)
 Set the center of the view.
void SetSize (float width, float height)
 Set the size of the view.
void SetSize (const Vector2f &size)
 Set the size of the view.
void SetRotation (float angle)
 Set the orientation of the view.
void SetViewport (const FloatRect &viewport)
 Set the target viewport.
void Reset (const FloatRect &rectangle)
 Reset the view to the given rectangle.
const Vector2fGetCenter () const
 Get the center of the view.
const Vector2fGetSize () const
 Get the size of the view.
float GetRotation () const
 Get the current orientation of the view.
const FloatRectGetViewport () const
 Get the target viewport rectangle of the view.
void Move (float offsetX, float offsetY)
 Move the view relatively to its current position.
void Move (const Vector2f &offset)
 Move the view relatively to its current position.
void Rotate (float angle)
 Rotate the view relatively to its current orientation.
void Zoom (float factor)
 Resize the view rectangle relatively to its current size.
const Matrix3GetMatrix () const
 Get the projection matrix of the view.
const Matrix3GetInverseMatrix () const
 Get the inverse projection matrix of the view.

Detailed Description

2D camera that defines what region is shown on screen

sf::View defines a camera in the 2D scene.

This is a very powerful concept: you can scroll, rotate or zoom the entire scene without altering the way that your drawable objects are drawn.

A view is composed of a source rectangle, which defines what part of the 2D scene is shown, and a target viewport, which defines where the contents of the source rectangle will be displayed on the render target (window or render-image).

The viewport allows to map the scene to a custom part of the render target, and can be used for split-screen or for displaying a minimap, for example. If the source rectangle has not the same size as the viewport, its contents will be stretched to fit in.

To apply a view, you have to assign it to the render target. Then, every objects drawn in this render target will be affected by the view until you use another view.

Usage example:

 sf::RenderWindow window;
 sf::View view;
 
 // Initialize the view to a rectangle going from (100, 100) to (500, 300)
 view.Reset(sf::FloatRect(100, 100, 500, 300));

 // Rotate it by 45 degrees
 view.Rotate(45);

 // Set its target viewport to be half of the window
 view.SetViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));

 // Apply it
 window.SetView(view);

 // Render stuff
 window.Draw(someSprite);

 // Set the default view back
 window.SetView(window.GetDefaultView());

 // Render stuff not affected by the view
 window.Draw(someText);
See also:
RenderWindow, RenderImage

Definition at line 43 of file View.hpp.


Constructor & Destructor Documentation

sf::View::View (  ) 

Default constructor.

This constructor creates a default view of (0, 0, 1000, 1000)

Definition at line 34 of file View.cpp.

sf::View::View ( const FloatRect rectangle  )  [explicit]

Construct the view from a rectangle.

Parameters:
rectangle Rectangle defining the zone to display

Definition at line 47 of file View.cpp.

sf::View::View ( const Vector2f center,
const Vector2f size 
)

Construct the view from its center and size.

Parameters:
center Center of the zone to display
size Size of zone to display

Definition at line 60 of file View.cpp.


Member Function Documentation

const Vector2f & sf::View::GetCenter (  )  const

Get the center of the view.

Returns:
Center of the view
See also:
GetSize, SetCenter

Definition at line 139 of file View.cpp.

const Matrix3 & sf::View::GetInverseMatrix (  )  const

Get the inverse projection matrix of the view.

This functions is meant for internal use only.

Returns:
Inverse of the projection matrix defining the view
See also:
GetMatrix

Definition at line 209 of file View.cpp.

const Matrix3 & sf::View::GetMatrix (  )  const

Get the projection matrix of the view.

This functions is meant for internal use only.

Returns:
Projection matrix defining the view
See also:
GetInverseMatrix

Definition at line 195 of file View.cpp.

float sf::View::GetRotation (  )  const

Get the current orientation of the view.

Returns:
Rotation angle of the view, in degrees
See also:
SetRotation

Definition at line 153 of file View.cpp.

const Vector2f & sf::View::GetSize (  )  const

Get the size of the view.

Returns:
Size of the view
See also:
GetCenter, SetSize

Definition at line 146 of file View.cpp.

const FloatRect & sf::View::GetViewport (  )  const

Get the target viewport rectangle of the view.

Returns:
Viewport rectangle, expressed as a factor of the target size
See also:
SetViewport

Definition at line 160 of file View.cpp.

void sf::View::Move ( const Vector2f offset  ) 

Move the view relatively to its current position.

Parameters:
offset Move offset
See also:
SetCenter, Rotate, Zoom

Definition at line 174 of file View.cpp.

void sf::View::Move ( float  offsetX,
float  offsetY 
)

Move the view relatively to its current position.

Parameters:
offsetX X coordinate of the move offset
offsetY Y coordinate of the move offset
See also:
SetCenter, Rotate, Zoom

Definition at line 167 of file View.cpp.

void sf::View::Reset ( const FloatRect rectangle  ) 

Reset the view to the given rectangle.

Note that this function resets the rotation angle to 0. It is a function provided for convenience, equivalent to the following calls:

 view.SetCenter(rectangle.GetCenter());
 view.SetSize(rectangle.GetSize());
 view.SetRotation(0);
Parameters:
rectangle Rectangle defining the zone to display
See also:
SetCenter, SetSize, SetRotation

Definition at line 127 of file View.cpp.

void sf::View::Rotate ( float  angle  ) 

Rotate the view relatively to its current orientation.

Parameters:
angle Angle to rotate, in degrees
See also:
SetRotation, Move, Zoom

Definition at line 181 of file View.cpp.

void sf::View::SetCenter ( const Vector2f center  ) 

Set the center of the view.

Parameters:
center New center
See also:
SetSize, GetCenter

Definition at line 83 of file View.cpp.

void sf::View::SetCenter ( float  x,
float  y 
)

Set the center of the view.

Parameters:
x X coordinate of the new center
y Y coordinate of the new center
See also:
SetSize, GetCenter

Definition at line 72 of file View.cpp.

void sf::View::SetRotation ( float  angle  ) 

Set the orientation of the view.

The default rotation of a view is 0 degree.

Parameters:
angle New angle, in degrees
See also:
GetRotation

Definition at line 108 of file View.cpp.

void sf::View::SetSize ( const Vector2f size  ) 

Set the size of the view.

Parameters:
size New size
See also:
SetCenter, GetCenter

Definition at line 101 of file View.cpp.

void sf::View::SetSize ( float  width,
float  height 
)

Set the size of the view.

Parameters:
width New width of the view
height New height of the view
See also:
SetCenter, GetCenter

Definition at line 90 of file View.cpp.

void sf::View::SetViewport ( const FloatRect viewport  ) 

Set the target viewport.

The viewport is the rectangle into which the contents of the view are displayed, expressed as a factor (between 0 and 1) of the size of the RenderTarget to which the view is applied. For example, a view which takes the left side of the target would be defined with View.SetViewport(sf::FloatRect(0, 0, 0.5, 1)). By default, a view has a viewport which covers the entire target.

Parameters:
viewport New viewport rectangle
See also:
GetViewport

Definition at line 120 of file View.cpp.

void sf::View::Zoom ( float  factor  ) 

Resize the view rectangle relatively to its current size.

Resizing the view simulates a zoom, as the zone displayed on screen grows or shrinks. factor is a multiplier:

  • 1 keeps the size unchanged
  • > 1 makes the view bigger (objects appear smaller)
  • < 1 makes the view smaller (objects appear bigger)
Parameters:
factor Zoom factor to apply
See also:
SetSize, Move, Rotate

Definition at line 188 of file View.cpp.


The documentation for this class was generated from the following files: