XNA 中的透视/正交投影转换?

发布于 2024-10-08 07:24:53 字数 214 浏览 3 评论 0原文

我正在 XNA 中为横向卷轴类型游戏在正交投影中绘制一些几何图形。我想做的是在透视投影中渲染背景几何形状。

然而,我显然需要背景几何图形与前景“对齐”,即,如果在透视图中我将 3D 模型的位置设置为 300, 30,那么在正交投影中它会对齐到 300, 30。

有没有办法我能做到这一点吗?我一直在研究世界到屏幕投影,但不确定我是否走在正确的道路上。

感谢您的帮助!

I'm drawing some geometry in orthographic projection in XNA for a sidescroller type game. What I want to do is to render background geometry in perspective projection.

However I obviously need the background geometry to 'line up' with the foreground, i.e. if in perspective I set the position of a 3D model to 300, 30 then in the orthographic projection it lines up to 300, 30.

Is there a way I can accomplish this? I've been looking into world to screen projection but not sure if I'm on the right track.

Thanks for any help!

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

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

发布评论

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

评论(2

笔芯 2024-10-15 07:24:53

呵呵,这里躺着怪物……这确实说起来容易做起来难:-) 是的,您在世界/屏幕投影方面走在正确的轨道上。您需要做的是选择一个“Z”平面,将在其上渲染所有 2d 透视投影。然后,您要做的是将“Z”平面上您感兴趣的任何给定点隐藏到屏幕坐标,并在该点渲染正交投影。

Heh, here lie monsters ... this is easier said than done for sure :-) Yes, you are on the right track with world/screen projection. What you need to do is pick a "Z" plane that you will render all of your 2d perspective projections onto. Then what you do is covert any given point that you're interested in on that "Z" plane to screen coordinates, and render your orthographic projection at that spot.

谁的年少不轻狂 2024-10-15 07:24:53

Joel 是对的,如果能将 2d 和 3d 结合起来那就太理想了。 2d 用作正交视图,3d 用作透视图。
使用多个 2d 精灵代替正交视图进行 2d 渲染。
对于几何图形,您最好的选择是使用矩阵结构的辅助函数……

Matrix view = Matrix.CreatePerspective(.......)

以及其他类似的静态辅助函数……

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.matrix_members.aspx

另外对模型进行缩放、旋转、平移等变换,可以通过矩阵结构本身来实现。

Matrix oldWorld = Matrix.CreateWorld(...);

// something happens ; next update

Matrix scaleMat = Matrix.CreateScale(...);
Matrix rotXMat = Matrix.CreateRotationX(...);
Matrix rotYMat = Matrix.CreateRotationY(...);
Matrix rotZMat = Matrix.CreateRotationZ(...);
Matrix translationMat = Matrix.CreateTranslation(...);

Matrix newWorldMat = scaleMat*rotXMat*rotYMat*rotZMat*translationMat*oldWorldMat;

Joel is right, it would be ideal if you could combine 2d and 3d. 2d acts as orthographic view, and 3d for perspective view.
Use multiple 2d sprites for 2d rendering inplace of orthographic view.
With respect to geometry you best choice will be, using the helper functions of the Matrix structure.. something like,

Matrix view = Matrix.CreatePerspective(.......)

and other similar static helper functions....

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.matrix_members.aspx

Additionally to transform the models by scale, rotation, translation, can be achieved by the matrix structure itself.

Matrix oldWorld = Matrix.CreateWorld(...);

// something happens ; next update

Matrix scaleMat = Matrix.CreateScale(...);
Matrix rotXMat = Matrix.CreateRotationX(...);
Matrix rotYMat = Matrix.CreateRotationY(...);
Matrix rotZMat = Matrix.CreateRotationZ(...);
Matrix translationMat = Matrix.CreateTranslation(...);

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