PDA

View Full Version : Determing Cell I'm in



06-19-2001, 04:03 PM
I have written a small program in which I can walk through a landscape made up of triangles. What I would like to know is how to determine what triangle I am standing in. Your help is much appreciated, thank you very much.

DFrey
06-19-2001, 05:12 PM
Are the triangle vertices in a regular grid as viewed from above? Or are the vertices irregularly placed?

06-20-2001, 09:07 AM
They are in a grid as viewed from above

harsman
06-21-2001, 02:29 AM
Think of the data as a 2d array where each cell contains a pair of triangles. To understand what pair of triangles you're on, determine what row of triangles you're in, what column of triangles you're in and, voila you'll know what pair of triangles you're standing on. Say that origo is at the bottom left of the terrain for example, then the column you're in is :

columnIndex=position.sideways/columnWidth

and the row is:

rowIndex=position.vertically/rowWidth

Now you know which pair of triangles you're on, so just test against collisions with those.