问题描述
我正在查看 "SFML/Graphics/Transform.h"
和 "SFML/Graphics/Transformable.h"
标题,我不能
明白一件事。我最小化
课程,以便你们可以轻松获得:
// "SFML/Graphics/Transform.h"
class Transform
{
public:
// Default constructor
Transform();
// Construct a transform from a 3X3 matrix
Transform(float a00,float a01,float a02,float a10,float a11,float a12,float a20,float a21,float a22);
};
// "SFML/Graphics/Transformable.h"
class Transformable
{
private:
Vector2f mPosition; // Position of the object in 2D world.
float mRotation; // Orientation of the object,in degress.
Vector2f mScale; // Scale of the object.
Vector2f mOrigin; // Origin of translation,rotation and scaling.of the object.
mutable Transform mTransform; // Combined transformation of the object.
mutable bool mTransformNeedUpdate; // Does the transform need to be recomputed?
mutable Transform mInverseTransform; // Combined transformation of the object.
mutable bool mInverseTransformNeedUpdate; // Does the transform need to be recomputed?
public:
// Functions to implement transformation
void setPostion(float x,float y);
void setPosition(const Vector2f& position);
void setRotation(float angle);
void setScale(float factorX,float factorY);
void setScale(const Vector2f& factors);
void setorigin(float x,float y);
void setorigin(const Vector2f& orgin);
const Vector2f& getPosition() const;
float getRotation() const;
const Vector2f& getScale() const;
const Vector2f& getorigin() const;
void move(float offsetX,float offsetY);
void move(const Vector2f& offset);
void rotate(float angle);
void scale(float factorX,float factorY);
void scale(const Vector2f& factors);
// What I don't understand
const Transform& getTransform() const;
const Transform& getInverseTransform() const;
};
在 "SFML/Graphics/Transformable.cpp"
中的 "getTransform()"
函数
实现如下代码:
const Transform& Transformable::getTransform() const
{
// Recompute the combined transform if needed
if (mTransformNeedUpdate)
{
float angle = -mRotation * 3.141592654f / 180.f;
float cosine = static_cast<float>(std::cos(angle));
float sine = static_cast<float>(std::sin(angle));
float sxc = mScale.x * cosine;
float syc = mScale.y * cosine;
float sxs = mScale.x * sine;
float sys = mScale.y * sine;
float tx = -mOrigin.x * sxc - mOrigin.y * sys + mPosition.x;
float ty = mOrigin.x * sxs - mOrigin.y * syc + mPosition.y;
mTransform = Transform( sxc,sys,tx,-sxs,syc,ty,0.f,1.f);
mTransformNeedUpdate = false;
}
return mTransform;
}
我的问题是他们如何实现这些值:sxc
、syc
、sxs
、sys
、tx
、ty
就像那样,为什么他们按那个顺序把它们放到 3X3 矩阵中。
非常感谢!!!