Welcome! Log In Create A New Profile


[RESOLVED] Generating Random Terrain using GX

Posted by owen 
[RESOLVED] Generating Random Terrain using GX
January 09, 2011 12:55AM
I'm writing a flying GAME which is on rails and I want to use GX_TRIANGLESTRIP (or anything) to draw a simple landscape that I can fly over. I'm having a hard time getting the triangles to line up correctly. Anybody tried generating random terrain like this? is there a easier way? (without loading a model )

Edited 2 time(s). Last edit at 01/24/2011 06:43PM by owen.
Re: Generating Random Terrain using GX
January 09, 2011 11:58AM
I always try everything in OpenGL first before I convert it to GX (manually)

You basicly want to generate a heightmap and draw from that, it's not that hard:
[www.gameprogrammer.com] some simple terain generation.

And then draw 1 triangle strip for each column.
Re: Generating Random Terrain using GX
January 09, 2011 08:52PM
Yeah I saw that page but I was having a hard time figuring out what the diamond cube was doing and then converting that to GX. I wanted to see if anybody has attempted it in GX. I guess I will have to write my own simple formula.
Re: Generating Random Terrain using GX
January 14, 2011 03:05PM
Well I did something, its not quite the diamond square technique but its passable for sand dunes or high flyovers. I may try to do some colision detection on it but it looks doubtful cause it may slow my framerate down to nothing.
Video (I really need to try doing screenshots): [www.youtube.com]
Re: Generating Random Terrain using GX
January 24, 2011 06:30PM
Here is the final, buggy, unopimised C code that I hacked together. All it does is draw several triangle strips to form a nearly flat surface with random bumps. It will not work in every scenario so use at your own risk. NO COLLISION DETENTION - just in case it isn't obvious. generates something like this [www.youtube.com] (except not scrolling/moving )

	int terrain_color_threshold=100; //how bright or how dark to fade the terrain as it gets higher/lower
	int terrain_grid=100; //100 //this number squared must be smaller than terrain_max
	int terrain_height=170;//the scale of the terrain box
	float terrain_max=10000, terrain[10000][4]={};  //4th is the direction of the point (for water effect)

void draw_terrain3( u32 col ) {
	int i, g;

	GRRLIB_ObjectView( 0, -200,-1500, 0,0,0,500,100,500);	//uses grrlib

	int grid=terrain_grid, p=0, p2=0;
	int grid_cols=grid*grid;
	float x=-1, y=-1, z=-1, grid_inc=2/(float)grid;
	for(g=0; g 0) & (g > 0) ) {
					terrain[p][0]=terrain[p2][0]; terrain[p][1]=terrain[p2][1]; terrain[p][2]=terrain[p2][2];
				} else {
					terrain[p][0]=x; terrain[p][1]=y; terrain[p][2]=z;				

		switch( randnum2(3) ){
			case 1: col=GRRLIB_GRAY; break;
			case 2: col=GRRLIB_SILVER; break;			
			case 3: default: col=GRRLIB_GREEN; 
Sorry, only registered users may post in this forum.

Click here to login