Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualfastcall22

Posted 07 December 2012 - 04:49 PM

EDIT:
I'm thinking of software rendering...

#1fastcall22

Posted 07 December 2012 - 04:47 PM

I would like to achieve is just the wireframe view of such a landscape

I had done something like this when I first started programming, and I learned the foundations of transformation matrices though it. So, I'll explain as how I learned it when I first attempted something like this.

Since this is rendered in 3D, you will need to work in 3D space:
type Point3:
    float x, y, z

You'll also need some sort of structure to model the terrain; an array of Point3 can work:
type Heightmap(N):
    Point3[,] points = new Point3[N,N]

Since the points on the grid are regularly spaced on the X and Z axis, you can infer the X and Z coordinate of the point by its row and column index:
type Heightmap(N):
    float[,] points = new float[N,N]
[/doe]

Next, when rendering the heightmap, you'll need to transform each vertex on the terrain to give it a pseudo-3D look.  As you can tell by the image, moving into the screen (+Z) shifts both the X-coordinate and Y-coordinate, and moving upwards shifts the Y-coordinate.  The transform might look something like this:
[code]
function transform(x y z):
    x' = x
    y' = y + .5z
    return (x' y')
[/code]

If you want to get really fancy, you can specify a unit such that 1 unit on the terrain is some number of pixels on the screen, center (0,0) in your world to be the center of the screen, and set the Y axis to point upward:
[code]
function transform(x y z):
    x' = x*16 + w/2
    y' = -(y + .5z)*16 + h/2
    return (x' y')
[/code]

Next, you'll need to draw the lines connecting each vertex to each neighbor (for vertices that have neighbors):
[code]
each row in 0..N-2
    each col in 0..N-2
        v = (transform col row terrain[row,col])
        n1 = (transform col row terrain[row,col+1])
        n2 = (transform col row terrain[row+1,col])
        line v n1
        line v n2 


PARTNERS