Advertisement

Getting the y value on a terrain

Started by June 16, 2002 01:44 AM
1 comment, last by Nazrix 22 years, 8 months ago
In our terrain we have a 2D array of height values. What I am trying to do is figure out what the camera's y would be given it's x & z. here's a screenshot btw just to show what it looks like. The terrain is 3D but is sort of arranged in tiles where it takes each coordinate in the array and adds 10 so that each tile is basically 10 units wide and 10 units long. I got far enough to know what tile you are on like this: int tile_x = (int) (camera->loc.x/land->TILE_SIZE); int tile_z = (int) (camera->loc.z/land->TILE_SIZE); and I figured out how far into a tile you are like this: int offset_x=(int) (camera->loc.x) % land->TILE_SIZE; int offset_z=(int) (camera->loc.z) % land->TILE_SIZE; So I am trying to find out based on knowing the (x,y,z) of the endpoints and the offsets that tell how far into a tile you have gone what the camera's y should be. any help is appreciated
A CRPG in development... Need help? Well, go FAQ yourself. "I'm gay, please convert me." - Nes8bit [edited by - Nazrix on June 16, 2002 2:45:34 AM]
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
OK, in 2 dimetions (finding y from x), it isn''t hard, just linear interpolate between the two.

In 3D, it is harder. I think it would work by interpolating the two lines (on the tiles) that are parallell to the x axis. That would give you two more ponts forming a line, and you could interpolate between them to get your final value. This should probably work, although, triangulation might screw around with this a fair bit?



Do not meddle in the affairs of moderators, for they are subtle and quick to anger.


ANDREW RUSSELL STUDIOS
Cool Links :: [ GD | TG | MS | NeHe | PA | SA | M&S | TA ]
Got Clue? :: [ Start Here! | Google | MSDN | GameDev.net Refrence | OGL v D3D | File Formats | Go FAQ yourself ]

Advertisement
Well, in my Terrainengine, i solved the problem by having a large array for the heights, and by taking values from 4 points around the player and take a midvalue of them as the actual height.


I guess if you would have the exact height, extract the heightdiference in the x and the z axis, and then multiply those values by the percentage the player has moved along the tile and att the refrence height and you should have the height.

Like this (Pascal) and a tilesize of 32x32, X,Y is the heightmapposition, and Xoff, Yoff is the distance traveled in the tile from 0-31

function GetHeight(X,Y, Xoff, Yoff: Integer);
begin
DX:= Heightmap[X+1,Y ]-Heightmap[X,Y]; // get the slope in X
DY:= Heightmap[X ,Y+1]-Heightmap[X,Y];// get the slope in Y

Result:=Heightmap[X,Y]+ // default height
Round((Xoff / 32)* DX) + // add the change in x
Round((Yoff / 32)* DY); // add the change in y
end;

I havent tried this function myself but it should be working,

/Andreas

This topic is closed to new replies.

Advertisement