transform - 我正在研究 SFML,我真的很想深入了解关于以下内容的转换:对象的位置、旋转、缩放和原点
问题描述
我正在查看"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, 0.f, 1.f);
mTransformNeedUpdate = false;
}
return mTransform;
}
我的问题是他们如何实现这些值:sxc
, syc
, sxs
, sys
, tx
, ty
,以及为什么他们按该顺序将它们放入 3X3 矩阵中。十分感谢!!!
解决方案
推荐阅读
- php - 在 Laravel 中使用很多包是不是很糟糕?
- node.js - npx react-native init AwesomeProject 错误 enolocal
- angular-material - 角度材料步进标题水平线和底部边框css
- javascript - setState 方法中的回调函数什么时候执行?
- mono - 如何使用 Visual Studio Mac 成功运行/调试 NUnit + SpecFlow 测试
- java - 使用 firebase 时任务尚未完成
- java - XLConnect 错误:NoClassDefFoundError (Java):org/apache/poi/openxml4j/exceptions/InvalidFormatException
- vb.net - VB.net Aforge 视频捕获 - 内存被消耗并冻结相机
- c# - 解析文件时出现 OutOfMemoryException
- javascript - 调用 Linking Event Listener 后,Formik State 返回 OLD 而不是 RECENT 或 CURRENT 值