Original Post
Hi !
This is a small errata for all of you who use the MAP loading tutorial from there:
http://folk.uio.no/stefanha/MAPFiles.pdf
Hi warned the author and he will correct that but he doesn''t have much time for that now.
So, I post some messages on the most popular forums or game programming.
In the SplitPolygon function (at the end of the tutorial), the "p" value is not
"p = -( pPlane_->n.Dot (pPoly_->vertices[ n ]) + pPlane_->d)) / denom;"
but
"p = -( pPlane_->n.Dot (pPoly_->vertices[ n ]) - pPlane_->d)) / denom;"
This was the correct answer, now some explainations.
A line''s equation is: "s + (e - s) * p = x" where s is the first vector of the line, e the second one and p is a real value (the one we are searching in the tutorial). It gives a vector x which is on the line.
A plane''s equation is "n . x + D = 0" where n is the normal vector of the line, x a vector
on the plane and D the plane''s translation.
Note that "." is the dot product and that we will define "d" as "d = e - s".
In the tutorial we want to find the intersection between the line and the plane. In order to do that, we substitute the x of the plane''s equation by the value of the x in the line''s equation (as our x must be on the line AND on the plane):
<=> n . (s + d * p) + D = 0
<=> - n . s - D = n . (d * p)
<=> p = (- n .s - D) / (n . d)
Et voilà, here we have the correct formula. The demonstration needs only the basic knowledge of dot product, vector, line and plane mathematics.
Hope this is correct. It seems for me.