PointHeight in a Triangle

Blitz3D Forums/Blitz3D Programming/PointHeight in a Triangle

RGR(Posted 2003) [#1]
;-


Koriolis(Posted 2003) [#2]
The simpler is to use bilinear filtering. Let's suppose that your terrain has one point per unit (as the default in blitz) and that the corner is positioned in (0,0) (also the default). Let's say (x,z) is the position on the terrain.
xi% = Int(x)
zi% = Int(z)
xfrac# = x-xi
zfrac# = z-zi
h00# = TerrainHeight(xi,zi)
h01# = TerrainHeight(xi,zi+1)
h10# = TerrainHeight(xi+1,zi)
h11# = TerrainHeight(xi+1,zi+1)
h# = (1-xfrac)*(1-yfrac)*h00 + xfrac*(1-yfrac)*h10 + (1-xfrac)*yfrac*h01 + xfrac*yfrac*h11

I didn't test it but it should work as is.
'h' holds the interpolated height.


RGR(Posted 2003) [#3]
;-


makakoman(Posted 2003) [#4]
Take a look at Swifts terrain system. There is an function in there, GetTerrainHeight, that uses the Plane Equation to get the height of any point in a quad.

MK


RGR(Posted 2003) [#5]
;-


RGR(Posted 2003) [#6]
;-


makakoman(Posted 2003) [#7]
@Kournikov,

Thanks - but if I get it right that's not what I want either. As I interpret it, Swift is finding the Position via Collision Camera - Terrain... at least in the version I have - no Include-file available ...

I am looking for a math-solution
------------------------------------------


I just noticed, Shawn must have taken the source code off the forums. If I remember correctly, he used to let people view the source to the Terrain System, but you had to license it if you wanted to use it in a project. Oh well. His code IS a math-solution. No camera/collision code. He uses the two triangles of the quad, determines which triangle the point lies in, then uses the plane equation to get the EXACT Y of the point X,Z on the plane of the triangle.

I am sorry for the confusion.

Regards,
MK


RGR(Posted 2003) [#8]
;-


RGR(Posted 2003) [#9]
;-


RGR(Posted 2003) [#10]
;-


cyberseth(Posted 2003) [#11]
You will have to use maths in order to find the height at a point. If you don't want to use maths, use LinePick. Here is a my LinePick bodge.

LinePick(x, Y, z, 0, -10000, 0)

Where Y is somewhere you know that's above the triangle, and x,z are the coordinates of the point you wanna check the height of. Basically it finds a point above the triangle, then does a linepick straight through it. Make sure your triangle is 'pickable' first.


RGR(Posted 2003) [#12]
;-


cyberseth(Posted 2003) [#13]
How was I to know you spent hours trying to find a math solution? Your headline said:
I found some wise explanations (google, etc.) use the Hesse-algorithm and blah blah and formulas that were not understandable for someone who has not studied mathematics...


That last bit can be taken to mean "I don't want a math solution, because they are too complicated", therefore I wrote a LinePick solution. You don't have to get so impatient and angry with me just for trying to offer an alternative, calling my post "such rubbish". Man, you posh Blitz uppercrusts are all alike.