ref: 388ac5e22b561fec0acae369f3ec21c4be9a9f99
parent: c1414921e4a25ae93629a6430f4edf1f304607ee
author: fabien sanglard <fabiensanglard@fabiens-Mac-Pro-3.local>
date: Thu Jan 31 19:25:31 EST 2013
Added comments to algorithm.
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -4468,7 +4468,7 @@
Algorithm: This is an optimized raycasting inside polygon test:
http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm
- The goal is to follow an horizontal ray passing by (x,y) and count how many
+ The goal is to follow an ***horizontal*** ray passing by (x,y) and count how many
wall are being crossed.
If it is an odd number of time: (x,y) is inside the sector.
If it is an even nymber of time:(x,y) is outside the sector.
@@ -4493,6 +4493,7 @@
// Compare the sign of y1 and y2.
// If (y1^y2) < 0 : y1 and y2 have different sign bit: y is between wal->y and wall[wal->point2].y.
+ // The goal is to not take into consideration any wall that is totally above or totally under the point [x,y].
if ((y1^y2) < 0)
{
x1 = wal->x-x;
@@ -4501,13 +4502,13 @@
//If (x1^x2) >= 0 x1 and x2 have identic sign bit: x is on the left or the right of both wal->x and wall[wal->point2].x.
if ((x1^x2) >= 0)
{
- // If (x,y) is on totally on the left or on the right, just count x1 (which indicate if we are on
- // (x,y) is on the left or on the right.
+ // If (x,y) is totally on the left or on the right, just count x1 (which indicate if we are on
+ // on the left or on the right.
wallCrossed ^= x1;
}
else
{
- // This is the most complicated case: X is between x1 and x2 and y is between y1 and y2.
+ // This is the most complicated case: X is between x1 and x2, we need a fine grained test.
// We need to know exactly if it is on the left or on the right in order to know if the ray
// is crossing the wall or not,
// The sign of the Cross-Product can answer this case :) !