DrawUserIndexedPrimitives for individual grids

This is a question about noob, but I searched extensively and cannot find the answer.

I have two separate cells that need to be drawn in one window using DrawUserIndexedPrimitives. I use two instances of BasicEffect with their own views and projection matrices.

However, when they are rendered, one line is joined. XNA believes that they are part of the same grid. Do I need to use a separate instance of GraphicsDeviceManager for each of them? This 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 at positions 1 connects to the first at positions 2.

Thanks for any help you can give.

+4
source share
1 answer

ZOMG! I understood.

It seems that XNA only uses indexes as zero-based indexes (although most coordinate systems are unidirectional), I had something like this:

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

and changing it to this, the problem is fixed:

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

Source: https://habr.com/ru/post/1445410/


All Articles