Current Location on Terrain

This topic is 4893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Guy's I have been reading and reading through articles and I just can not figure out what I need todo to be able to tell teh current location on my terrain that im at. Now Im basically just trying to be able to get the current height value of the terrain so I can render my model ontop of hte terrain and when the model is translated (moved) around the terrain it is always above the terrain and not floating though it of course. I know the number of Traingles, Vert's, Indices, and I have normals setup as well. is there a way to tell from when I render my normals (considering that when you render normals you create an array to hold vect's positions of them) .. im confused haha someone please help if anyone has any tutorials with some code snip's please pass them my way thanks.

Share on other sites
hehe, funny, this is the exact problem that I've been sorting in my head while at work today ;)

Don't have any code for you, but I can give you some pointers as to what I've figured out.

1) Figure out which 'block' of vertices encase your point
2) Use linear interpolation between those points, and average those values to find the height at the given point

Sorry I can't be more specific, maybe I can give you more after I get home and actually type up my ideas ;)

Share on other sites
you need help to find the correct Y position at your landscape?

you need a very simple tutorial?

so here we go :)

y00........y01
....------
....|.../|
....|../.|
....|./..|
....------
y61........y62

// Object position / size of quad ( y00<->y01 and y00<->y61 is block_size )

float xx=object_x / block_size;
float zz=object_z / block_size;

// we need integer value for block position
int ex = floor( xx );
int ez = floor( zz );

// get the height coordinates from your landscape, very simple
float y00=land[ex ][ez ];
float y01=land[ex+1 ][ez ];
float y61=land[ex ][ez+1 ];
float y62=land[ex+1 ][ez+1 ];

//here we got the position x/z inside the target block (the two triangles)
float fex=xx-ex;
float fez=zz-ez;

//and here we find the trinangle you are in
//if fex+fez < 1 we are in first triangle , else we are in second
//and calculate the height y position in correct triangle

if (fex+fez < 1.000001){ ee=-(y00+(((y01-y00)*fex)+((y61-y00)*fez)));}
if (fex+fez > 1.000000){ fex=1.0-fex;fez=1.0-fez;ee=-(y62+(((y61-y62)*fex)+((y01-y62)*fez)));}

return ee;
}

at end here the float ee is holding the Height value
at THIS point in your landscape, so you can place
your chars and objects with it

greetings from germany

[Edited by - Aragon on August 25, 2005 3:01:57 PM]

Share on other sites
thanks man im def. going to give this a try and hey im german too .. greetings from the USA :[] thanks again

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• Forum Statistics

• Total Topics
634059
• Total Posts
3015292
×