#### Archived

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

# Walking on a terrain

This topic is 6196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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
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;}

##### Share on other sites
You should be able to interpolate the height of the floor under the player from the heights of the nodes making up the triangle the player is on.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 41
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631741
• Total Posts
3001976
×