我的模型的比例似乎改变了他们的立场,但我不知道为什么。我是按照S-R-T顺序来做的。蓝色平面的原点为(0,0,0)。
模型矩阵的计算方法如下:
// set model matrix
glm::mat4 model = glm::mat4( 1.0f );
// scale
model = glm::scale( model, _entity.Scale );
// rotate
model = glm::rotate( model, glm::radians( _entity.Rotation.x ), glm::vec3( 1.0f, 0.0f, 0.0f ) );
model = glm::rotate( model, glm::radians( _entity.Rotation.y ), glm::vec3( 0.0f, 1.0f, 0.0f ) );
model = glm::rotate( model, glm::radians( _entity.Rotation.z ), glm::vec3( 0.0f, 0.0f, 1.0f ) );
// translate
model = glm::translate( model, _entity.Position );
Shader::setMat4( _shader, "model", model );
在着色器中,它看起来如下所示:
vs_out.FragPos = vec3(model * vec4(aPos, 1.0));
vs_out.Normal = mat3(transpose(inverse(model))) * aNormal;
vs_out.TexCoord = aTexCoord;
gl_Position = projection * view * vec4(vs_out.FragPos, 1.0);
第一张图片是1.0比例尺,第二张是10.0比例尺:
1条答案
按热度按时间relj7zay1#
我是按照S-R-T顺序来做的。
不是的。你要按T-R-S的顺序来做。S-R-T的顺序是
p' = translation * rotation * scale * p
。你必须从右到左阅读。