1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-21 20:29:59 +01:00

Allow negative coordinates

This commit is contained in:
Miloslav Číž 2018-09-02 21:43:44 +02:00
parent ad5eca88fb
commit 06f0a49626
2 changed files with 22 additions and 2 deletions

View file

@ -404,6 +404,12 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, HitResult *hitResults,
currentSquare.x = ray.start.x / UNITS_PER_SQUARE;
currentSquare.y = ray.start.y / UNITS_PER_SQUARE;
if (ray.start.x < 0) // round down, not toward zero
currentSquare.x--;
if (ray.start.y < 0)
currentSquare.y--;
*hitResultsLen = 0;
int16_t squareType = arrayFunc(currentSquare.x,currentSquare.y);
@ -446,8 +452,13 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, HitResult *hitResults,
break;
}
ray.start.x = currentPos.x % UNITS_PER_SQUARE;
ray.start.y = currentPos.y % UNITS_PER_SQUARE;
ray.start.x = currentPos.x < 0 ?
(UNITS_PER_SQUARE + currentPos.x % UNITS_PER_SQUARE - 1) :
(currentPos.x % UNITS_PER_SQUARE);
ray.start.y = currentPos.y < 0 ?
(UNITS_PER_SQUARE + currentPos.y % UNITS_PER_SQUARE - 1) :
(currentPos.y % UNITS_PER_SQUARE);
castRaySquare(ray,&no,&co);

9
test.c
View file

@ -124,6 +124,15 @@ int main()
16))
return 1;
if (!testSingleRay(
-4 * UNITS_PER_SQUARE - UNITS_PER_SQUARE / 2,
7 * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 3,
100,-100,
0, 2,
1, 2900,
16))
return 1;
for (Unit i = -UNITS_PER_SQUARE; i <= UNITS_PER_SQUARE; i += 64)
{
Unit v = sinInt(i);