小编Nil*_*Qor的帖子

具有缩放拉伸纵横比的 glm 旋转

我正在尝试使用 glm 旋转纹理图像,但输出看起来被拉伸或未沿 z 轴正确旋转。对于这个问题,可能的解决方案是什么?

在此输入图像描述

float imgAspectRatio = imageWidth / (float) imageHeight;
float viewAspectRatio = viewWidth / (float) viewHeight;

if (imgAspectRatio > viewAspectRatio) {
    yScale = viewAspectRatio / imgAspectRatio;
} else {
    xScale = imgAspectRatio / viewAspectRatio;
}

glm::mat4 model(1.0f);
model = glm::translate(model, glm::vec3(0, 0, 0));
model = glm::rotate(model, glm::radians(angle),
                    glm::vec3(0, 0, 1));
model = glm::scale(model, glm::vec3(xScale, yScale, 1.0f));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 有些人建议与 glm::ortho 相乘,但它给出的是正方形

glm::mat4 projection(1.0f);    
projection = glm::ortho(
              -imgAspectRatio,             
              imgAspectRatio,              
              -1.0f,      
              1.0f,       
              -1.0f,              
              1.0f                
      );
Run Code Online (Sandbox Code Playgroud)

c++ opengl scaling rotation glm-math

1
推荐指数
1
解决办法
1375
查看次数

标签 统计

c++ ×1

glm-math ×1

opengl ×1

rotation ×1

scaling ×1