Menu

Infinite terrain method (from tut3)

Help
srekel
2005-03-22
2013-04-30
  • srekel

    srekel - 2005-03-22

    I'm trying to make an "infinite" terrain by generating two terrains at (0,0)->(1,1) and (0,1)->(1,2), but for some reason it won't quite work.

    They line up pretty good, but not exactly, it's like the first ends at z = 0.99 and the second starts at 1.0 (or the first at 1.0 and the second at 1.1, it doesn't matter, I just hope you understand what I mean).

    What can I do to fix this?

     
    • srekel

      srekel - 2005-03-24

      I now understand exactly what the problem is. Basically, it's this part:
      void NoiseMapBuilderPlane::Build ()
        //...code omitted...
        // Fill every point in the noise map with the output values from the model.
        for (int z = 0; z < m_destHeight; z++) {
          float* pDest = m_pDestNoiseMap->GetSlabPtr (z);
          xCur = m_lowerXBound;
          for (int x = 0; x < m_destWidth; x++) {

      It should be "z <= m_destHeight" and likewise for x. As it is now, the heightmap will be one row too small. I.e., if I do this:
      mHeightMapBuilder.SetDestSize (4, 4);
      mHeightMapBuilder.SetBounds (0, 4, 0, 4);
      Then I'll get values at 0, 1, 2, 3 but not at four. This is of course a design choice you can have, but in my opinion it is a lot nicer to be able to do this:
      mHeightMapBuilder.SetBounds (0, 4, 0, 4);
      // ....
      mHeightMapBuilder.SetBounds (0, 4, 4, 8);
      instead of
      mHeightMapBuilder.SetBounds (0, 4, 0, 4);
      // ....
      mHeightMapBuilder.SetBounds (0, 4, 3, 7);

      Of course, this is just in the utils part so it isn't something that is necessary for libnoise. I just thought I should mention it, I guess I'm not the first one to have this problem. Indeed, I actually opened your image of the two heightmaps that are next to eachother in Paint Shop Pro, and moved them next to eachother (without the two pixels inbetween). They didn't match. ;)

       
    • Jason Bevins

      Jason Bevins - 2005-03-30

      Hi srekel,

      As Microsoft is so fond of saying, "this behaviour is by design" :-)

      The code you have written:

      > mHeightMapBuilder.SetDestSize (4, 4);
      > mHeightMapBuilder.SetBounds (0, 4, 0, 4);
      > mHeightMapBuilder.SetBounds (0, 4, 4, 8);

      is correct and should produce two height maps that mesh together.

      Note that this does not mean that the rightmost column contains the same values as the leftmost column of the adjacent height map.  The reason it is written this way is as follows: (I hope this makes some sense)

      Suppose you had the code:
      mHeightMapBuilder.SetDestSize (4, 4);
      mHeightMapBuilder.SetBounds (0, 1, 0, 1);
      mHeightMapBuilder.SetBounds (0, 1, 1, 2);

      This produces two 4x4 height maps.  Each point in the height map represents 0.25 units in 'noise space'.  So the top row of the first height map will contain the noise values from the following coordinates:

      0.00  0.25  0.50  0.75

      The top row of the second height map will contain the noise values from the following coordinates:

      1.00 1.25 1.50 1.75

      Note that if you join these height maps together:

      0.00  0.25  0.50  0.75 | 1.00 1.25 1.50 1.75

      the difference between adjacent noise coordinates remains 0.25.  They will seamlessly join.

      Also the code you posted (x <= m_destWidth) and (z <= m_destHeight) is incorrect.  This would cause the loop to iterate (width + 1) and (height + 1) times.

      I hope this helps.  Post in this forum if you got questions.  I'd also like to see the images you've generated if possible.

      -- jas

       
    • srekel

      srekel - 2005-03-30

      Ah. I see how you intended now, and it makes sense. :) It shouldn't be THAT hard to change my code to what it "should" be like - and it will probably make for nicer architecture as well.

      I just took some screenshots (for your pleasure alone ;)), you can find them here:

      http://www.srekel.net/pmwiki/pmwiki.php?n=Projects.InfiniteWorld

       
      • Jason Bevins

        Jason Bevins - 2005-04-07

        Very cool!  It looks like it could easily be made into a game like the old Intellivision game Astrosmash.  Do you generate the terrain in real-time?

        Did you want a height map to have the same values in the rightmost (and topmost) row as the values in the leftmost (and bottommost) row in the adjacent height map?  If so, you can modify lines 840 and 841 in noiseutils.cpp as follows:

        Remove:
          double xDelta  = xExtent / (double)m_destWidth;
          double zDelta  = zExtent / (double)m_destHeight;

        Add:
          double xDelta  = xExtent / (double)(m_destWidth + 1);
          double zDelta  = zExtent / (double)(m_destHeight + 1);

        -- jas

         
        • Jason Bevins

          Jason Bevins - 2005-04-11

          Oh crap...

          double xDelta = xExtent / (double)(m_destWidth - 1);
          double zDelta = zExtent / (double)(m_destHeight - 1);

          (note the minuses.)

          -- jas

           

Log in to post a comment.