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.

DarkBASIC Professional Discussion / Ground Height Mathematics

Author
Message
mimesis
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 25th Feb 2003 12:10
Would someone please tell me how the mathematics behind "GET GROUND HEIGHT(Matrix Number, X, Z)" works ?

I would like to use regular X mesh patches instead of matrixes. What I want to do is:
1. store the vertex positions in an array.
2. an algorythm would find wich of the vertex (3) to use for calculating the height of the patch at the current camera position.
3.Calculate the height based on the 3 vertices that make up the triangle the camera is currently over.

I think this have something to do with the Barycentric coordinate calculus of a point inside a triangle.

Any help would be grealty appreciated
mimesis
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 25th Feb 2003 14:54
hmmm, question to hard to hack ?
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 25th Feb 2003 15:10
Without having some code that does this (and not enough time to write some now) I can only give a few pointers.

I usually start anything 3D by considering the easier 2D equivalent, so for this we are trying to find the height of a point on a line in a right angled triangle IE :-
2
|\
O| \______height to find
| |\H
| | \
3-4--1
--A1--
-A2-
A1/A2 = adjacents, which we know (distance between points 1&3 / 1&4)
O = opposite, which we know (distance between point 3 & 2)
H = Hypotenuse, which we don`t know, or care about.

Using SOHCAHTOA we can use:-
Tan(angle) = O / A1 (where A1 = distance between point 1 & 3 And O is the height between points 3 & 2)
To find the angle between the opposite and adjacent at 1 (Note: you could pre-calc these and store in an array)
Then Using SOHCAHTOA again we can use:-
Tan(angle) = O / A2 (Where A2 = distance between point 1 & 4 and O is the height we want to find)
To find the height we want (O in this case)

Thats just the start of it, you still need to swap the equations round to get the numbers out, and adapt it to 3D (although you can probably cheat a bit with that, if your scape is constructed the same as DB`s matrix`s).

Hope this helps a bit, you could also try looking at the info here:-

http://http://www.programmersheaven.com/zone10/mh96.htm
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 25th Feb 2003 15:12
Oh bugger, the diagram got messed up due to the font being different, hope you can still sort it out.
mimesis
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 25th Feb 2003 18:30
Thanks Ratty for bringing me a step closer...
Dont know exactly what to search for at "programmersheaven"
as I dont know the right mathematical term\name for this use.
Is Barycentric coordinate the right term for this?
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 25th Feb 2003 19:08
its just the cross product of 4 vertex

ReturnA = ObjectPos / CrossProduct(VertexA,VertexC)
ReturnB = ObjectPos / CrossProduct(VertexB,VertexD)
ObjectPos.Y = CrossProduct(ReturnA,ReturnB) * CrossProduct((ObjectPos.X * ReturnA),(ObjectPos.Z * ReturnB))

... this is all cross products are
CrossProduction = (InputA + InputB / 2)

but ofcourse imagine you're doing this over the X,Y,Z

its kinda weird but its just really a fact of finding the centre, finding the percentage movement for the X,Z of the object. And then taking that and multiplying it from the base over the position...
lol ya know i'm not sure the math above is right, seems right - but i've been up for like 80hours now so forgive if the brain is going a little

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
rapscaLLion
23
Years of Service
User Offline
Joined: 29th Aug 2002
Location: Canada
Posted: 25th Feb 2003 23:22
Ugh, I confused and I've only been up 7 hours...

LOL @ raven, go get some sleep!

@Bassi: I have no clue, but there has been a program that conforms a matrix to a model, that way you can show the model, hide the matrix, and have some quick and dirty landscape collision

Alex Wanuch
aka rapscaLLion
Kousen Dev Progress >> Currently Working On Editors
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 26th Feb 2003 15:08
This came in another post:-

http://http://gamedevnetwork.com/index.php?catid=1

look for 'linear interpolation' as I think thats what you are trying to do (NOTE: DB has built in commands for this, never tried them though)

Login to post a reply

Server time is: 2026-07-16 18:21:39
Your offset time is: 2026-07-16 18:21:39