1
0
Fork 0

Compare commits

..

No commits in common. "9678e8c286e9cea11de67cf7ea70391a39af14f9" and "029f753bbf193eea2fcbe8a62c0b26f28929ebfa" have entirely different histories.

2 changed files with 5 additions and 30 deletions

View file

@ -99,7 +99,7 @@ std::ostream& operator<<(std::ostream& ostream, World const& world)
return(ostream);
}
RaycastResult World::castRay(float originX, float originY, float orientation) const
float World::castRay(float originX, float originY, float orientation) const
{
/*
* Reference used for ray intersection computations :
@ -214,21 +214,7 @@ RaycastResult World::castRay(float originX, float originY, float orientation) co
float vDist = sqrtf((originX - vCheckX)*(originX - vCheckX) +
(originY - vCheckY)*(originY - vCheckY));
RaycastResult result{};
if (hDist > vDist) {
result.distance = vDist;
result.hitX = vCheckX;
result.hitY = vCheckY;
} else {
result.distance = hDist;
result.hitX = hCheckX;
result.hitY = hCheckY;
}
result.hitBlock = getBlock(floorf(result.hitX) + vRound,
floorf(result.hitY));
return result;
return hDist > vDist ? vDist : hDist;
}
void World::fillColumn(sf::RenderWindow& window, unsigned int column,
@ -281,10 +267,7 @@ void World::render(sf::RenderWindow& window)
} else if (rayAngle > 360) {
rayAngle -= 360;
}
float obstacleScale = worldToCamera / (
castRay(player.x, player.y, rayAngle).distance *
cosf(deltaAngle*deg_to_rad)
);
float obstacleScale = worldToCamera / castRay(player.x, player.y, rayAngle);
/* 2 Is wall height in meters. */
fillColumn(window, i, obstacleScale);
}

12
World.h
View file

@ -9,7 +9,6 @@
#include <ostream>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <optional>
#include "Color.h"
#include "Player.h"
@ -21,13 +20,6 @@ enum class BlockType {
WINDOW,
};
struct RaycastResult {
float distance;
float hitX;
float hitY;
BlockType hitBlock;
};
class World {
public:
Player player;
@ -69,9 +61,9 @@ private:
* @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 Result struct containing information on the hit.
* @return Distance of the hit to the origin.
*/
RaycastResult castRay(float originX, float originY, float orientation) const;
float castRay(float originX, float originY, float orientation) const;
};