Struct sfml::graphics::Transform
[−]
[src]
#[repr(C)]pub struct Transform(pub sfTransform);
Define a 3x3 transform matrix.
A Transform
specifies how to translate,
rotate, scale, shear, project, whatever things.
Methods
impl Transform
[src]
fn new(matrix: [f32; 9]) -> Transform
Create a new transform from a 3x3 matrix
Arguments
matrix - An array supplying the matrix
Here is an illustration of how the array elements correspond to the matrix elements:
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
Return a new Transform
fn matrix(&self) -> [f32; 16]
Return the matrix
fn identity() -> Self
The identity transform (does nothing)
fn inverse(&mut self) -> Transform
Return the inverse of a transform
If the inverse cannot be computed, a new identity transform is returned.
Return the inverse matrix
fn combine(&mut self, other: &mut Transform)
Combine two transforms
The result is a transform that is equivalent to applying transform followed by other. Mathematically, it is equivalent to a matrix multiplication.
Arguments
- other - Transform to combine to transform
fn translate(&mut self, x: f32, y: f32)
Combine a transform with a translation
Arguments
- x - Offset to apply on X axis
- y - Offset to apply on Y axis
fn rotate(&mut self, angle: f32)
fn rotate_with_center(&mut self, angle: f32, center_x: f32, center_y: f32)
Combine the current transform with a rotation
The center of rotation is provided for convenience as a second argument, so that you can build rotations around arbitrary points more easily (and efficiently) than the usual [translate(-center), rotate(angle), translate(center)].
Arguments
- angle - Rotation angle, in degrees
- center_x - X coordinate of the center of rotation
- center_y - Y coordinate of the center of rotation
fn scale(&mut self, scale_x: f32, scale_y: f32)
Combine the current transform with a scaling
Arguments
- scale_x - Scaling factor on the X axis
- scale_y - Scaling factor on the Y axis
fn scale_with_center(
&mut self,
scale_x: f32,
scale_y: f32,
center_x: f32,
center_y: f32
)
&mut self,
scale_x: f32,
scale_y: f32,
center_x: f32,
center_y: f32
)
Combine the current transform with a scaling
The center of scaling is provided for convenience as a second argument, so that you can build scaling around arbitrary points more easily (and efficiently) than the usual [translate(-center), scale(factors), translate(center)]
Arguments
- scale_x - Scaling factor on X axis
- scale_y - Scaling factor on Y axis
- center_x - X coordinate of the center of scaling
- center_y - Y coordinate of the center of scaling
fn transform_point(&mut self, point: &Vector2f) -> Vector2f
fn transform_rect(&mut self, rectangle: &FloatRect) -> FloatRect
Apply a transform to a rectangle
Since SFML doesn't provide support for oriented rectangles, the result of this function is always an axis-aligned rectangle. Which means that if the transform contains a rotation, the bounding rectangle of the transformed rectangle is returned.
Arguments
rectangle - Rectangle to transform
Return the transformed rectangle