投影矩阵
QMatrix4x4 m_projection;
投影矩阵计算
【相机的视场角fov,最近距离,zNear,最远距离zFar,宽高比aspect】
qreal aspect = qreal((mWidth)) / qreal(mHeight ? mHeight : 1);
// Set near plane to 3.0, far plane to 7.0, field of view 45 degrees
const qreal zNear = 0.2, zFar = 10000.0, fov = 75.0;
m_projection.setToIdentity();
m_projection.perspective(fov, aspect, zNear, zFar);
这个体型区域内的额 物体会被投影。
![1644639789(1) 1644639789(1)](https://img2022.cnblogs.com/blog/2704972/202202/2704972-20220212124012161-1200734647.png)
view 矩阵
描述相机(眼睛)是怎么观察 物体 的。
![1644640314(1) 1644640314(1)](https://img2022.cnblogs.com/blog/2704972/202202/2704972-20220212124012983-1969856787.png)
void updateCameraVectors()
{
glm::vec3 front;
front.x = -sin(glm::radians(Yaw)); //偏航角为正数,偏向x负半轴 front.y = sin(glm::radians(Pitch));
front.z = -cos(glm::radians(Pitch)) * cos(glm::radians(Yaw));
Front = glm::normalize(front);
Right = glm::normalize(glm::cross(Front, WorldUp));
Up = glm::normalize(glm::cross(Right, Front));
DEBUG_LOG("cam position : %f %f %f\n",Position.x,Position.y,Position.z);
DEBUG_LOG("cam rot : yaw %f pitch %f \n",Yaw,Pitch);
}
glm::mat4 GetViewMatrix() {
return glm::lookAt(Position, Position + Front, Up);
}
glm::mat4 view = virtualCamera::GetViewMatrix();
|
model 矩阵控制模型旋转
QMatrix4x4 model;
model.rotate(m_xrot, 1.0f, 0.0f, 0.0f);
model.rotate(m_yrot, 0.0f, 1.0f, 0.0f);
model.rotate(m_zrot, 0.0f, 0.0f, 1.0f);
|
MVP model view project 矩阵(其实是 project * view * model *obj)
将obj 坐标 渲染到屏幕上面的(u,v)点
(u,v) = projectMatrix * view * model * obj
QMatrix4x4 matrix(
view[0][0],view[1][0],view[2][0],view[3][0],
view[0][1],view[1][1],view[2][1],view[3][1],
view[0][2],view[1][2],view[2][2],view[3][2],
view[0][3],view[1][3],view[2][3],view[3][3]
);
m_program->setUniformValue("mvpMatrix", m_projection * matrix * model);
|
参考文档
https://blog.csdn.net/zhangpengzp/article/details/88749779
https://www.itranslater.com/qa/details/2582874717636002816
http://www.dovov.com/glm-lookat.html