4

This is a noob question but I've searched extensively and cannot find the answer.

I've got two separate meshes that need to be drawn in the same window, both using DrawUserIndexedPrimitives. I'm using two BasicEffect instances with their own view & projection matrices.

However when these are rendered there's a line joining the two together. XNA thinks they're part of the same mesh. Do I need to use a separate GraphicsDeviceManager instance for each one? That does not seem right..

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
    GraphicsDevice.VertexDeclaration = declaration;

    effect.Begin();
    effect.View = view;

    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    {
        pass.Begin();
        GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, positions1, 0, positions1.Length, index1, 0, index1.Length / 3);
        pass.End();
    }

    effect.End();

    effect2.Begin();
    effect2.View = view2;

    foreach (EffectPass pass in effect2.CurrentTechnique.Passes)
    {
        pass.Begin();
        GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, positions2, 0, positions2.Length, index2, 0, index2.Length / 3);
        pass.End();
    }

    effect2.End();

    base.Draw(gameTime);
}

The last triangle in positions1 is joined to the first in positions2.

Thanks for any help you can give..

pinckerman
  • 4,115
  • 6
  • 33
  • 42
Laura
  • 41
  • 2

1 Answers1

0

ZOMG! I got it..

It looks like XNA only takes indices as zero-based (even though most co-ordinate systems are one-based), I had something like this:

int[] index1 = new int[] { 1, 2, 3, ..., n };

and changing it to this fixed the problem:

int[] index1 = new int[] { 0, 1, 2, ..., n - 1 };
Laura
  • 41
  • 2