簡體   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