使用第一人称相机在 XNA 中绘制纹理基元

发布于 2024-08-28 05:47:31 字数 1532 浏览 7 评论 0原文

所以我设置了一个 XNA 应用程序。相机处于第一人称模式,用户可以使用键盘移动并使用鼠标重新定位相机目标。我已经能够很好地加载 3D 模型,并且它们在屏幕上显示没有问题。每当我尝试绘制任何图元(有纹理或无纹理)时,无论我如何放置相机,它都不会显示在屏幕上的任何位置。

在Initialize() 中,我有:

        quad = new Quad(Vector3.Zero, Vector3.UnitZ, Vector3.Up, 2, 2);

        quadVertexDecl = new VertexDeclaration(this.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

在LoadContent() 中,我有:

        quadTexture = Content.Load<Texture2D>(@"Textures\brickWall");

        quadEffect = new BasicEffect(this.GraphicsDevice, null);
        quadEffect.AmbientLightColor = new Vector3(0.8f, 0.8f, 0.8f);
        quadEffect.LightingEnabled = true;
        quadEffect.World = Matrix.Identity;
        quadEffect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
        quadEffect.Projection = this.Projection;
        quadEffect.TextureEnabled = true;
        quadEffect.Texture = quadTexture;

在Draw() 中我有:

        this.GraphicsDevice.VertexDeclaration = quadVertexDecl;
        quadEffect.Begin();

        foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes)
        {
            pass.Begin();
            GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(
                     PrimitiveType.TriangleList,
                     quad.Vertices, 0, 4,
                     quad.Indexes, 0, 2);

            pass.End();
        }

        quadEffect.End();

我认为我在quadEffect 属性中做错了什么,但我不太确定是什么。

So I have a XNA application set up. The camera is in first person mode, and the user can move around using the keyboard and reposition the camera target with the mouse. I have been able to load 3D models fine, and they appear on screen no problem. Whenever I try to draw any primitive (textured or not), it does not show up anywhere on the screen, no matter how I position the camera.

In Initialize(), I have:

        quad = new Quad(Vector3.Zero, Vector3.UnitZ, Vector3.Up, 2, 2);

        quadVertexDecl = new VertexDeclaration(this.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

In LoadContent(), I have:

        quadTexture = Content.Load<Texture2D>(@"Textures\brickWall");

        quadEffect = new BasicEffect(this.GraphicsDevice, null);
        quadEffect.AmbientLightColor = new Vector3(0.8f, 0.8f, 0.8f);
        quadEffect.LightingEnabled = true;
        quadEffect.World = Matrix.Identity;
        quadEffect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
        quadEffect.Projection = this.Projection;
        quadEffect.TextureEnabled = true;
        quadEffect.Texture = quadTexture;

And in Draw() I have:

        this.GraphicsDevice.VertexDeclaration = quadVertexDecl;
        quadEffect.Begin();

        foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes)
        {
            pass.Begin();
            GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(
                     PrimitiveType.TriangleList,
                     quad.Vertices, 0, 4,
                     quad.Indexes, 0, 2);

            pass.End();
        }

        quadEffect.End();

I think I'm doing something wrong in the quadEffect properties, but I'm not quite sure what.

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

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

发布评论

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

评论(1

攀登最高峰 2024-09-04 05:47:31

我无法在工作的计算机上运行此代码,因为我没有安装游戏工作室。但作为参考,请查看创作者俱乐部网站上的 3D 音频样本。他们在该项目中有一个“QuadDrawer”,它演示了如何在世界上的任何位置绘制纹理四边形。对于您想要做的事情来说,这是一个非常好的解决方案:-)

http:// Creators.xna.com/en-US/sample/3daudio

I can't run this code on the computer here at work as I don't have game studio installed. But for reference, check out the 3D audio sample on the creator's club website. They have a "QuadDrawer" in that project which demonstrates how to draw a textured quad in any position in the world. It's a pretty nice solution for what it seems you want to do :-)

http://creators.xna.com/en-US/sample/3daudio

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