More cleanup, mostly removing variables and simplifying the math.
This commit is contained in:
parent
113df851af
commit
033d5cdfec
3 changed files with 41 additions and 51 deletions
|
@ -41,6 +41,7 @@ void TexturePack::load_image(std::vector<uint32_t>& texture, const char *filenam
|
|||
sf::Image img;
|
||||
bool good = img.loadFromFile(filename);
|
||||
dbc::check(good, format("failed to load {}", filename));
|
||||
|
||||
uint32_t *pixbuf = (uint32_t *)img.getPixelsPtr();
|
||||
std::copy_n(pixbuf, texture.size(), texture.begin());
|
||||
}
|
||||
|
@ -63,10 +64,10 @@ Raycaster::Raycaster(sf::RenderWindow& window, Matrix &map) :
|
|||
textures.load_textures();
|
||||
}
|
||||
|
||||
void Raycaster::position_camera(float player_x, float player_y, int tile_size) {
|
||||
void Raycaster::position_camera(float player_x, float player_y) {
|
||||
// x and y start position
|
||||
posX = player_x / tile_size;
|
||||
posY = player_y / tile_size;
|
||||
posX = player_x;
|
||||
posY = player_y;
|
||||
}
|
||||
|
||||
void Raycaster::draw_pixel_buffer() {
|
||||
|
@ -370,32 +371,24 @@ void Raycaster::sort_sprites(int* order, double* dist, int amount)
|
|||
}
|
||||
}
|
||||
|
||||
void Raycaster::move_forward(double moveSpeed) {
|
||||
if(empty_space(int(posX + dirX * moveSpeed), int(posY))) posX += dirX * moveSpeed;
|
||||
if(empty_space(int(posX), int(posY + dirY * moveSpeed))) posY += dirY * moveSpeed;
|
||||
void Raycaster::run(double speed, int dir) {
|
||||
double speed_and_dir = speed * dir;
|
||||
if(empty_space(int(posX + dirX * speed_and_dir), int(posY))) {
|
||||
posX += dirX * speed_and_dir;
|
||||
}
|
||||
|
||||
if(empty_space(int(posX), int(posY + dirY * speed_and_dir))) {
|
||||
posY += dirY * speed_and_dir;
|
||||
}
|
||||
}
|
||||
|
||||
void Raycaster::move_backward(double moveSpeed) {
|
||||
if(empty_space(int(posX - dirX * moveSpeed), int(posY))) posX -= dirX * moveSpeed;
|
||||
if(empty_space(int(posX), int(posY - dirY * moveSpeed))) posY -= dirY * moveSpeed;
|
||||
}
|
||||
|
||||
void Raycaster::rotate_right(double rotSpeed) {
|
||||
void Raycaster::rotate(double speed, int dir) {
|
||||
double speed_and_dir = speed * dir;
|
||||
double oldDirX = dirX;
|
||||
dirX = dirX * cos(-rotSpeed) - dirY * sin(-rotSpeed);
|
||||
dirY = oldDirX * sin(-rotSpeed) + dirY * cos(-rotSpeed);
|
||||
dirX = dirX * cos(speed_and_dir) - dirY * sin(speed_and_dir);
|
||||
dirY = oldDirX * sin(speed_and_dir) + dirY * cos(speed_and_dir);
|
||||
|
||||
double oldPlaneX = planeX;
|
||||
planeX = planeX * cos(-rotSpeed) - planeY * sin(-rotSpeed);
|
||||
planeY = oldPlaneX * sin(-rotSpeed) + planeY * cos(-rotSpeed);
|
||||
}
|
||||
|
||||
void Raycaster::rotate_left(double rotSpeed) {
|
||||
double oldDirX = dirX;
|
||||
dirX = dirX * cos(rotSpeed) - dirY * sin(rotSpeed);
|
||||
dirY = oldDirX * sin(rotSpeed) + dirY * cos(rotSpeed);
|
||||
|
||||
double oldPlaneX = planeX;
|
||||
planeX = planeX * cos(rotSpeed) - planeY * sin(rotSpeed);
|
||||
planeY = oldPlaneX * sin(rotSpeed) + planeY * cos(rotSpeed);
|
||||
planeX = planeX * cos(speed_and_dir) - planeY * sin(speed_and_dir);
|
||||
planeY = oldPlaneX * sin(speed_and_dir) + planeY * cos(speed_and_dir);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue