Implement basic first person view rendering.

This commit is contained in:
2023-04-20 02:21:21 +01:00
parent d186b948a7
commit 4a9d85ba1c
3 changed files with 25 additions and 8 deletions
+20 -4
View File
@@ -20,16 +20,32 @@ int firstperson_init(unsigned int _width, unsigned int _height)
return 1;
}
void firstperson_update(sf::RenderTarget* renderTarget)
void firstperson_update(sf::RenderTarget* renderTarget, Camera* camera)
{
const float columnWidth = (float)width/(float)camera->resolution;
float columnHeight = 0;
renderTexture.clear();
sf::CircleShape shape(50);
renderTexture.draw(shape);
renderTexture.display();
for (unsigned int i = 0; i < camera->resolution; i++) {
float distance = camera->rays[i].distance;
if (distance > 0.f) columnHeight = 0.5f * (float)height/camera->rays[i].distance;
float centeredHeight = (float)height/2.f - columnHeight/2.f;
float distanceScale = distance/10.f;
distanceScale = (distanceScale > 1.f)? 1.f : distanceScale;
float brightness = 255.f*(1.f-distanceScale);
sf::RectangleShape rectangle(sf::Vector2f(columnWidth, columnHeight));
rectangle.setPosition(sf::Vector2f(i*columnWidth, centeredHeight));
rectangle.setFillColor(sf::Color(brightness, brightness, brightness));
renderTexture.draw(rectangle);
}
renderTexture.display();
sf::Sprite sprite(renderTexture.getTexture());
sprite.setPosition(renderTexturePosition);
renderTarget->draw(sprite);
}
void firstperson_setTexturePosition(float x, float y)