|
|
@ -97,9 +97,6 @@ void Raycaster::apply_sprite_effect(shared_ptr<sf::Shader> effect, float width, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Raycaster::sprite_casting(sf::RenderTarget &target) { |
|
|
|
void Raycaster::sprite_casting(sf::RenderTarget &target) { |
|
|
|
constexpr const int texture_width = TEXTURE_WIDTH; |
|
|
|
|
|
|
|
constexpr const int texture_height = TEXTURE_HEIGHT; |
|
|
|
|
|
|
|
constexpr const int half_height = TEXTURE_HEIGHT / 2; |
|
|
|
|
|
|
|
auto& lights = $level.lights->lighting(); |
|
|
|
auto& lights = $level.lights->lighting(); |
|
|
|
|
|
|
|
|
|
|
|
// sort sprites from far to close
|
|
|
|
// sort sprites from far to close
|
|
|
@ -110,6 +107,11 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { |
|
|
|
if(!$sprites.contains(rec.second)) continue; |
|
|
|
if(!$sprites.contains(rec.second)) continue; |
|
|
|
|
|
|
|
|
|
|
|
auto& sprite_texture = $sprites.at(rec.second); |
|
|
|
auto& sprite_texture = $sprites.at(rec.second); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int texture_width = (float)sprite_texture.frame_size.x; |
|
|
|
|
|
|
|
int texture_height =(float)sprite_texture.frame_size.y; |
|
|
|
|
|
|
|
int half_height = texture_height / 2; |
|
|
|
|
|
|
|
|
|
|
|
auto& sf_sprite = sprite_texture.sprite; |
|
|
|
auto& sf_sprite = sprite_texture.sprite; |
|
|
|
auto sprite_pos = $level.world->get<components::Position>(rec.second); |
|
|
|
auto sprite_pos = $level.world->get<components::Position>(rec.second); |
|
|
|
|
|
|
|
|
|
|
@ -175,7 +177,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { |
|
|
|
int d = y * texture_height - $height * half_height + sprite_height * half_height; |
|
|
|
int d = y * texture_height - $height * half_height + sprite_height * half_height; |
|
|
|
int tex_y = ((d * texture_height) / sprite_height) / texture_height; |
|
|
|
int tex_y = ((d * texture_height) / sprite_height) / texture_height; |
|
|
|
|
|
|
|
|
|
|
|
sf::Vector2f origin{texture_width / 2, texture_height / 2}; |
|
|
|
sf::Vector2f origin{texture_width / 2.0f, texture_height / 2.0f}; |
|
|
|
sf::Vector2f scale{sprite_scale_w, sprite_scale_h}; |
|
|
|
sf::Vector2f scale{sprite_scale_w, sprite_scale_h}; |
|
|
|
sf::Vector2f position{x + origin.x * scale.x, y + origin.y * scale.y}; |
|
|
|
sf::Vector2f position{x + origin.x * scale.x, y + origin.y * scale.y}; |
|
|
|
sf::IntRect in_texture{ {tex_x, tex_y}, {tex_render_width, texture_height}}; |
|
|
|
sf::IntRect in_texture{ {tex_x, tex_y}, {tex_render_width, texture_height}}; |
|
|
@ -323,8 +325,9 @@ void Raycaster::cast_rays() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Raycaster::draw_ceiling_floor() { |
|
|
|
void Raycaster::draw_ceiling_floor() { |
|
|
|
constexpr static const int texture_width = TEXTURE_WIDTH; |
|
|
|
constexpr const int texture_width = TEXTURE_WIDTH; |
|
|
|
constexpr static const int texture_height = TEXTURE_HEIGHT; |
|
|
|
constexpr const int texture_height = TEXTURE_HEIGHT; |
|
|
|
|
|
|
|
|
|
|
|
auto &lights = $level.lights->lighting(); |
|
|
|
auto &lights = $level.lights->lighting(); |
|
|
|
size_t surface_i = 0; |
|
|
|
size_t surface_i = 0; |
|
|
|
const RGBA *floor_texture = textures::get_surface(surface_i); |
|
|
|
const RGBA *floor_texture = textures::get_surface(surface_i); |
|
|
|