【问题标题】:Basic Primitive - TriangleStrip - Monogame基本原语 - TriangleStrip - Monogame
【发布时间】:2014-06-04 23:11:01
【问题描述】:

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

这是类级别的变量:

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);

在draw方法中我放了:

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);

有什么想法吗?

提前致谢

【问题讨论】:

    标签: xna-4.0 monogame


    【解决方案1】:
    • 可能是您正在向后绘制多边形。这意味着您在错误的方向声明顶点,您可能需要更改顺序。我不确定哪个是声明顶点的正确方向。
    • 或者,您可以关闭背面剔除,这将绘制 多边形的两边。这将对每个多边形产生 2 次平局的性能影响。您可以先尝试将其关闭,如果它解决了它,那么您就知道我的第一点是原因。

    【讨论】:

    • 是的,我想我解决了你提到的方式,或者我的项目有问题。
    猜你喜欢
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多