mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Changed Transform::Combine to modify *this (more consistent with other functions)
This commit is contained in:
parent
48c7db52c3
commit
b8ea003eae
@ -135,18 +135,18 @@ public :
|
|||||||
FloatRect TransformRect(const FloatRect& rectangle) const;
|
FloatRect TransformRect(const FloatRect& rectangle) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Combine two transforms
|
/// \brief Combine the current transform with another one
|
||||||
///
|
///
|
||||||
/// The result is a transform that is equivalent to applying
|
/// The result is a transform that is equivalent to applying
|
||||||
/// *this followed by \a transform. Mathematically, it is
|
/// *this followed by \a transform. Mathematically, it is
|
||||||
/// equivalent to a matrix multiplication.
|
/// equivalent to a matrix multiplication.
|
||||||
///
|
///
|
||||||
/// \param transform Transform to combine to this transform
|
/// \param transform Transform to combine with this transform
|
||||||
///
|
///
|
||||||
/// \return New combined transform
|
/// \return Reference to *this
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Transform Combine(const Transform& transform) const;
|
Transform& Combine(const Transform& transform);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Combine the current transform with a translation
|
/// \brief Combine the current transform with a translation
|
||||||
@ -365,7 +365,7 @@ private:
|
|||||||
/// \relates sf::Transform
|
/// \relates sf::Transform
|
||||||
/// \brief Overload of binary operator * to combine two transforms
|
/// \brief Overload of binary operator * to combine two transforms
|
||||||
///
|
///
|
||||||
/// This call is equivalent to calling left.Combine(right).
|
/// This call is equivalent to calling Transform(left).Combine(right).
|
||||||
///
|
///
|
||||||
/// \param left Left operand (the first transform)
|
/// \param left Left operand (the first transform)
|
||||||
/// \param right Right operand (the second transform)
|
/// \param right Right operand (the second transform)
|
||||||
@ -379,7 +379,7 @@ SFML_GRAPHICS_API Transform operator *(const Transform& left, const Transform& r
|
|||||||
/// \relates sf::Transform
|
/// \relates sf::Transform
|
||||||
/// \brief Overload of binary operator *= to combine two transforms
|
/// \brief Overload of binary operator *= to combine two transforms
|
||||||
///
|
///
|
||||||
/// This call is equivalent to calling left = left.Combine(right).
|
/// This call is equivalent to calling left.Combine(right).
|
||||||
///
|
///
|
||||||
/// \param left Left operand (the first transform)
|
/// \param left Left operand (the first transform)
|
||||||
/// \param right Right operand (the second transform)
|
/// \param right Right operand (the second transform)
|
||||||
|
@ -139,12 +139,12 @@ FloatRect Transform::TransformRect(const FloatRect& rectangle) const
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Transform Transform::Combine(const Transform& transform) const
|
Transform& Transform::Combine(const Transform& transform)
|
||||||
{
|
{
|
||||||
const float* a = myMatrix;
|
const float* a = myMatrix;
|
||||||
const float* b = transform.myMatrix;
|
const float* b = transform.myMatrix;
|
||||||
|
|
||||||
return Transform(a[0] * b[0] + a[4] * b[1] + a[12] * b[3],
|
*this = Transform(a[0] * b[0] + a[4] * b[1] + a[12] * b[3],
|
||||||
a[0] * b[4] + a[4] * b[5] + a[12] * b[7],
|
a[0] * b[4] + a[4] * b[5] + a[12] * b[7],
|
||||||
a[0] * b[12] + a[4] * b[13] + a[12] * b[15],
|
a[0] * b[12] + a[4] * b[13] + a[12] * b[15],
|
||||||
a[1] * b[0] + a[5] * b[1] + a[13] * b[3],
|
a[1] * b[0] + a[5] * b[1] + a[13] * b[3],
|
||||||
@ -153,6 +153,8 @@ Transform Transform::Combine(const Transform& transform) const
|
|||||||
a[3] * b[0] + a[7] * b[1] + a[15] * b[3],
|
a[3] * b[0] + a[7] * b[1] + a[15] * b[3],
|
||||||
a[3] * b[4] + a[7] * b[5] + a[15] * b[7],
|
a[3] * b[4] + a[7] * b[5] + a[15] * b[7],
|
||||||
a[3] * b[12] + a[7] * b[13] + a[15] * b[15]);
|
a[3] * b[12] + a[7] * b[13] + a[15] * b[15]);
|
||||||
|
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -163,7 +165,7 @@ Transform& Transform::Translate(float x, float y)
|
|||||||
0, 1, y,
|
0, 1, y,
|
||||||
0, 0, 1);
|
0, 0, 1);
|
||||||
|
|
||||||
return *this = Combine(translation);
|
return Combine(translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -185,7 +187,7 @@ Transform& Transform::Rotate(float angle)
|
|||||||
sin, cos, 0,
|
sin, cos, 0,
|
||||||
0, 0, 1);
|
0, 0, 1);
|
||||||
|
|
||||||
return *this = Combine(rotation);
|
return Combine(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -200,7 +202,7 @@ Transform& Transform::Rotate(float angle, float centerX, float centerY)
|
|||||||
sin, cos, centerY * (1 - cos) - centerX * sin,
|
sin, cos, centerY * (1 - cos) - centerX * sin,
|
||||||
0, 0, 1);
|
0, 0, 1);
|
||||||
|
|
||||||
return *this = Combine(rotation);
|
return Combine(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -218,7 +220,7 @@ Transform& Transform::Scale(float scaleX, float scaleY)
|
|||||||
0, scaleY, 0,
|
0, scaleY, 0,
|
||||||
0, 0, 1);
|
0, 0, 1);
|
||||||
|
|
||||||
return *this = Combine(scaling);
|
return Combine(scaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -229,7 +231,7 @@ Transform& Transform::Scale(float scaleX, float scaleY, float centerX, float cen
|
|||||||
0, scaleY, centerY * (1 - scaleY),
|
0, scaleY, centerY * (1 - scaleY),
|
||||||
0, 0, 1);
|
0, 0, 1);
|
||||||
|
|
||||||
return *this = Combine(scaling);
|
return Combine(scaling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -250,14 +252,14 @@ Transform& Transform::Scale(const Vector2f& factors, const Vector2f& center)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Transform operator *(const Transform& left, const Transform& right)
|
Transform operator *(const Transform& left, const Transform& right)
|
||||||
{
|
{
|
||||||
return left.Combine(right);
|
return Transform(left).Combine(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Transform& operator *=(Transform& left, const Transform& right)
|
Transform& operator *=(Transform& left, const Transform& right)
|
||||||
{
|
{
|
||||||
return left = left.Combine(right);
|
return left.Combine(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user