【问题标题】:Textured Primitives in XNA with a first person camera带有第一人称相机的 XNA 中的纹理基元
【发布时间】:2010-04-12 19:29:40
【问题描述】:

所以我设置了一个 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 属性中做错了,但我不太确定是什么。

【问题讨论】:

    标签: xna primitive perspectivecamera


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-25
      • 2013-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多