简体   繁体   English

xna在固定屏幕坐标上将3d对象显示为2d

[英]xna display 3d objects as 2d on fixed screen coord

helllo, I'm trying to create a minecraft-like inventory which renders items and blocks on the screen in different slots. 您好,我正在尝试创建一个类似于Minecraft的清单,以在屏幕上的不同插槽中呈现项目和块。 I have an array of vertices of a block and I want to draw it at a spesific screen coordinates at a spesific size. 我有一个块的顶点数组,我想以特定的大小在特定的屏幕坐标处绘制它。

BTW, this is the code I'm currently using, it is working but I can't deteminate a spesific position or a size: 顺便说一句,这是我当前正在使用的代码,它正在工作,但是我无法确定特定的位置或大小:

 Vector2 coord = new Vector2(-4, 0); //Screen coord.
 int distance = 20; //Distance of the camera from the block(control the size).

  BlockRenderer.basicTextureEffect.View = Matrix.Identity * Matrix.CreateLookAt(new Vector3(-distance, distance * 0.6f, -distance), Vector3.One / 2, Vector3.Up) *  Matrix.CreateTranslation(coord.X, coord.Y, 0);
  BlockRenderer.basicTextureEffect.CurrentTechnique.Passes[0].Apply();
  graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertex, 0, vertex.Length / 3);

thank you for your help! 谢谢您的帮助!

Your matrixs need to be swapped. 您的矩阵需要交换。 You want the identity matrix to be at the end. 您希望身份矩阵位于末尾。 Matrix translations are interpreted from right to left. 矩阵翻译从右到左进行解释。 The matrix.identity is in reference to the origin of the cameras view. matrix.identity是指摄影机视图的原点。 If you have view.lookat(matrix.identity * myMatrix); 如果您有view.lookat(matrix.identity * myMatrix); myMatrix isnt interpreted correctly if you are depending on your object to be at the viewports origin. 如果依赖于对象位于视口的原点,则不会正确解释myMatrix。

Heres a good reference. 这是一个很好的参考。

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Coll_Detection_Matrices.php http://www.riemers.net/chi/Tutorials/XNA/Csharp/Series2D/Coll_Detection_Matrices.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM