Jump to content
  • Advertisement
Sign in to follow this  
football94

uneven 3D tile map

This topic is 1035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys

Ive been researching riemers xna flightsim game(link below) and did some collision detection experiments using the terrain , but after modifying the numbers in the array I came across the problem of an uneven surface, for example for all the zero values the avatar stays even with the terrain, but when I changed the values to one, the avatar began to move up, and higher still with the two values, so I was hoping if anyone had any advice or suggestions on how the problem could be fixed, it would be much appreciated.

 

                             Thank you smile.png

 

 

 

 

link to riemers flightsim

http://www.riemers.net/eng/Tutorials/XNA/Csharp/series2.php

 

The array

  public void LoadFloorPlan()
        {
            floorPlan = new int[,]
             {
                 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},  
                 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 
                
             };


          
        }


 public void SetUpVertices()
        {
            cityWidth = floorPlan.GetLength(0) ;
            cityLength = floorPlan.GetLength(1) ;


           


            List<VertexPositionNormalTexture> verticesList = new List<VertexPositionNormalTexture>();
            for ( x = 0; x < cityWidth; x++)
            {
                for ( z = 0; z < cityLength; z++)
                {
                    int imagesInTexture = 11;
                    int imagesInTexture1 = 1;
                    int imagesInTexture2 = 5;
                    if (floorPlan[x, z] == 0)
                    {


                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z), new Vector3(0, 1, 0), new Vector2(0, 1)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(0, 0)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 1)));

                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(0, 0)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 2)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 1)));

                    }
                    
                        if (floorPlan[x, z] == 1)
                        {

                          
                           
                            verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z), new Vector3(0, 1, 0), new Vector2(0, 1)));
                            verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(0, 0)));
                            verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 1)));

                            verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(0, 0)));
                            verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z - 1), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 0)));
                            verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z), new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture, 1)));

                        }

                        if (floorPlan[x, z] == 2)
                    {


                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z) , new Vector3(0, 1, 0), new Vector2(0, 1)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1) , new Vector3(0, 1, 0), new Vector2(0, 0)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z) , new Vector3(0, 1, 0), new Vector2(1.0f / imagesInTexture2, 1)));

                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x, 0, -z - 1) , new Vector3(0, 1, 0) , new Vector2(0, 0)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z - 1) , new Vector3(0, 1, 0) , new Vector2(1.0f / imagesInTexture2, 0)));
                        verticesList.Add(new VertexPositionNormalTexture(new Vector3(x + 1, 0, -z)  , new Vector3(0, 1, 0) , new Vector2(1.0f / imagesInTexture2, 1)));

                    }
                }
            }

            cityVertexBuffer = new VertexBuffer(device, verticesList.Count * VertexPositionNormalTexture.SizeInBytes, BufferUsage.WriteOnly);

            cityVertexBuffer.SetData<VertexPositionNormalTexture>(verticesList.ToArray());
        }

pictures of avatar

 

blue for zero values

red for one values

green for two values

Edited by football94

Share this post


Link to post
Share on other sites
Advertisement
Can't know what is wrong with the code you posted. I would suspect that those number are meant to control terrain height. Have you don't any other changes to the example code apart from changing the floor plan?

Share this post


Link to post
Share on other sites

Thanks for the reply HappyCoder but Ive managed to come up with a solution

which was to just change the int floorplan into a float floorplan which works

perfectly for me since that I now have more options to play around with the number values

 

 

Thankyou

 

new code below

public void LoadFloorPlan()
        {
            floorPlan = new float[,]
             {
                 {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f},  
                 {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f},  
                 {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f},  
                 {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f},  
                 {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f},  
                 {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.1f},  
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                 {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
                {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
               {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
               {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                 {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                 {0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f,0.002f},
                 
                
             };


          
        }

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!