|
|
|
@ -1,9 +1,32 @@ |
|
|
|
|
#include "raycaster.hpp" |
|
|
|
|
#include "texture.hpp" |
|
|
|
|
#include <algorithm> |
|
|
|
|
|
|
|
|
|
using namespace fmt; |
|
|
|
|
using std::make_unique; |
|
|
|
|
|
|
|
|
|
union ColorConv { |
|
|
|
|
struct { |
|
|
|
|
uint8_t r; |
|
|
|
|
uint8_t g; |
|
|
|
|
uint8_t b; |
|
|
|
|
uint8_t a; |
|
|
|
|
} as_color; |
|
|
|
|
uint32_t as_int; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
inline uint32_t dumb_lighting(uint32_t pixel, double distance) { |
|
|
|
|
if(distance < 0.9) return pixel; |
|
|
|
|
|
|
|
|
|
ColorConv conv{.as_int=pixel}; |
|
|
|
|
conv.as_color.r /= distance; |
|
|
|
|
conv.as_color.g /= distance; |
|
|
|
|
conv.as_color.b /= distance; |
|
|
|
|
|
|
|
|
|
return conv.as_int; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Raycaster::Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height) : |
|
|
|
|
$width(width), $height(height), |
|
|
|
|
$window(window), |
|
|
|
@ -226,7 +249,7 @@ void Raycaster::cast_rays() { |
|
|
|
|
int texY = (int)texPos & (textures.TEXTURE_HEIGHT - 1); |
|
|
|
|
texPos += step; |
|
|
|
|
RGBA pixel = texture[textures.TEXTURE_HEIGHT * texY + texX]; |
|
|
|
|
pixels[pixcoord(x, y)] = pixel; |
|
|
|
|
pixels[pixcoord(x, y)] = dumb_lighting(pixel, perpWallDist); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SET THE ZBUFFER FOR THE SPRITE CASTING
|
|
|
|
|