Announcement

Collapse
No announcement yet.

3D Topography

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 3D Topography

    I have a very low resolution "map" of a surface- 5 x 50 points or so. I want to display this as a tilted 3D topography map but I'm a bit confused as to the best method. Is it best dealt with as an image or a graph? I can write some simple display code, but don't want to reinvent the wheel, nor do I know how to do surfaces and lighting. Not sure how to make such a low res thing look good- if I had more points it would actually be easier. I don't want to buy an expensive package for this one time thing. Can anybody point me to some suitable PBWin code or give me an example of what I need to write? Thx!

  • #2
    I would recommend to study a bit samples on José Roca's forum.
    For this task you can use:

    OpenGL

    Direct3D

    I personally prefer OpenGL, it is quite easy to jump in, and it still provides interface for everything you need to get from 3D card.
    On José's web you can find "raw SDK" OpenGL samples as well as some using higher level libraries. All with tutorials going from single triangle render to more complex topics - so lot of code for study.

    You can render the terrain using immediate mode ( glBegin / glVertex3f / glEnd ) first and then you can start to optimize using vertex arrays/vertex buffers/display lists once you get the idea.


    Petr
    [email protected]

    Comment


    • #3
      Petr- Thanks, looked at the first Opengl demo and it's exactly what I need to do. Hopefully my pea sized brain can figure this out in a reasonable time. I know 12 year old game programmers can do this blindfolded, but there's never a 12 year old around when you need one.

      Comment


      • #4


        Try to use some of the most basic José's OpenGL skeletons, and for rendering use following:
        Code:
        sub Array2Surface( byref Arr() as single )
          register i as long, j as long
          local s1, s2 as long
          local mini, maxi, delta as single
          s1 = ubound(Arr,1)
          s2 = ubound(Arr,2)
        
          mini = 1000000000
          maxi =-1000000000
          
          ' -- Get min max values, useful for colors
          for i = 1 to s1
            for j = 1 to s2
              mini = min(mini, MyArray(i,j))
              maxi = max(maxi, MyArray(i,j))
            next
          next    
          
          delta = maxi - mini
          
          glPushMatrix
            ' -- Center the final mesh
            glTranslatef -s1/2,0,-s2/2    
            
            ' -- Green color
            glColor3ub 0, 255, 0
            
            ' -- Mesh building - via the most dummy way, but works :)
            glBegin %GL_TRIANGLES
              for i = 1 to s1-1
                         
                for j = 1 to s2-1
                  
                  glColor3ub 0, (MyArray(i,j)-mini) / delta * 255, 0
                  glVertex3f i, MyArray(i,j),j
                  
                  glColor3ub 0, (MyArray(i+1,j)-mini) / delta * 255, 0          
                  glVertex3f i+1, MyArray(i+1,j),j        
                  
                  glColor3ub 0, (MyArray(i+1,j+1)-mini) / delta * 255, 0          
                  glVertex3f i+1, MyArray(i+1,j+1),j+1          
                           
                  glColor3ub 0, (MyArray(i,j+1)-mini) / delta * 255, 0
                  glVertex3f i, MyArray(i,j+1),j+1        
                            
                  glColor3ub 0, (MyArray(i,j)-mini) / delta * 255, 0
                  glVertex3f i, MyArray(i,j),j
                            
                  glColor3ub 0, (MyArray(i+1,j+1)-mini) / delta * 255, 0          
                  glVertex3f i+1, MyArray(i+1,j+1),j+1        
        
                next  
              next             
              
            glEnd        
          glPopMatrix
          
        end sub
        So if you have 5x50 array, you could try something like:
        Code:
        glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
        glLoadIdentity   
        
        gluLookAt ( 50, 50, 50, 0, 0, 0, 0, 1, 0 )
        
        Array2Surface(MyArray())
        
        wglSwapBuffers(hDc)
        ( MyArray should be 2D array )

        It should render the terrain with lowest points in black and higher the vertex is, more green it gains.


        Bye,
        Petr
        [email protected]

        Comment


        • #5
          Hi Petr,
          That's much easier- thanks! I'll be working on this over the next couple weeks.

          CH

          Comment


          • #6
            Before you go to Open GL, you will need to regrid your data to higher density using interpolation software. 5X50 is very coarse topo data. Inverse distance would work fine enough... and of course there are more sophisticated interpolation schemes such as Krigging, minimum curvature...etc...

            Comment

            Working...
            X