28 #include <SFML/Graphics/View.hpp>
48 myHalfSize (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;
172 const Matrix3& View::GetMatrix()
const
176 const_cast<View*
>(
this)->RecomputeMatrix();
185 void 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;
View(const FloatRect &ViewRect=FloatRect(0, 0, 1000, 1000))
Construct the view from a rectangle.
This class defines a view (position, size, etc.) ; you can consider it as a 2D camera.
T x
X coordinate of the vector.
const sf::Vector2f & GetCenter() const
Get the center of the view.
T Right
Right coordinate of the rectangle.
void SetCenter(float X, float Y)
Change the center of the view (take 2 values)
void SetFromRect(const FloatRect &ViewRect)
Rebuild the view from a rectangle.
const sf::Vector2f & GetHalfSize() const
Get the half-size of the view.
void Move(float OffsetX, float OffsetY)
Move the view (take 2 values)
Utility class to manipulate 3x3 matrices representing 2D transformations.
void Zoom(float Factor)
Resize the view rectangle to simulate a zoom / unzoom effect.
const sf::FloatRect & GetRect() const
Get the bounding rectangle of the view.
void SetHalfSize(float HalfWidth, float HalfHeight)
Change the half-size of the view (take 2 values)
T Bottom
Bottom coordinate of the rectangle.
T y
Y coordinate of the vector.
T Top
Top coordinate of the rectangle.
T Left
Left coordinate of the rectangle.