2021SC@SDUSC
目录
书接上回,本文我们来讲一下矩阵在图形变换中最重要的变换,就是怎么将3维空间的物体转换为2维的图像。
观察矩阵(View)
在一个3维场景中,物体的坐标都基于场景的世界坐标系建立,而为了将世界坐标系中的坐标投影到屏幕上,我们首先需要将物体的坐标转换到摄像机的的坐标空间,俗称观察空间。


以下的代码返回了一个观察矩阵view,它的参数有9个,分别构成3个3维向量。
OvMaths::FMatrix4 OvMaths::FMatrix4::CreateView(const float p_eyeX, const float p_eyeY, const float p_eyeZ, const float p_lookX, const float p_lookY, const float p_lookZ, const float p_upX, const float p_upY, const float p_upZ)
{
const OvMaths::FVector3 eye(p_eyeX, p_eyeY, p_eyeZ);
const OvMaths::FVector3 look(p_lookX, p_lookY, p_lookZ);
const OvMaths::FVector3 up(p_upX, p_upY, p_upZ);
const OvMaths::FVector3 forward(eye - look);
FVector3::Normalize(forward);
const OvMaths::FVector3 upXForward(OvMaths::FVector3::Cross(up, forward));
FVector3::Normalize(upXForward);
const OvMaths::FVector3 v(OvMaths::FVector3::Cross(forward, upXForward));
OvMaths::FMatrix4 View;
View.data[0] = upXForward.x;
View.data[1] = upXForward.y;
View.data[2] = upXForward.z;
View.data[3] = -OvMaths::FVector3::Dot(eye, upXForward);
View.data[4] = v.x;
View.data[5] = v.y;
View.data[6] = v.z;
View.data[7] = -OvMaths::FVector3::Dot(eye, v);
View.data[8] = forward.x;
View.da

本文继续深入分析Overload游戏引擎的OvMaths函数库,主要讨论观察矩阵、透视矩阵和正交矩阵在图形变换中的应用。观察矩阵用于将3D物体坐标转换到摄像机坐标空间;透视矩阵模拟真实世界的近大远小效果,通过CreatePerspective和CreateFrustum函数实现;正交矩阵则将坐标映射到2D立方体空间,用于正交投影。文章详细介绍了每个矩阵的计算过程和作用。
最低0.47元/天 解锁文章
2364

被折叠的 条评论
为什么被折叠?



