Question

I had a working shape but when I try to change the coordinates it disappears. Here is what I did.

This is class level variables:

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

Then in Initialization method I put these:

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

And in draw method I put:

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

This is working fine. but when I change it to this one it doesn't work anymore.

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

another change that i made:

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

any idea?

Thanks in advance

Was it helpful?

Solution

  • It may be that you are drawing your polygons backwards. Meaning you are declaring your vertices in the wrong direction and you may need to change the order. I am not sure which is the correct direction to declare vertices.
  • Alternatively you can turn off back face culling which will draw both sides of polygons. This will have a performance hit 2 draws for each polygon. You could try turning this off first and if it fixes it then you know that my first point is the cause.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top