在我的XNA游戏中,我使用Viewport.Project来获取太阳3D坐标的2d屏幕坐标(主要是因为它看起来很棒)。然而,当我在太阳的相反方向上看时,我看到了其中的两个(严格来说,一个)。我不知道这里发生了什么..。
有人知道是怎么回事吗?我怎样才能防止这种情况呢?
为了帮助可视化这一点,这里有一个我正在讨论的图像:Hyperlinked image, don't have 10+ rep
代码如下:
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();发布于 2012-03-19 10:52:23
你有没有试过检查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);https://stackoverflow.com/questions/9764203
复制相似问题