diff --git a/World.cpp b/World.cpp index 40120ed..1ca062c 100644 --- a/World.cpp +++ b/World.cpp @@ -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); } } diff --git a/World.h b/World.h index 7f716e3..6ecf4ab 100644 --- a/World.h +++ b/World.h @@ -54,11 +54,11 @@ private: void fillColumn(sf::RenderWindow&, unsigned int column, float scale, sf::Color wallColor = sf::Color(84,56,34)) const; /** - * Cast a ray from a given position and return the on-screen scale. + * Cast a ray from a given position and its distance to the origin. * @param originX Ray X origin, strictly positive * @param originY Ray Y origin, strictly positive * @param orientation Angle to cast to, in degrees between 0 and 360 - * @return Scale on the screen of the hit wall. + * @return Distance of the hit to the origin. */ float castRay(float originX, float originY, float orientation) const; };