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