mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-23 20:49:57 +01:00
Fix pokitto bugs
This commit is contained in:
parent
c4d5f80eab
commit
40d80db615
1 changed files with 21 additions and 21 deletions
42
raycastlib.h
42
raycastlib.h
|
@ -165,18 +165,18 @@ void render(Camera cam, ArrayFunction arrayFunc, PixelFunc pixelFunc,
|
||||||
|
|
||||||
#define printProfile() {\
|
#define printProfile() {\
|
||||||
printf("profile:\n");\
|
printf("profile:\n");\
|
||||||
printf(" profile_sqrtInt: %d\n",profile_sqrtInt);\
|
printf(" sqrtInt: %d\n",profile_sqrtInt);\
|
||||||
printf(" profile_clamp: %d\n",profile_clamp);\
|
printf(" clamp: %d\n",profile_clamp);\
|
||||||
printf(" profile_cosInt: %d\n",profile_cosInt);\
|
printf(" cosInt: %d\n",profile_cosInt);\
|
||||||
printf(" profile_angleToDirection: %d\n",profile_angleToDirection);\
|
printf(" angleToDirection: %d\n",profile_angleToDirection);\
|
||||||
printf(" profile_dist: %d\n",profile_dist);\
|
printf(" dist: %d\n",profile_dist);\
|
||||||
printf(" profile_len: %d\n",profile_len);\
|
printf(" len: %d\n",profile_len);\
|
||||||
printf(" profile_pointIsLeftOfRay: %d\n",profile_pointIsLeftOfRay);\
|
printf(" pointIsLeftOfRay: %d\n",profile_pointIsLeftOfRay);\
|
||||||
printf(" profile_castRaySquare: %d\n",profile_castRaySquare);\
|
printf(" castRaySquare: %d\n",profile_castRaySquare);\
|
||||||
printf(" profile_castRayMultiHit : %d\n",profile_castRayMultiHit);\
|
printf(" castRayMultiHit : %d\n",profile_castRayMultiHit);\
|
||||||
printf(" profile_castRay: %d\n",profile_castRay);\
|
printf(" castRay: %d\n",profile_castRay);\
|
||||||
printf(" profile_normalize: %d\n",profile_normalize);\
|
printf(" normalize: %d\n",profile_normalize);\
|
||||||
printf(" profile_vectorsAngleCos: %d\n",profile_vectorsAngleCos); }
|
printf(" vectorsAngleCos: %d\n",profile_vectorsAngleCos); }
|
||||||
#else
|
#else
|
||||||
#define profileCall(c)
|
#define profileCall(c)
|
||||||
#endif
|
#endif
|
||||||
|
@ -274,7 +274,7 @@ Unit dist(Vector2D p1, Vector2D p2)
|
||||||
dx = dx * dx;
|
dx = dx * dx;
|
||||||
dy = dy * dy;
|
dy = dy * dy;
|
||||||
|
|
||||||
return sqrtInt(((uint32_t) dx) + ((uint32_t) dy));
|
return sqrtInt((uint32_t) (dx + dy));
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit len(Vector2D v)
|
Unit len(Vector2D v)
|
||||||
|
@ -291,8 +291,8 @@ int8_t pointIsLeftOfRay(Vector2D point, Ray ray)
|
||||||
{
|
{
|
||||||
profileCall(pointIsLeftOfRay);
|
profileCall(pointIsLeftOfRay);
|
||||||
|
|
||||||
int dX = point.x - ray.start.x;
|
Unit dX = point.x - ray.start.x;
|
||||||
int dY = point.y - ray.start.y;
|
Unit dY = point.y - ray.start.y;
|
||||||
return (ray.direction.x * dY - ray.direction.y * dX) > 0;
|
return (ray.direction.x * dY - ray.direction.y * dX) > 0;
|
||||||
// ^ Z component of cross-product
|
// ^ Z component of cross-product
|
||||||
}
|
}
|
||||||
|
@ -381,16 +381,16 @@ void castRayMultiHit(Ray ray, ArrayFunction arrayFunc, HitResult *hitResults,
|
||||||
|
|
||||||
*hitResultsLen = 0;
|
*hitResultsLen = 0;
|
||||||
|
|
||||||
int_fast16_t squareType = arrayFunc(currentSquare.x,currentSquare.y);
|
int16_t squareType = arrayFunc(currentSquare.x,currentSquare.y);
|
||||||
|
|
||||||
Vector2D no, co; // next cell offset, collision offset
|
Vector2D no, co; // next cell offset, collision offset
|
||||||
|
|
||||||
no.x = 0; // just to supress a warning
|
no.x = 0; // just to supress a warning
|
||||||
no.y = 0;
|
no.y = 0;
|
||||||
|
|
||||||
for (uint_fast16_t i = 0; i < constraints.maxSteps; ++i)
|
for (uint16_t i = 0; i < constraints.maxSteps; ++i)
|
||||||
{
|
{
|
||||||
int_fast16_t currentType = arrayFunc(currentSquare.x,currentSquare.y);
|
int16_t currentType = arrayFunc(currentSquare.x,currentSquare.y);
|
||||||
|
|
||||||
if (currentType != squareType)
|
if (currentType != squareType)
|
||||||
{
|
{
|
||||||
|
@ -457,7 +457,7 @@ HitResult castRay(Ray ray, ArrayFunction arrayFunc)
|
||||||
void castRaysMultiHit(Camera cam, ArrayFunction arrayFunc, HitFunction hitFunc,
|
void castRaysMultiHit(Camera cam, ArrayFunction arrayFunc, HitFunction hitFunc,
|
||||||
RayConstraints constraints)
|
RayConstraints constraints)
|
||||||
{
|
{
|
||||||
uint_fast16_t fovHalf = cam.fovAngle / 2;
|
uint16_t fovHalf = cam.fovAngle / 2;
|
||||||
|
|
||||||
Vector2D dir1 = angleToDirection(cam.direction - fovHalf);
|
Vector2D dir1 = angleToDirection(cam.direction - fovHalf);
|
||||||
Vector2D dir2 = angleToDirection(cam.direction + fovHalf);
|
Vector2D dir2 = angleToDirection(cam.direction + fovHalf);
|
||||||
|
@ -471,14 +471,14 @@ void castRaysMultiHit(Camera cam, ArrayFunction arrayFunc, HitFunction hitFunc,
|
||||||
Ray r;
|
Ray r;
|
||||||
r.start = cam.position;
|
r.start = cam.position;
|
||||||
|
|
||||||
for (uint_fast8_t i = 0; i < cam.resolution.x; ++i)
|
for (uint8_t i = 0; i < cam.resolution.x; ++i)
|
||||||
{
|
{
|
||||||
r.direction.x = dir1.x + (dX * i) / cam.resolution.x;
|
r.direction.x = dir1.x + (dX * i) / cam.resolution.x;
|
||||||
r.direction.y = dir1.y + (dY * i) / cam.resolution.x;
|
r.direction.y = dir1.y + (dY * i) / cam.resolution.x;
|
||||||
|
|
||||||
castRayMultiHit(r,arrayFunc,hits,&hitCount,constraints);
|
castRayMultiHit(r,arrayFunc,hits,&hitCount,constraints);
|
||||||
|
|
||||||
for (uint_fast8_t j = 0; j < hitCount; ++j)
|
for (uint8_t j = 0; j < hitCount; ++j)
|
||||||
hitFunc(i,hits[j],j,r);
|
hitFunc(i,hits[j],j,r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue