XNA 查看矩阵 - 寻求解释 [英] XNA View Matrix - Seeking explanation

查看:21
本文介绍了XNA 查看矩阵 - 寻求解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解 XNA 中的视图矩阵时遇到了一些严重的问题.我已经完成了所有其他部分的工作,因为我刚刚自学了所需的数学知识,所以我不想在不了解它们首先做什么的情况下使用内置的矩阵函数.

I'm having some serious trouble understanding the view matrix in XNA. I've come pretty far with all the other parts and since I've just learnt myself the required maths I don't want to use the built in Matrix-functions without understanding what they do first.

现在我了解了旋转、投影和平移的基础知识,但我终生无法理解 XNA 中的视图矩阵是如何工作的.

Now I understand the basics of rotation, projection and translation but I can't for the life of me understand how the view matrix works in XNA.

从我收集到的信息来看,视图矩阵应该将世界"转换为它自己的空间.看起来很有道理,但是库中的Matrix.CreateLookAt方法却很让人费解.

From what I've gathered, the view matrix should transform the "world" to it's own space. Seems reasonable, but the Matrix.CreateLookAt method in the library is quite puzzling.

我已经确定(通过检查库函数输出的内容)这两段代码产生相同的结果:

I've established (through examining what the library function outputs) that these two pieces of code yield the same results:

Matrix view = Matrix.CreateReflection(new Plane(Vector3.UnitX, 0)) * Matrix.CreateReflection(new Plane(Vector3.UnitZ, 0)) * Matrix.CreateTranslation(Position);
// ..equals this if (Position = (0 0 -5), since LookAt "looks at" but the above just looks straight down Z)..
Matrix blah = Matrix.CreateLookAt(Position, Vector3.Zero, Vector3.UnitY);

为什么要翻转 X 轴和 Z 轴?我认为你应该根据相机的旋转来旋转世界,但在相反的方向,然后在相反的方向以相同的量平移世界.

Why flip the X and Z axes? I thought you should rotate the world according to the cameras rotation, but in the opposite direction, and then translate the world by the same amount in the opposite direction.

或者视图矩阵根本不用作变换,而只是编码相机在世界中的位置和旋转?

Or is the view matrix not used as a transformation at all but just encodes the position and rotation of the camera in the world?

推荐答案

视图矩阵正在将场景转换为视图空间.在视图空间中,虚拟相机位于原点并沿 z 轴正方向观察.有不同的方法可以实现这一点,但最常见的视图矩阵由围绕每个轴的平移和三个旋转组成.

The view matrix is transforming the scene into view space. In view space the virtual camera is at the origin and is looking in the positive z-direction. There are different ways to achieve this, but most commonly the view matrix consists of a translation and three rotations around each axis.

变换 = 平移 * RotationZ * RotationY * RotationX

Transform = Translate * RotationZ * RotationY * RotationX

这篇关于XNA 查看矩阵 - 寻求解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆