PDA

View Full Version : how to follow the terrain height

12-13-2000, 07:13 PM
hi everyone,

i would be appreciate if anyone could help me out, on how to follow the terrain height?

i have a .wrl file, and have converted it in 3DExploration to get the coordinates, and it works. so now i have the terrain verticies, normals, face_indicies and texture coordinates.

my problem is:

how to get/detect the current viewer coordinates(position), so when up arrow key is being pressed, the 'viewer' will follow the terrain height?

dans
12-13-2000, 10:48 PM
Solve the plane equation for the point that you're standing on.

The plane equation is (x)nx + (y)ny + (z)nz + c = 0.

{nx, ny, nz} is the plane normal of the current cell.

c is a constant offset which can be solved by plugging in
the coordinates of one of the corner points of the cell.

Your current position on the map is {x,z} solve for y.

In pseudocode:

// Get my current position on the map
pos = {something};

// Figure out the current cell I'm standing in
cell = FindCell(pos);

// Get the plane normal of the cell or triangle
normal = cell.normal;

// Get one of the corner points of the cell
point = cell.point(1);

// Solve for c, the plane equation offset
c = normal.x * point.x + normal.y * point.y + normal.z * point.z;

// Now solve for the y component of my position
pos.y = (c - normal.x * pos.x - normal.z * pos.z) / normal.y;