Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Triangle interpolation

Author
Message
Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 17th Oct 2011 19:32 Edited at: 17th Oct 2011 19:42
I've recently had problems making a function which figures out the height of a point on a 3D triangle from its three vertices' height values (talking about a surface element, not a triangle rotated at any angle!), and the X&Z position of the object i want to place onto the triangle (ground...)

Couldn't find a place anywhere which would have told me straight forward what to do, and rarely, what tried to tell me gave me tons of equations with a dozen unexplained variables... so i came up with my own solution and here it is:


(important detail: the triangle must have the same lenghts on all three sides, at least it was built for that)


The triangle's three verts are:

vertAx#, vertAy#, vertAz#
vertBx#, vertBy#, vertBz#
vertCx#, vertCy#, vertCz#

The point's coordinates where we want to get the height of the tri:
edTERRAIN3dmouseX#, edTERRAIN3dmouseZ#

We get the height in this variable:
HeightAt_ABC#

The code:



Good for not relying on any collision methods.

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%

Login to post a reply

Server time is: 2024-04-19 10:18:54
Your offset time is: 2024-04-19 10:18:54