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:
parent
ad5eca88fb
commit
06f0a49626
2 changed files with 22 additions and 2 deletions
15
raycastlib.h
15
raycastlib.h
|
@ -404,6 +404,12 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, HitResult *hitResults,
|
||||||
currentSquare.x = ray.start.x / UNITS_PER_SQUARE;
|
currentSquare.x = ray.start.x / UNITS_PER_SQUARE;
|
||||||
currentSquare.y = ray.start.y / 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;
|
*hitResultsLen = 0;
|
||||||
|
|
||||||
int16_t squareType = arrayFunc(currentSquare.x,currentSquare.y);
|
int16_t squareType = arrayFunc(currentSquare.x,currentSquare.y);
|
||||||
|
@ -446,8 +452,13 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, HitResult *hitResults,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ray.start.x = currentPos.x % UNITS_PER_SQUARE;
|
ray.start.x = currentPos.x < 0 ?
|
||||||
ray.start.y = currentPos.y % UNITS_PER_SQUARE;
|
(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);
|
castRaySquare(ray,&no,&co);
|
||||||
|
|
||||||
|
|
9
test.c
9
test.c
|
@ -124,6 +124,15 @@ int main()
|
||||||
16))
|
16))
|
||||||
return 1;
|
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)
|
for (Unit i = -UNITS_PER_SQUARE; i <= UNITS_PER_SQUARE; i += 64)
|
||||||
{
|
{
|
||||||
Unit v = sinInt(i);
|
Unit v = sinInt(i);
|
||||||
|
|
Loading…
Reference in a new issue