28#include <SFML/Graphics/View.hpp>
46View::View(
const sf::Vector2f& Center,
const sf::Vector2f& HalfSize) :
80 myHalfSize.x = HalfWidth;
81 myHalfSize.y = HalfHeight;
130 const_cast<View*
>(
this)->RecomputeMatrix();
141 myCenter.x += OffsetX;
142 myCenter.y += OffsetY;
163 myHalfSize /= Factor;
172const Matrix3& View::GetMatrix()
const
176 const_cast<View*
>(
this)->RecomputeMatrix();
185void View::RecomputeMatrix()
188 float Left = myCenter.
x - myHalfSize.
x;
189 float Top = myCenter.
y - myHalfSize.
y;
190 float Right = myCenter.
x + myHalfSize.
x;
191 float Bottom = myCenter.
y + myHalfSize.
y;
194 myRect.
Left = std::min(Left, Right);
195 myRect.
Top = std::min(Top, Bottom);
196 myRect.
Right = std::max(Left, Right);
197 myRect.
Bottom = std::max(Top, Bottom);
200 myMatrix(0, 0) = 2.f / (Right - Left);
201 myMatrix(1, 1) = 2.f / (Top - Bottom);
202 myMatrix(0, 2) = (Left + Right) / (Left - Right);
203 myMatrix(1, 2) = (Bottom + Top) / (Bottom - Top);
205 myNeedUpdate =
false;
Utility class to manipulate 3x3 matrices representing 2D transformations.
T Top
Top coordinate of the rectangle.
T Right
Right coordinate of the rectangle.
T Left
Left coordinate of the rectangle.
T Bottom
Bottom coordinate of the rectangle.
T x
X coordinate of the vector.
T y
Y coordinate of the vector.
This class defines a view (position, size, etc.) ; you can consider it as a 2D camera.
void Zoom(float Factor)
Resize the view rectangle to simulate a zoom / unzoom effect.
const sf::Vector2f & GetHalfSize() const
Get the half-size of the view.
void SetHalfSize(float HalfWidth, float HalfHeight)
Change the half-size of the view (take 2 values).
View(const FloatRect &ViewRect=FloatRect(0, 0, 1000, 1000))
Construct the view from a rectangle.
void Move(float OffsetX, float OffsetY)
Move the view (take 2 values).
const sf::FloatRect & GetRect() const
Get the bounding rectangle of the view.
void SetFromRect(const FloatRect &ViewRect)
Rebuild the view from a rectangle.
const sf::Vector2f & GetCenter() const
Get the center of the view.
void SetCenter(float X, float Y)
Change the center of the view (take 2 values).