Pick back up and comment
Clean placeholder code to get it running. Add comments to clarify working, add TODOs in main, add some references for the maths.
This commit is contained in:
parent
f21fc6f805
commit
2d396269e0
3 changed files with 34 additions and 4 deletions
18
World.cpp
18
World.cpp
|
@ -94,11 +94,15 @@ void World::fillColumn(sf::RenderWindow& window, int column, float scale, sf::Co
|
||||||
|
|
||||||
float World::castRay(float originX, float originY, float orientation)
|
float World::castRay(float originX, float originY, float orientation)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Reference used for ray intersection computations :
|
||||||
|
* https://web.archive.org/web/20220628034315/https://yunes.informatique.univ-paris-diderot.fr/wp-content/uploads/cours/INFOGRAPHIE/08-Raycasting.pdf
|
||||||
|
*/
|
||||||
float deltaX;
|
float deltaX;
|
||||||
float deltaY;
|
float deltaY;
|
||||||
if(orientation < 45 || orientation > 315)
|
if(orientation < 45 || orientation > 315)
|
||||||
{
|
{
|
||||||
deltaX = ;
|
|
||||||
}
|
}
|
||||||
else if(orientation < 135)
|
else if(orientation < 135)
|
||||||
{
|
{
|
||||||
|
@ -113,11 +117,16 @@ float World::castRay(float originX, float originY, float orientation)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::render(sf::RenderWindow& window) const
|
void World::render(sf::RenderWindow& window) const
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Draw ground and sky planes through half of the screen, as the walls
|
||||||
|
* will get drawn over them.
|
||||||
|
* This doesn't work if we support textures/levels.
|
||||||
|
*/
|
||||||
sf::RectangleShape ground = sf::RectangleShape(sf::Vector2f(window.getSize().x,window.getSize().y/2.0));
|
sf::RectangleShape ground = sf::RectangleShape(sf::Vector2f(window.getSize().x,window.getSize().y/2.0));
|
||||||
ground.setFillColor(groundColor);
|
ground.setFillColor(groundColor);
|
||||||
ground.setPosition(0,window.getSize().y/2.0);
|
ground.setPosition(0,window.getSize().y/2.0);
|
||||||
|
@ -128,10 +137,13 @@ void World::render(sf::RenderWindow& window) const
|
||||||
window.draw(ground);
|
window.draw(ground);
|
||||||
window.draw(ceiling);
|
window.draw(ceiling);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Throw rays and draw walls over the ceiling and ground.
|
||||||
|
* Only throws in the plane, which doesn't work for levels/3D.
|
||||||
|
*/
|
||||||
for(int i = 0;i<window.getSize().x;i++)
|
for(int i = 0;i<window.getSize().x;i++)
|
||||||
{
|
{
|
||||||
fillColumn(window, i, 0.5);
|
fillColumn(window, i, 0.5);
|
||||||
std::cout << i << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
7
World.h
7
World.h
|
@ -43,6 +43,13 @@ private:
|
||||||
sf::Color ceilingColor;
|
sf::Color ceilingColor;
|
||||||
|
|
||||||
void fillColumn(sf::RenderWindow&, int column, float scale, sf::Color wallColor = sf::Color(127,127,127)) const;
|
void fillColumn(sf::RenderWindow&, int column, float scale, sf::Color wallColor = sf::Color(127,127,127)) const;
|
||||||
|
/**
|
||||||
|
* Cast a ray from a given position and return the on-screen scale.
|
||||||
|
* @param originX Ray X origin
|
||||||
|
* @param originY Ray Y origin
|
||||||
|
* @param orientation Angle to cast to, in degrees
|
||||||
|
* @return Scale on the screen of the hit wall.
|
||||||
|
*/
|
||||||
float castRay(float originX, float originY, float orientation);
|
float castRay(float originX, float originY, float orientation);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
11
main.cpp
11
main.cpp
|
@ -3,6 +3,17 @@
|
||||||
|
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
|
||||||
|
// TODO: Handle inputs to move player
|
||||||
|
// TODO: Raycast from player position
|
||||||
|
// TODO: Fix raycasts and use it correctly
|
||||||
|
// TODO: Render world in event loop
|
||||||
|
// TODO: Understand what the code was doing (looks like scale from fill column is the output of the raycast)
|
||||||
|
// Ref: https://lodev.org/cgtutor/raycasting.html
|
||||||
|
// Ref: http://yunes.informatique.univ-paris-diderot.fr/wp-content/uploads/cours/INFOGRAPHIE/08-Raycasting.pdf
|
||||||
|
// TODO: Update player for camera plane
|
||||||
|
// TODO: Camera plane represents screen, rays go through it proportional to the screen
|
||||||
|
// TODO: Find a way to go to edges instead of just equally split (?)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Hello, World!" << std::endl;
|
std::cout << "Hello, World!" << std::endl;
|
||||||
|
|
Loading…
Add table
Reference in a new issue