欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

Gams101作业1

时间:2023-06-06

虚拟机

Eigen::Matrix4f get_view_matrix(Eigen::Vector3f eye_pos){ Eigen::Matrix4f view = Eigen::Matrix4f::Identity(); Eigen::Matrix4f translate; translate << 1, 0, 0, -eye_pos[0], 0, 1, 0, -eye_pos[1], 0, 0, 1, -eye_pos[2], 0, 0, 0, 1; view = translate * view; return view;}

// 包括绕Y,Z轴,自定义的K轴

Eigen::Matrix4f get_model_matrix(float rotation_angle){ Eigen::Matrix4f model = Eigen::Matrix4f::Identity(); float angle = rotation_angle * MY_PI / 180.0; Eigen::Matrix4f rotate_matrix; // rotate it aroun the Z axis //rotate_matrix<< // cos(angle), -sin(angle), 0.0, 0.0, // sin(angle), cos(angle), 0.0, 0.0, // 0.0, 0.0, 1.0, 0.0, // 0.0, 0.0, 0.0, 1.0; // rotate it around the Y axis// rotate_matrix<

Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar){ Eigen::Matrix4f projection = Eigen::Matrix4f::Identity(); float angle = eye_fov * MY_PI / 180.0; auto t = tan(angle/2)*-zNear; auto r = aspect_ratio*t; auto l = -r; auto b = -t; // perspective->orth Eigen::Matrix4f PersToOrth; Eigen::Matrix4f Orth; Eigen::Matrix4f orthTranslation; Eigen::Matrix4f orthScale; PersToOrth << zNear,0,0,0, 0,zNear,0,0, 0,0,zNear+zFar,-zNear*zFar, 0,0,1,0; orthTranslation<<1,0,0,-(l+r)/2.0, 0,1,0,-(t+b)/2.0, 0,0,1,-(zNear+zFar)/2.0, 0,0,0,1; orthScale<< 2.0/(r-l),0,0,0, 0,2.0/(t-b),0,0, 0,0,2.0/(zNear-zFar),0, 0,0,0,1; Orth = orthScale*orthTranslation; projection = Orth*PersToOrth*projection; return projection;}

参考链接:
提高参考 百度百科:罗德里格旋转公式
透视矩阵的推导及几大矩阵的理论

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。