我发现我修改相机pos的z轴图像始终都是一样大小, 我猜测可能是我的投影矩阵出现了问题, 希望各位大佬能指点一下.
我的投影矩阵:
void Rst::Rasterizer::SetProjection(float eyeFov, float aspectRatio, float zNear, float zFar)
{
Eigen::Vector4f temp = Eigen::Vector4f::Identity();
auto n = zNear;
auto f = zFar;
//KS: https://smuwm007.feishu.cn/docs/doccn2FNKtTm58i2R4jISC7vd4e#KufB6G
Eigen::Matrix4f p2o;
p2o <<
n, 0, 0, 0,
0, n, 0, 0,
0, 0, f + n, -f * n,
0, 0, 1, 0;
float halve = eyeFov / 2 * MY_PI / 180;
float top = -zNear * std::tan(halve);
float bottom = -top;
float right = top * aspectRatio;
float left = -right;
Eigen::Matrix4f m, s;
m <<
1, 0, 0, -(left + right) / 2,
0, 1, 0, -(top + bottom) / 2,
0, 0, 1, -(zNear + zFar) / 2,
0, 0, 0, 1;
s <<
2 / (right – left), 0, 0, 0,
0, 2 / (top – bottom), 0, 0,
0, 0, 2 / (zNear – zFar), 0,
0, 0, 0, 1;
projection = p2o * m * s;
}
Attachments:
You must be
logged in to view attached files.