mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-12-23 01:26:19 +01:00
Add tests
This commit is contained in:
parent
b1146d8f05
commit
b59f44048b
2 changed files with 72 additions and 2 deletions
13
raycastlib.h
13
raycastlib.h
|
@ -58,6 +58,17 @@ typedef uint16_t uint_maybe32_t;
|
|||
printf(" dist: %d\n", h.distance);\
|
||||
printf(" texcoord: %d\n", h.textureCoord);}\
|
||||
|
||||
#define logPixelInfo(p){\
|
||||
printf("pixel:\n");\
|
||||
printf(" position: ");\
|
||||
logVector2D(p.position);\
|
||||
printf(" depth: %d\n", p.depth);\
|
||||
printf(" wall: %d\n", p.isWall);\
|
||||
printf(" textCoordY: %d\n", p.textureCoordY);\
|
||||
printf(" hit: ");\
|
||||
logHitResult(p.hit);\
|
||||
}\
|
||||
|
||||
/// Position in 2D space.
|
||||
typedef struct
|
||||
{
|
||||
|
@ -800,7 +811,7 @@ PixelInfo mapToScreen(Vector2D worldPosition, Unit height, Camera camera)
|
|||
|
||||
result.position.x = (a * middleColumn) / b;
|
||||
result.position.x = 2 * (middleColumn - result.position.x);
|
||||
|
||||
// TODO: ^ why is this 2 here?
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
61
test.c
61
test.c
|
@ -57,6 +57,49 @@ int testSingleRay(Unit startX, Unit startY, Unit dirX, Unit dirY,
|
|||
return result;
|
||||
}
|
||||
|
||||
int testSingleMapping(Unit posX, Unit posY, Unit posZ, uint32_t resX,
|
||||
uint32_t resY, Unit camX, Unit camY, Unit camZ, Unit camDir, Unit fov,
|
||||
Unit expectX, Unit expectY, Unit expectZ)
|
||||
{
|
||||
int result;
|
||||
|
||||
Camera c;
|
||||
|
||||
c.resolution.x = resX;
|
||||
c.resolution.y = resY;
|
||||
c.position.x = camY;
|
||||
c.position.y = camY;
|
||||
c.direction = camDir;
|
||||
c.height = posZ;
|
||||
c.fovAngle = fov;
|
||||
|
||||
Vector2D pos;
|
||||
Unit height;
|
||||
|
||||
pos.x = posX;
|
||||
pos.y = posY;
|
||||
height = posZ;
|
||||
|
||||
PixelInfo p;
|
||||
|
||||
printf("- mapping pixel: %d %d %d\n",posX,posY,posZ);
|
||||
|
||||
p = mapToScreen(pos,height,c);
|
||||
|
||||
printf("- result:\n");
|
||||
logPixelInfo(p);
|
||||
|
||||
result = p.position.x == expectX && p.position.y == expectY &&
|
||||
p.depth == expectZ;
|
||||
|
||||
if (result)
|
||||
printf("\nOK\n\n");
|
||||
else
|
||||
printf("\nFAIL\n\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// returns milliseconds
|
||||
long measureTime(void (*func)(void))
|
||||
{
|
||||
|
@ -95,7 +138,6 @@ void benchCastRays()
|
|||
|
||||
void benchmarkMapping()
|
||||
{
|
||||
Vector2D v;
|
||||
Camera c;
|
||||
|
||||
c.resolution.x = 1024;
|
||||
|
@ -165,6 +207,23 @@ int main()
|
|||
16))
|
||||
return 1;
|
||||
|
||||
if (!testSingleMapping(
|
||||
-UNITS_PER_SQUARE,
|
||||
0,
|
||||
UNITS_PER_SQUARE / 2,
|
||||
1280,
|
||||
640,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
UNITS_PER_SQUARE / 2,
|
||||
UNITS_PER_SQUARE / 4,
|
||||
1280, // shouldn't be half?
|
||||
320,
|
||||
1024
|
||||
))
|
||||
return -1;
|
||||
|
||||
for (Unit i = -UNITS_PER_SQUARE; i <= UNITS_PER_SQUARE; i += 64)
|
||||
{
|
||||
Unit v = sinInt(i);
|
||||
|
|
Loading…
Reference in a new issue