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 Discussion / Math Behind 'getMatrixHeight'

Author
Message
Aramil_04
18
Years of Service
User Offline
Joined: 8th Dec 2007
Location:
Posted: 13th Mar 2009 23:30
Hello,

I've stopped using DarkBASIC many years ago, and I'm now programming in C++, using OpenGL. I've decided to write my own simple matrix class, but I'm struggling with the math involved in calculating matrix height. Here is basically what I'm doing:

1) Calculate the coordinates of the four corners of the matrix tile I'm standing on,
2) Find which half (upper-right or lower left triangle) of the tile I'm on,
3) Find the equation of the plane formed by the corners of this triangle,
4) Plug in all other values into the equation and solve for the y-coord.

Since my code isn't DarkBASIC, I probably shouldn't post it. I just need to know if my math technique is correct, because it doesn't seem to be working properly. It's possible it's my code, but if someone can confirm my technique, then I'll know if it's the math or not. Thanks!

- Geoff
Quirkyjim
17
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 14th Mar 2009 00:15
Check the Programming Talk forum, they'll have more help with C++ and other stuff like that.

~QJ
That's what they WANT you to think...
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 14th Mar 2009 00:34
or darkgdk. thats just for c++

New Site! Check it out \/
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Mar 2009 01:01
Aramil_04

That sounds about right math wise. I'll expand a bit:

Quote: "1) Calculate the coordinates of the four corners of the matrix tile I'm standing on,
2) Find which half (upper-right or lower left triangle) of the tile I'm on,
3) Find the equation of the plane formed by the corners of this triangle,
4) Plug in all other values into the equation and solve for the y-coord."


3a) Take two vectors from the found triangle and use the cross-product to calculate the normal to the plane.
3b) If you can calculate the normals ahead of time for each triangle and store them in an array, you could save yourself the calculation time by referencing the normal when it comes time to find the height.

4) Using the position, a reference vertex of the triangle, and the face normal, use the dot product to solve for height.

Enjoy your day.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 14th Mar 2009 08:54
I believe you could take the partial derivative of the plane from one angle towards the player's x and z coordinates to find the rate of change then just plug in the x and z values to find it. Can't remember the exact math, but google directional partial derivatives.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Aramil_04
18
Years of Service
User Offline
Joined: 8th Dec 2007
Location:
Posted: 15th Mar 2009 00:46
Quote: "
3a) Take two vectors from the found triangle and use the cross-product to calculate the normal to the plane.
3b) If you can calculate the normals ahead of time for each triangle and store them in an array, you could save yourself the calculation time by referencing the normal when it comes time to find the height.

4) Using the position, a reference vertex of the triangle, and the face normal, use the dot product to solve for height.
"


Yes, this is what I was doing, except your method has a different step 4. Anyways, I've implemented your idea instead and the height function seems to work well. At odds times the height is calculated wrong, but that's probably a coding error on my part. I'm probably getting the wrong tile corner coords some of the time. Thank you very much for the help!

Login to post a reply

Server time is: 2026-07-21 19:06:38
Your offset time is: 2026-07-21 19:06:38