Results 1 to 2 of 2

Thread: Terrain from a Rectangular 2D mesh

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jul 2003
    Location
    Bangalore, Karnataka, India
    Posts
    123

    Terrain from a Rectangular 2D mesh

    I have the following function for creating a mesh .I want to make this mesh into 3D terrain.What additions should be make in the following code.I want to create Height fields from this rectangular mesh.How to do that.

    void DrawMesh(GLfloat size, GLint Linesx, GLint Linesz)
    {
    glBegin(GL_LINES);
    for (int xc = 0; xc < LinesX; xc++)
    {
    glVertex3f( -size / 2.0 + xc / (GLfloat)(LinesX-1)*size,
    0.0,
    size / 2.0);
    glVertex3f( -size / 2.0 + xc / (GLfloat)(LinesX-1)*size,
    0.0,
    size / -2.0);
    }
    for (int zc = 0; zc < LinesX; zc++)
    {
    glVertex3f( size / 2.0,
    0.0,
    -size / 2.0 + zc / (GLfloat)(LinesZ-1)*size);
    glVertex3f( size / -2.0,
    0.0,
    -size / 2.0 + zc / (GLfloat)(LinesZ-1)*size);
    }
    glEnd();
    }


    Regards

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    625

    Re: Terrain from a Rectangular 2D mesh

    I avoid code dumps from other people like the plague however, some at-first-glance-hints

    1- Use vertex arrays. Compute once and reuse.
    2- "/ 2.0" is evil: "* .5f" is much better.
    3- My terrain renderers does not have constants in them. Do you really need?

    How to turn a mesh in a terrain?
    Depending on how much "elegant", "nice", "fast", "portable" your code is meant to be there may be different apporoaches.

    What you are probably asking is to do a brute-force renderer. In that case, you just have to create WxH vertices for a WxH heightmap. Then, look pixel (w,h) from the image and put its value (after adeguate processing) in vertex (w, h), Y coordinate.
    If you want to just code fast you can do it in less than a week. If you want to have something elegant, it may take longer. If you want it to be fast it will take **much** longer.

Similar Threads

  1. Single mesh versus array of mesh
    By DannySaucen in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-06-2012, 08:44 AM
  2. Tangent Space Vector for my Terrain mesh
    By Mars_999 in forum OpenGL: Advanced Coding
    Replies: 25
    Last Post: 01-23-2006, 09:37 PM
  3. Replies: 2
    Last Post: 05-04-2005, 07:28 PM
  4. Rectangular mesh not rendered
    By iris_raj in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-21-2004, 02:19 AM
  5. terrain mesh
    By iris_raj in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 08-18-2003, 07:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean