繁体   English   中英

在 SFML 中,如何在没有缩放因子的情况下应用转换?

[英]In SFML, how do I apply a transformation without the scaling factor?

我正在基于 wiki 上的Object 层次结构示例在 SFML 中创建 UI 系统。 我有一个 TextBox 节点,其中包含我想要显示的 sf::Text object。 我的问题是,当我增加 sf::Text object 的比例因子时,它会放大文本使其看起来像像素。 只增加字体大小会更有意义,但我无法弄清楚如何应用父节点的转换减去比例因子来防止放大效果。 我对转换矩阵的理解非常有限,我收集到的是应用转换的东西。 任何关于如何进行的建议表示赞赏。

我最终发现了这个问题,它帮助我将比例因子与变换矩阵分开。 对于那些有类似问题的人,这是我得到的解决方案:

const float* mat = states.transform.getMatrix();
float temp[16];
std::copy(mat, mat + 16, temp); // mat has 16 members, hence mat + 16 is the last member
float scalex = sqrtf((temp[0] * temp[0]) + (temp[1] * temp[1]));
float scaley = sqrtf((temp[4] * temp[4]) + (temp[5] * temp[5]));
// Remove scale from the final transform
sf::Transform textState(
    temp[0] / scalex, temp[1] / scaley, temp[12], 
    temp[4] / scalex, temp[5] / scaley, temp[13],
    0.f, 0.f, 1.f
    );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM