1
0
Fork 0

World: make CastRay generic

Previously CastRay did the scale computation and used the player view statistics.
This makes it quite specialized, and the rest of the computations are made outside.

Move the computations in the render function and make castRay generic.
This commit is contained in:
Teo-CD 2024-01-25 22:30:38 +00:00
parent ddb01d0509
commit a0b6536432
2 changed files with 5 additions and 6 deletions

View file

@ -200,10 +200,8 @@ float World::castRay(float originX, float originY, float orientation) const
(originY - hCheckY)*(originY - hCheckY));
float vDist = sqrtf((originX - vCheckX)*(originX - vCheckX) +
(originY - vCheckY)*(originY - vCheckY));
float finalDist = hDist > vDist ? vDist : hDist;
/* 2 Is wall height in meters. */
return player.focalLength*2/finalDist;
return hDist > vDist ? vDist : hDist;
}
void World::fillColumn(sf::RenderWindow& window, unsigned int column,
@ -250,7 +248,8 @@ void World::render(sf::RenderWindow& window) const
} else if (rayAngle > 360) {
rayAngle -= 360;
}
float obstacleScale = castRay(player.x, player.y, rayAngle)/player.sensorSize;
float obstacleScale = player.focalLength*2/(castRay(player.x, player.y, rayAngle)*player.sensorSize);
/* 2 Is wall height in meters. */
fillColumn(window, i, obstacleScale);
}
}