我正在尝试使用MSDN http://msdn.microsoft.com/en-us/library/bb464051.aspx
中的示例代码在XNA中绘制纹理四边形但不是在XY平面上绘制它而是在XZ平面中绘制它
我用这个初始化那个四边形 this.quad = new Quad(Vector3.Zero,Vector3.Up,Vector3.Backward,1,1);
我几乎尝试了Normal和Left矢量的每个组合,无论四边形绘制在哪里,四边形都是完全黑色的。
我在这里做错了什么?当我传递它时纹理的信息丢失了吗?我映射纹理位置错了吗?
ps:纹理,灯光已启用。
public class Quad
{
public VertexPositionNormalTexture[] Vertices;
public Vector3 Origin;
public Vector3 Up;
public Vector3 Normal;
public Vector3 Left;
public Vector3 UpperLeft;
public Vector3 UpperRight;
public Vector3 LowerLeft;
public Vector3 LowerRight;
public int[] Indexes;
public Quad(Vector3 origin, Vector3 normal, Vector3 up,
float width, float height)
{
this.Vertices = new VertexPositionNormalTexture[4];
this.Indexes = new int[6];
this.Origin = origin;
this.Normal = normal;
this.Up = up;
// Calculate the quad corners
this.Left = Vector3.Cross(normal, this.Up);
Vector3 uppercenter = (this.Up * height / 2) + origin;
this.UpperLeft = uppercenter + (this.Left * width / 2);
this.UpperRight = uppercenter - (this.Left * width / 2);
this.LowerLeft = this.UpperLeft - (this.Up * height);
this.LowerRight = this.UpperRight - (this.Up * height);
this.FillVertices();
}
private void FillVertices()
{
Vector2 textureUpperLeft = new Vector2(0.0f, 0.0f);
Vector2 textureUpperRight = new Vector2(1.0f, 0.0f);
Vector2 textureLowerLeft = new Vector2(0.0f, 1.0f);
Vector2 textureLowerRight = new Vector2(1.0f, 1.0f);
for (int i = 0; i < this.Vertices.Length; i++)
{
this.Vertices[i].Normal = this.Normal;
}
this.Vertices[0].Position = this.LowerLeft;
this.Vertices[0].TextureCoordinate = textureLowerLeft;
this.Vertices[1].Position = this.UpperLeft;
this.Vertices[1].TextureCoordinate = textureUpperLeft;
this.Vertices[2].Position = this.LowerRight;
this.Vertices[2].TextureCoordinate = textureLowerRight;
this.Vertices[3].Position = this.UpperRight;
this.Vertices[3].TextureCoordinate = textureUpperRight;
this.Indexes[0] = 0;
this.Indexes[1] = 1;
this.Indexes[2] = 2;
this.Indexes[3] = 2;
this.Indexes[4] = 1;
this.Indexes[5] = 3;
}
}
我的绘制方法:
graphicsDevice.BlendState = BlendState.AlphaBlend;
Effect.World = Matrix.Identity;
Effect.View = Camera.View;
Effect.Projection = Camera.Projection;
Effect.TextureEnabled = true;
Effect.Texture = OilTexture;
Effect.EnableDefaultLighting();
Effect.PreferPerPixelLighting = true;
foreach (EffectPass pass in oilEffect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>
(PrimitiveType.TriangleList,
Vertices,
0,
4,
Indexes,
0,
2);
}
- 我解决了我的问题。当我将texture2d传递到3个地方时,出现了问题,现在我正在从主绘图中绘制它,纹理现在显示得很好。
答案 0 :(得分:0)
四边形可能有黑色的原因有很多,以下是我喜欢调试的一些事项:
如果这些都不能仔细查看您传递顶点闪电值的区域,顶点法线值以及向下照明硬件的区域。