基本原语 - TriangleStrip - Monogame

时间:2014-01-22 23:55:51

标签: xna-4.0 monogame

我有一个工作的形状,但当我尝试更改坐标时它会消失。 这就是我所做的。

这是类级变量:

private BasicEffect _effect;
private VertexPositionColor[] _vertices = new VertexPositionColor[5];

然后在初始化方法中我把这些:

float aspectRatio = (float)GraphicsDevice.Viewport.Bounds.Width / GraphicsDevice.Viewport.Bounds.Height;
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 1000.0f);
Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up);

_effect = new BasicEffect(GraphicsDevice);
_effect.LightingEnabled = false;
_effect.TextureEnabled = false;
_effect.VertexColorEnabled = true;
_effect.Projection = projection;
_effect.View = view;
_effect.World = Matrix.Identity;

Color color = Color.Black;

_vertices[0] = new VertexPositionColor(new Vector3(-1, -1, 0), color);
_vertices[2] = new VertexPositionColor(new Vector3(-1, 1, 0), color);
_vertices[2] = new VertexPositionColor(new Vector3(1, -1, 0), color);
_vertices[3] = new VertexPositionColor(new Vector3(1, 1, 0), color);

在绘制方法中我把:

foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
{
    // Apply the pass
    pass.Apply();
    // Draw the square
    GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, _vertices, 0, 2);
}

这很好用。但当我把它改成这个时,它就不再起作用了。

_vertices[1].Position = new Vector3(-0.10f, 1.37f, -3.0f);
_vertices[0].Position = new Vector3(-0.15f, 1.40f, -3.0f);
_vertices[2].Position = new Vector3(-0.00f, 1.40f, -3.0f);
_vertices[4].Position = new Vector3(0.15f, 1.40f, -3.0f);
_vertices[3].Position = new Vector3(0.10f, 1.37f, -3.0f);

我做了另一个改变:

GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, _vertices, 0, 3);

任何想法?

提前致谢

1 个答案:

答案 0 :(得分:1)

  • 可能是您向后绘制多边形。这意味着您正在以错误的方向声明顶点,您可能需要更改顺序。我不确定哪个是声明顶点的正确方向。
  • 或者你可以关掉后面的剔除 多边形的两边。每个多边形的性能将达到2次。你可以尝试首先关闭它,如果它修复它,那么你知道我的第一点是原因。