【GAME101】作业 物体倒立、镜像问题

43 篇文章 30 订阅
22 篇文章 14 订阅

复制粘贴下面的投影矩阵函数:

Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar)
{
#// 初始化一个单位矩阵projection
	Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();

#/* 初始化一个单位矩阵persp2ortho,其作用为将透视点映射为适合
 #  进行正交投影的点*/
	Eigen::Matrix4f persp2ortho = Eigen::Matrix4f::Identity();
	persp2ortho << zNear, 0, 0, 0,
		0, zNear, 0, 0,
		0, 0, zNear + zFar, -zNear * zFar,
		0, 0, 1, 0;

	double halfEyeRadian = eye_fov * MY_PI / 2 / 180.0;
	double top = -zNear * tan(halfEyeRadian); //*zNear原本是正的,但我取-zNear求top,bottom,right,left就好了
	double bottom = -top;
	double right = top * aspect_ratio;
	double left = -right;

	Eigen::Matrix4f orthoScale = Eigen::Matrix4f::Identity();
	orthoScale << 2 / (right - left), 0, 0, 0,
		0, 2 / (top - bottom), 0, 0,
		0, 0, 2 / (zNear - zFar), 0,
		0, 0, 0, 1;

	Eigen::Matrix4f orthoTrans = Eigen::Matrix4f::Identity();
	orthoTrans << 1, 0, 0, -(right + left) / 2,
		0, 1, 0, -(top + bottom) / 2,
		0, 0, 1, -(zNear + zFar) / 2,
		0, 0, 0, 1;

	Eigen::Matrix4f matrixOrtho = orthoScale * orthoTrans;

	projection = matrixOrtho * persp2ortho;
	return projection;
}

主要是求出的摄像机nearPlane的四个方向距离top,bottom,right,left,必须全部取它的反数。

因此有了 double top = -zNear * tan(halfEyeRadian),其他3个值都是依赖top产生的,top取反,其他都会被取反。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值