1

I have a project with a floor built from with small cubes (100x100 of them). If I exceed that size, the performance of my game suffers. How can I efficiently draw a larger number of identical models?

Here's how I'm currently drawing the ground:

    //Function to draw my ground ( 100 X 100 X 1)
    public void DrawGround(GameTime gameTime)
    {
        // Copy any parent transforms.
        Matrix[] transforms = new Matrix[this.model.Bones.Count];
        this.model.CopyAbsoluteBoneTransformsTo(transforms);

        //loop 1 cube high
        for (int a = 0; a < 1; a++)
        {
            //loop 100 along cube
            for (int b = 0; b < 100; b++)
            {
                //loop 100 cubic wide
                for (int c = 0; c < 100; c++)
                {
                    // Draw the model. A model can have multiple meshes, so loop.
                    foreach (ModelMesh mesh in this.model.Meshes)
                    {
                        // This is where the mesh orientation is set, as well 
                        // as our camera and projection.
                        foreach (BasicEffect effect in mesh.Effects)
                        {
                            effect.EnableDefaultLighting();
                            effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(this.position);
                            effect.View = this.view;
                            effect.Projection = this.projection;


                        }

                        // Draw the mesh, using the effects set above.
                        mesh.Draw();
                    }
                }
            }
        }
    }

I think it is better to use the a vertex buffer, but I have not found a tutorial for that I want to do. Can you explain how I can do this?

Mehdi Bugnard
  • 532
  • 5
  • 24
  • As a suggestion, try loading/storing your map in chunks of 20-10 square. This will mean as the user moves around you load and unload areas and also only required to render (and store in memory) the structure of the chunk once. – AbstractChaos Jan 21 '13 at 13:43
  • Yes thank you, but I would like the user can view a minimum 100X100 cubes around him. I think I have something here -> -> http://www.float4x4.net/index.php/2011/07/hardware-instancing-for-pc-in-xna-4-with-textures/ – Mehdi Bugnard Jan 21 '13 at 15:35
  • Do you need to use cubes? or are you doing a minecraft style game? – Luis Estrada Jan 21 '13 at 16:05
  • Yes exactly! I wanted to keep the same idea as "Minecraft". Is it okay to make Like this ? – Mehdi Bugnard Jan 21 '13 at 16:11

0 Answers0