More cleaning of the Raycaster class to have no #defines for variables. Now it can be arbitrarily sized and positioned.
This commit is contained in:
parent
c9d4b7ed1e
commit
2dfe5417b1
3 changed files with 100 additions and 94 deletions
|
@ -14,12 +14,6 @@
|
|||
|
||||
using matrix::Matrix;
|
||||
|
||||
#define TEXTURE_WIDTH 256 // must be power of two
|
||||
#define TEXTURE_HEIGHT 256 // must be power of two
|
||||
|
||||
#define NUM_SPRITES 1
|
||||
#define NUM_TEXTURES 11
|
||||
|
||||
struct Sprite {
|
||||
double x;
|
||||
double y;
|
||||
|
@ -30,28 +24,28 @@ struct Sprite {
|
|||
int vDiv=1;
|
||||
};
|
||||
|
||||
#define RAY_VIEW_WIDTH 960
|
||||
#define RAY_VIEW_HEIGHT 720
|
||||
#define RAY_VIEW_X (1280 - RAY_VIEW_WIDTH)
|
||||
#define RAY_VIEW_Y 0
|
||||
|
||||
using RGBA = uint32_t;
|
||||
|
||||
struct TexturePack {
|
||||
std::vector<uint32_t> texture[NUM_TEXTURES];
|
||||
int NUM_SPRITES=1;
|
||||
int NUM_TEXTURES=11;
|
||||
int TEXTURE_WIDTH=256; // must be power of two
|
||||
int TEXTURE_HEIGHT=256; // must be power of two
|
||||
|
||||
std::vector<std::vector<uint32_t>> images;
|
||||
std::vector<Sprite> SPRITE{{4.0, 3.55, 8}};
|
||||
const int floor = 3;
|
||||
const int ceiling = 6;
|
||||
|
||||
void load_textures();
|
||||
void load_image(std::vector<uint32_t>& texture, const char *filename);
|
||||
std::vector<uint32_t> load_image(const char *filename);
|
||||
Sprite &get_sprite(size_t sprite_num);
|
||||
std::vector<uint32_t>& get(size_t num);
|
||||
};
|
||||
|
||||
struct Raycaster {
|
||||
int $width=RAY_VIEW_WIDTH;
|
||||
int $height=RAY_VIEW_HEIGHT;
|
||||
int PITCH=0;
|
||||
|
||||
TexturePack textures;
|
||||
double posX = 0;
|
||||
double posY = 0;
|
||||
|
@ -63,36 +57,39 @@ struct Raycaster {
|
|||
// the 2d raycaster version of camera plane
|
||||
double planeX = 0;
|
||||
double planeY = 0.66;
|
||||
|
||||
//ZED allocate this on the heap
|
||||
std::array<double, RAY_VIEW_WIDTH> ZBuffer;
|
||||
//ZED: USE smart pointer for this
|
||||
std::unique_ptr<RGBA[]> pixels = nullptr;
|
||||
|
||||
//ZED: heap too?
|
||||
int spriteOrder[NUM_SPRITES];
|
||||
double spriteDistance[NUM_SPRITES];
|
||||
|
||||
sf::Texture view_texture;
|
||||
sf::Sprite view_sprite;
|
||||
|
||||
//ZED: USE smart pointer for this
|
||||
std::unique_ptr<RGBA[]> pixels = nullptr;
|
||||
|
||||
int $width;
|
||||
int $height;
|
||||
sf::RenderWindow& $window;
|
||||
Matrix& $map;
|
||||
int PITCH=0;
|
||||
std::vector<int> spriteOrder;
|
||||
std::vector<double> spriteDistance;
|
||||
std::vector<double> ZBuffer; // width
|
||||
|
||||
Raycaster(sf::RenderWindow& window, Matrix &map);
|
||||
Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height);
|
||||
|
||||
void draw_pixel_buffer();
|
||||
void clear();
|
||||
void cast_rays();
|
||||
void sprite_casting();
|
||||
void draw_ceiling_floor();
|
||||
void sprite_casting();
|
||||
void sort_sprites(std::vector<int>& order, std::vector<double>& dist, int amount);
|
||||
void render();
|
||||
bool empty_space(int new_x, int new_y);
|
||||
void sort_sprites(int* order, double* dist, int amount);
|
||||
|
||||
// ZED these can be one or two functions
|
||||
bool empty_space(int new_x, int new_y);
|
||||
|
||||
void run(double speed, int dir);
|
||||
void rotate(double speed, int dir);
|
||||
void position_camera(float player_x, float player_y);
|
||||
|
||||
void set_position(int x, int y);
|
||||
inline size_t pixcoord(int x, int y) {
|
||||
return ((y) * $width) + (x);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue