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!
Announcement
Collapse
No announcement yet.
3D Topography
Collapse
X
-
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
-
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
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)
It should render the terrain with lowest points in black and higher the vertex is, more green it gains.
Bye,
Petr
Comment
Comment