height on a heighmap at position x,z ?

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

Recommended Posts

Hi, I can't find on google what I need, maybe because I don't know how to describe it to google :( I have a triangle x1,y1,z1 x2,y2,z2 z3,y3,z3 I know that I am on top of the triangle and I know where I am, at Pos PX,PZ. How do I get the right Y position? Please help, all I can find is using planes or vectors.

Share on other sites
What do you mean by "I know that I am on top of the triangle"? Are you trying to determine the normal vector or something? I'm afraid I don't understand your question.

Share on other sites
Are you looking for avarege Y value?
YAvg = (y1+y2+y3)/3.0
Or do you need the maximum Y value?
make a small function that returns the max value from 3 given float values.

there is another way though.
on any given x,z value on the raw data from the heightmap (grayscale values), you can translate the gray value of the x,z spot to a height value.

Hope that help.

Share on other sites
When I look with google, the most formulas starts with: make a plane out of your coordinates, test if your position is on the triangle...... But they all continue creating Planes out of Vectors and other things that I don't know about.

I just want to make really sure, that I already know on which of the 500.000 Triangles I am
And I only need a formula to get one y coordinate.

Maybe its still not clear what I want.
I have a landscape made out of a 1000x1000 array of height-Information.
given, that I know I am on the quad on [432][500], and given that I know I am on the left triangle, and I know that the triangle coords are
for example 10,10,10 20,30,20 15 20,30
I want to know the height When my object ist at x=12,z=12
then I move forward and I am on pos x=12,Z=13.....
i need to know the y-position , and I don't think it is the average y-value of the three points of that triangle.

Share on other sites
Quote:
 Original post by cybergolemHi,I can't find on google what I need, maybe because I don't know how to describe it to google :(I have a triangle x1,y1,z1 x2,y2,z2 z3,y3,z3I know that I am on top of the triangle and I know where I am, at Pos PX,PZ.How do I get the right Y position?Please help, all I can find is using planes or vectors.

Solution: compute the triangle-plane and resolve by y

If you like formulas [smile]

Triangle : A, B, CPlane    : N*P + d = 0    where  N = (B-A)^(C-A)  (cross product )           d = -N * A       (dot product)If we expand the implicit equation of the plane we haveNx * x + Ny * y + Nz * z + d = 0hencey = -(Nx*x + Nz*z + d)/Ny  note that in height maps Ny is always != 0

Share on other sites
Quote:
 Original post by cybergolemHi,I can't find on google what I need, maybe because I don't know how to describe it to google :(I have a triangle x1,y1,z1 x2,y2,z2 z3,y3,z3I know that I am on top of the triangle and I know where I am, at Pos PX,PZ.How do I get the right Y position?Please help, all I can find is using planes or vectors.

Try Googling Line Intercept Triangle or Line Intercept Plane to find an algorithm and probably source code. I did this a couple of years ago and found enough to solve it. If you have a regular height map (fixed equally spaced grid coordinates) it can be simplified alot.

Share on other sites
calculate where the ray with origin below the surface and direction (0,1,0) that is the ray defined by the equation

p = (PX, Y, PZ) + t*(0,1,0)

where Y is a BELOW the terrian -1000000000000 would certianlly do the trick ;)

and find the intersection of this ray(paramaterized line) with the plane defined by the triangle

the equation of a plane is

N DOT (O - P) = 0

where N is the normal of the plane, O is any point on the plane. A plane is all points P that satisify this equation.

so with a triangle of Vertices V1, V2, V3 the plane would be

N = (V2 - V1) cross (V3 - V1)
O = V1

now we substitute the equation of a ray into this equation and solve for t. hopefully you can finish the math, if you want me to just ask.

alternitively, we can take an orthographic projection of the scene from a view orthogonal to the x-z plane. we then render the heightmap by rendering only the z values of the result. to obtain intermediate z values we use scanline interpolation. we're basically drawing the terrain from a view below it looking up and we simply keep the z buffer contents and produce a heightmap of a specified precision. read up on orthographic or parallel projections. does anyone know if this is the standard way to generate a heightmap? it seems preferable to raytracing for non dynamic scene.

Tim

Share on other sites
Quote:
 Original post by blizzard999Solution: compute the triangle-plane and resolve by y

I still don't think in planes or vectors, just plain coordinate system :-)

Share on other sites
would you rather think in terms of rendering z values using orthographic projections? lol I think the plane technique is the most straightforward approach. google up on plane equations and vector.

Tim

Share on other sites
god I gotta step out of raytracing mode lol. my renderer project is turning me insane. blizzards solution is so much cleaner and obvious, lol.

Tim

• What is your GameDev Story?

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

• 11
• 12
• 10
• 11
• 13
• Forum Statistics

• Total Topics
634096
• Total Posts
3015480
×