简体   繁体   English

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

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

I am creating a UI system in SFML based on the Object Hierarchy Example on the wiki.我正在基于 wiki 上的Object 层次结构示例在 SFML 中创建 UI 系统。 I have a TextBox node that contains an sf::Text object that I want to be displayed.我有一个 TextBox 节点,其中包含我想要显示的 sf::Text object。 My issue is that when I increase the scale factor of the sf::Text object, it zooms into the text making it appear pixely.我的问题是,当我增加 sf::Text object 的比例因子时,它会放大文本使其看起来像像素。 It would make much more sense to just increase the font size, but I cannot figure out how to apply the transformations of the parent node minus the scale factor to prevent the zooming in effect.只增加字体大小会更有意义,但我无法弄清楚如何应用父节点的转换减去比例因子来防止放大效果。 I have a very limited understanding of transformation matrices, which I gather are what applies the transformation.我对转换矩阵的理解非常有限,我收集到的是应用转换的东西。 Any advice on how to proceed is appreciated.任何关于如何进行的建议表示赞赏。

I eventually found this question which helped me separate the scale factor from the transform matrix.我最终发现了这个问题,它帮助我将比例因子与变换矩阵分开。 For those with a similar problem, here is the solution I came to:对于那些有类似问题的人,这是我得到的解决方案:

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