Thread: We Have Terrain!

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    We Have Terrain!

    http://img.photobucket.com/albums/v1...no/Terrain.jpg

    Hmm..

    Moving on up theme song anyone?

    Now I gotta learn how to texture map this beast...
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Nice Can't quite say I can do that yet.

  3. #3
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    After all the work you have been putting into this and all the setbacks you have needed to go through, I'm glad to see you have stuck to it and come up with a product however far from a full game it may be .
    Sic vis pacum para bellum. If you want peace, prepare for war.

  4. #4

    Join Date
    May 2005
    Posts
    1,042
    Good job man, keep up the good work.
    I'm not immature, I'm refined in the opposite direction.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Good work Shamino!

    A simple texture map that applies the texture evenly across the terrain is this:

    Code:
    float fUCoef=1.0f/(float)iMapWidth;
    float fVCoef=1.0f/(float)iMapHeight;
    
    int row=0,col=0;
    DWORD dwVertexNum;
    DWORD dwOffset=0;
    
    for (int z=iStartZ;z<iEndZ;z+=iCellSize)
    {
      for (int x=iStartX;x<iEndX;x+=iCellSize)
      {
         float height=(float)pHeightMap[dwOffset]*fScaleFactor;
    
         Vertices[dwVertexNum]=TerrainVertex(x,height,y,(float)col*fUCoef,(float)row*fVCoef);
    
         col++;
         dwOffset++;
         dwVertexNum++;
       }
       col=0;
       row++;
    }

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Lol, I think it's pretty hillarious that I tried to understand what you wrote Bubba last night when I was incredibly trashed..

    It was like a foreign language..


    Looking at it now, I see that it is basically grabbing a quad of vertices from the heightmap, a "cell" and just iterating through each cell. This sets us up nicely to simply apply a texture right after we find the right vertices.. Where would the actual texture application code go in that?

    Right before you increase the col, offset, and the vertex num?

    EDIT: POST 500 WOOT
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well in Direct3D you don't 'bind' textures to anything. You use SetTexture() to change the current texture it's using and every primitive you draw will have that texture applied to it. So the texture code is in the loop. It just sets the u and v texture coordinates and Direct3D uses those to map the texture onto the triangle.

  8. #8
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    And now we have wireframe

    Quality sucks due to jpegage..

    http://img.photobucket.com/albums/v1...rrainLines.jpg
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  9. #9
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Another question, is upscaling a terrain the same as getting a bigger one?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  10. #10
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Shamino
    And now we have wireframe

    Quality sucks due to jpegage..

    http://img.photobucket.com/albums/v1...rrainLines.jpg
    why are there no cross-sections in the wireframe?

  11. #11
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Shamino
    Another question, is upscaling a terrain the same as getting a bigger one?
    No, because each poly just gets bigger with scaling, if you get a bigger terrain, you can scale it the same way but have more polys per unit area (higher res).

  12. #12
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    Quote Originally Posted by Perspective
    why are there no cross-sections in the wireframe?
    I think he renders the terrain as I do; with glBegin(GL_QUADS); but for Direct 3D . I guess that it is a bit faster to do like that since it will become less calls to the API, but this is just what I guess prove me wrong

    And that is a cool terrain, what kind of lighting do you use? Nice work.

    Daniel

    EDIT: Here is a screen of my terrain http://e43.sag.karlstad.se/it18/screenShot.jpg
    Last edited by The Wazaa; 03-15-2006 at 10:29 AM.

  13. #13
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    > but this is just what I guess prove me wrong

    ok.

    If you render with individual quads or triangles you repeat many many vertices. The same vertex will be sent through the graphics pipeline 4 times (on average, for a uniform grid based terrain). It is much faster to use trianlge strips or trianlge fans which link triangles together.

    btw: your quads are split into two triangles in the pipeline anyway.

  14. #14
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    For Direct3D you cannot render quads by themselves. Everything is in triangles since any 3 points in space are guaranteed to be colinear or lie in the same plane and thus create a plane.

    A triangle is easy to texture as well but I won't go into the math right here.

    Do what Perspective said. Use triangle strips. Each row of the terrain should be a strip. Depending on your space partitioning algo your setup may differ significantly from just using a regular grid. However I've found that regular grids do lend themselves to a lot of usefulness.

    www.vterrain.org - Everything you ever wanted to know about terrain and more.

    Still working on my implementation. However I'm more focused on another project at the moment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Continous LOD Terrain Source... Released!
    By Perspective in forum Game Programming
    Replies: 13
    Last Post: 04-17-2006, 11:21 PM
  2. New terrain engine
    By VirtualAce in forum Game Programming
    Replies: 16
    Last Post: 03-16-2006, 02:47 AM
  3. Drawing only what you can see (terrain)
    By Eber Kain in forum Game Programming
    Replies: 8
    Last Post: 07-05-2004, 12:19 AM
  4. Terrain algos
    By VirtualAce in forum Game Programming
    Replies: 1
    Last Post: 04-10-2004, 02:50 PM
  5. OpenGL terrain demo (EDITOR)
    By Jeremy G in forum Game Programming
    Replies: 2
    Last Post: 03-30-2003, 08:11 PM