1

在我的 XNA 游戏中,我使用 Viewport.Project 来获取太阳 3D 坐标的 2d 屏幕坐标(主要是因为它看起来不错)。我得到了这个工作,但是,当我朝太阳的相反方向看时,我看到了其中的两个(从技术上讲,一个)。我不知道这里发生了什么..

有谁知道发生了什么?我怎样才能防止这种情况发生?

为了帮助可视化这一点,这是我正在谈论的图像: 超链接图像,没有 10+ 代表

这是代码:

        Rectangle clientBounds = Window.ClientBounds;
        Texture2D sun = Content.Load<Texture2D>(@"Image\Skybox_Sun");
        Vector3 coords = new Vector3(1000, 0, 1000);
        Vector3 coords1 = graphics.GraphicsDevice.Viewport.Project(coords, camera.Projection, camera.View, Matrix.Identity);
        suncoords = coords1;
        spriteBatch.Begin();
        spriteBatch.Draw(sun, new Vector2(coords1.X, coords1.Y), null, Color.White, 0, new Vector2(cursor.Width / 2, cursor.Height / 2), q, SpriteEffects.None, 0);
        spriteBatch.End();
4

1 回答 1

2

你试过检查 coords1.Z 吗?我想你身后的太阳对应于负 Z,在这种情况下,你可以尝试在绘制之前添加一个 if 条件,如下所示:

if(coords1.Z > 0)
  spriteBatch.Draw(sun, new Vector2(coords1.X, coords1.Y), null, Color.White, 0, new Vector2(cursor.Width / 2, cursor.Height / 2), q, SpriteEffects.None, 0);
于 2012-03-19T02:52:23.403 回答