C# XNA - 我有一个相机看着一个点 - 那么为什么我还需要一个投影矩阵?逻辑问题

发布于 2024-10-26 09:05:32 字数 381 浏览 1 评论 0原文

我很好奇为什么没有投影矩阵就什么都不会显示,以及投影矩阵到底在做什么。我在MSNDN上搜索过,但没有结果,所以我想我应该尝试询问有使用经验的人。

我看一下要点:

viewMatrix = Matrix.CreateLookAt(camPos, trackPos, player.getMatrix().Up);

...根据我对其工作原理的理解,我不需要任何补充信息即可使相机正常工作。我可以使用投影矩阵使所有内容都显示良好,但我真的不明白为什么需要它/它到底要完成什么。

也许如果有人可以传递链接或简要解释它,我将能够更好地操纵该属性并从中获得一些更流畅的相机工作,但总的来说,我不喜欢使用我不完全理解的代码。

I am curious about why exactly nothing will display without a projection matrix and what exactly the projection matrix is doing. I've scoured MSNDN to no avail, so I thought I'd try asking someone with experience in it's use.

I have a look at point:

viewMatrix = Matrix.CreateLookAt(camPos, trackPos, player.getMatrix().Up);

...From my understanding of how this works I shouldn't need any supplemental information to make a camera work. I can make everything show up fine using a projection matrix but I really just don't understand why it is needed / what exactly it is accomplishing.

Maybe if someone can pass a link or explain it in brief I will be able to better manipulate the property and get some smoother camera work out of it, but overall I don't like using code I don't comprehend fully.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

破晓 2024-11-02 09:05:32

投影矩阵从相机空间变换到二维。

  • 世界矩阵 = 对象变换
  • 摄像机矩阵 = 将世界变换为摄像机空间
  • 投影矩阵 = 将摄像机空间变换为 2d 空间

如果没有投影,您将陷入 3d 状态,而且我们还没有 3d 监视器。

简单的例子:如果您有一个位于对象空间中心的对象并将旋转应用于世界矩阵,您将围绕其自身的中心旋转对象。

如果稍后旋转相机,所有对象都将围绕相机位置旋转。

稍后你需要看看你做了什么,然后你应用投影。它可以使用透视图,也可以不使用透视图。使用透视投影,您基本上将 x,y 除以 z,最简单的透视投影可能是:

x2d = x/z * screenwidth + screenwidth/2;
y2d = y/z * screenheight + screenheight/2;

这给我们一种“3d 感觉”,通过更深入 3d 空间的点靠近屏幕中间,想想经典的星场,您就会明白。要了解更多信息,您需要了解基本的线性代数,我建议您从感兴趣的地方开始!

The projection matrix transforms from camera space to 2d.

  • World matrix = Object transformation
  • Camera matrix = Transforms World to Camera space
  • Projection matrix = Transforms Camera space to 2d space

Without Projection you are stuck in 3d, and we dont have 3d monitors (yet).

Easy example: If you have a object centered in object space and apply rotation to world matrix you will rotate object around its own centre.

If you later on rotate the camera, all objects will rotate around the cameras position.

Later on you will need to want to see what you have done, then you apply the projection. It can either use perspective or not. With perspective projection you basically divide the x,y with z, the most trivial perspective projection is probably:

x2d = x/z * screenwidth + screenwidth/2;
y2d = y/z * screenheight + screenheight/2;

This gives us a "3d feeling" by points further into 3d space being closer middle of screen, think of a classic star field and youll understand. For more information you will need to understand basic linear algebra, and I suggest you start there as you are interested!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文