DirectX Terrain Generation
Since a new post has been way overdue I’ve decided to post the first relatively interesting thing I could come up with. At the moment I’m learning a great deal regarding 3D rendering as well as some of the complex mathematics involved, such as four-dimensional matrix operations and quaternions, both of which are obviously very common in 3D development. Up until now, I’ve had the luxury of relying on game engines to do most of the complex work for me so this is quite new to me, and mind you, it won’t be particularly graphically interesting but it’s worth a try.
The strange white blob on the screen is just a rotating teacup mesh. So right now, this week I’ve been working on a little terrain project that would randomly generate terrain, differently each time the program is run. The concept is very easy, as I’m simply creating a grid of vertices of any size I specify; right now this is 160×160 with a 0.4 unit distance between each vertex. I then generate random numbers which are responsible for both the height and colour of each vertex (a heightmap, yay!). I then run a series of smoothing passes that, right now very simply average the four neighbouring vertices and combine that value into each center vertex. Unfortunately this means that all bordering vertices are out of the question and I simply set their height to zero.
The last thing which took me suprisingly long is connecting it all up with indexes (indices). After struggling with a simple combination of for loops and guessing I finally got the result I wanted, yay!
It ain’t no Crysis but it’s a start.