Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 this post

Link to post
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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!