• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Walking on a terrain

## Recommended Posts

Big_Al482    122
I am using a 32x32 grayscale bitmap to generate a landscape by determing height of a certain point on the terrain with the bitmap''s color values (the whiter the pixel on the bitmap, the higher to the terrain will be at that point). But now I want to move around on it. I''m reading OpenGL Game Programming right now (very good book by the way), but I''m having trouble with Astle''s GetHeight() function...I was wondering if this is the traditional way to determine the user''s position on the y axis...can it be done another way? with collision detection maybe? If anyone knows of some other techniques, please respond to this post & if you know where I can read up on them, I''d really like to know thanks everyone

##### Share on other sites
kieren_j    100
Im going to throw his into the thread, dont know if it will help you Works for me

float CTerrain::CalcHeight(float x, float y){	float x1,y1,x2,y2;	float v,v1,v2;	float a;	float b;		// convert to terrain-space coordinates	x = (x + (Width*HALF_MAP_SCALE)) / MAP_SCALE;	y = (y + (Height*HALF_MAP_SCALE)) / MAP_SCALE;	if (x > Width - 1)	x = (float)Width - 1.0f;	if (y > Height - 1)	y = (float)Height - 1.0f;	// get the 4 points	x1 = floorf(x);	y1 = floorf(y);	x2 = x1 + 1;	y2 = y1 + 1;		// calculations	a = x - x1;	b = y - y1;	// more stuff... thanks 2 "malkia"	v1 = HEIGHT_MAP(x1,y1)*(1-a) + HEIGHT_MAP(x2,y1)*a;	v2 = HEIGHT_MAP(x1,y2)*(1-a) + HEIGHT_MAP(x2,y2)*a;	v = v1*(1-b) + v2*b;	return v;}