Skip to main content
GameDev.net gamedev.net
🔒 Locked

Getting correct quad(patch) camera is over

Started by steg May 22, 2003 at 6:46 AM 1 replies 250+ views
Original Post
steg
steg
Hi all, If I have a terrain with 128x128 quads, each quad happens to be a width and depth of 96x96 (x,z), to find which patch the camera is over is the following correct : D3DXVECTOR3 CameraPos = GetCameraPos(); int PatchOnX = (int)CameraPos.x / 96; int PatchOnZ = (int)CameraPos.z / 96; Now having these two values, I could index into my heightmap as follows : int Height = HeightMap[(PatchOnX*128)+PatchOnZ]; It seems correct, but the Height I get back seems to vary, maybe this is because each quad has 4 vertices, thus 4 heights ? Kind regards, Steve As I get older, my mind becomes more cluttered. [3d Game development] [edited by - steg on May 22, 2003 7:47:44 AM]
If it isn't working, take a bath, have a think and try again...
VladR
VladR
If I understand you right, you need to get the Y-position of the point you are currently standing on so that you could follow the terrain, right ?

So you have the X and Z coordinate (P.x, P.z) of point P, now:
1. Find out which triangle of the quad are you standing on (compare X,Z coords of the quad`s points)
2. Since you have heightmap with regular distances between points, the situation looks like this:

T3
|..
|...
|....
|.....
M1-P--M2
|.......
|........
T1-------T2

T1,T2,T3 - points of the triangle you are standing over
P - your position over terrain inside the triangle
M1,M2 - line that is paraller with line T1,T2
3. You can find the P.y from the line equation of line M1M2
4. You calculate M1 from line equation of line T1T3, where M1.x = T1.x, M1.z = P.z
5. You calculate M2 from line equation of line T2T3, where M2.z = P.z , M2.x - calc.it from 2D line equation T2T3, the same with M2.y but now from 3d line equation
6. Just calculate P.y from line equation M1M2, knowing P.x and P.z

Where I mention "line equation" I mean simple interpolation with deltaX, deltaY, deltaZ.

It is not the only way, nor the fastest, but i think it is most obvious and simple.

VladR
Avenger game


[edited by - VladR on May 23, 2003 3:02:32 AM]
steg
steg
Thanks for your help VladR,

Kind regards,
Steve
If it isn't working, take a bath, have a think and try again...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.