Jump to content
  • Advertisement
Sign in to follow this  
Andy474

[XNA] HeightMap Problems

This topic is 3035 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

Hey quick question: I Am loading a height map into my game from a texture file. here is my Method
 private void LoadHeightMap(Texture2D HeightMap)
        {
            int width = HeightMap.Width;
            int height = HeightMap.Height;
            float[,] heightData = new float[height, width];

            Color[] heightMapColors = new Color[width * height];
            HeightMap.GetData(heightMapColors);
            for (int y = height - 1; y > 0; y--)
                for (int x = width - 1; x > 0; x--)
                    heightData[y, x] = 
                        MathHelper.Clamp(heightMapColors[x + y * width].R / f_MapDivScale,
                        0, i_MaxLandscapeHeight);

            hm_HeightMap =  new HeightMap(width, height, heightData);
        }



And I set the Vertices using the Following Method
 d_VertexList = new Dictionary<Vector2, TextureIndexVertex>();
            for (int x = 0; x < hm_HeightMap.Width; x++)
            {
                for (int y = 0; y < hm_HeightMap.Height; y++)
                {
                    TextureIndexVertex thisVertex = new TextureIndexVertex();
                    thisVertex.TextureCoordinate.X = (float)x / 30.0f;
                    thisVertex.TextureCoordinate.Y = (float)y / 30.0f;
                    thisVertex.Position = new Vector3(x, hm_HeightMap.HeightData[y, x], y);

                    d_VertexList.Add(new Vector2(x,y), thisVertex);
                }
            }



And I set the Indices using the Following Method
 l_IndiciesList = new List<int>();
            for (int y = 0; y < hm_HeightMap.Height - 1; y++)
            {
                for (int x = 0; x < hm_HeightMap.Width - 1; x++)
                {
                    int lowerLeft = x + y * hm_HeightMap.Width;
                    int lowerRight = (x + 1) + y * hm_HeightMap.Width;
                    int topLeft = x + (y + 1) * hm_HeightMap.Width;
                    int topRight = (x + 1) + (y + 1) * hm_HeightMap.Width;

                    l_IndiciesList.Add(topLeft);
                    l_IndiciesList.Add(lowerRight);
                    l_IndiciesList.Add(lowerLeft);

                    l_IndiciesList.Add(topLeft);
                    l_IndiciesList.Add(topRight);
                    l_IndiciesList.Add(lowerRight);
                }
            }



Now when I load a height map which is square (300x300, 500x500, 1000x1000) etc, I get a perfect result (or what seems to be at least). However, when I try to load a map which is a rectangle (444x567) I Get Distorted Lines all over the place E.g. Problem Pic at most, I can only figure that there must be something going wrong with the indices so any advice is appreciated Regards ~Andy^ [Edited by - Andy474 on April 1, 2010 3:20:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
I think the heightmap must be square (512x512, 1024x1024, etc)
(Or not.. but the picture's link is dead, so i dont know what you see in your screen :] )

Share this post


Link to post
Share on other sites
Sorry :) link is now Fixed. Surely you must be able to use Rectangular textures like 1000x500 its just a matter of how you load them in?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!