1
0
Fork 0
Toy-Raytracer/World.h

69 lines
1.5 KiB
C
Raw Normal View History

2019-05-27 13:50:49 +02:00
//
// Created by trotfunky on 27/05/19.
//
#ifndef RAYCASTING_WORLD_H
#define RAYCASTING_WORLD_H
#include <vector>
#include <ostream>
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Color.h"
#include "Player.h"
2019-05-27 13:50:49 +02:00
enum class BlockType {
2024-01-28 22:08:35 +00:00
AIR,
WALL,
DOOR,
WINDOW,
2019-05-27 13:50:49 +02:00
};
class World {
public:
2024-01-28 22:08:35 +00:00
Player player;
2019-05-27 13:50:49 +02:00
2024-01-28 22:08:35 +00:00
World(int w, int h,
sf::Color groundColor = Colors::Ground,
sf::Color ceilingColor = Colors::Ceiling,
std::vector<BlockType> worldMap = {});
int getW() const;
int getH() const;
2019-05-27 13:50:49 +02:00
inline BlockType getBlock(int x, int y) const;
inline BlockType getBlock(float x, float y) const;
void setBlock(BlockType block, int x, int y, int width = 1, int height = 1);
2019-05-27 13:50:49 +02:00
2024-01-28 22:08:35 +00:00
void render(sf::RenderWindow&) const;
2024-01-28 22:08:35 +00:00
/**
* Move the world one step forward.
* @param stepTime delta time since last step, in seconds
*/
void step(const float& stepTime);
2024-01-28 22:08:35 +00:00
friend std::ostream& operator<<(std::ostream& ostream, World const & world);
2019-05-27 13:50:49 +02:00
private:
2024-01-28 22:08:35 +00:00
int w;
int h;
std::vector<BlockType> map;
2024-01-28 22:08:35 +00:00
sf::Color groundColor;
sf::Color ceilingColor;
2024-01-28 22:08:35 +00:00
void fillColumn(sf::RenderWindow&, unsigned int column, float scale,
sf::Color fillColor = Colors::Wall) const;
/**
* Cast a ray from a given position and return its distance to the origin.
* @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 Distance of the hit to the origin.
*/
float castRay(float originX, float originY, float orientation) const;
2019-05-27 13:50:49 +02:00
};
#endif //RAYCASTING_WORLD_H