Refactored the CameraLOL to be inside the rayview instead of a convolute main_ui->camera->rayview and back. Closes #16.

This commit is contained in:
Zed A. Shaw 2025-06-29 11:11:12 -04:00
parent 75c28cd764
commit ab1a415b55
7 changed files with 83 additions and 89 deletions

View file

@ -442,3 +442,63 @@ void Raycaster::update_level(GameLevel level) {
void Raycaster::init_shaders() {
$brightness = shaders::get("rayview_sprites");
}
Point Raycaster::plan_move(int dir, bool strafe) {
$camera.t = 0.0;
if(strafe) {
$camera.target_x = $pos_x + int(-$dir_y * 1.5 * dir);
$camera.target_y = $pos_y + int($dir_x * 1.5 * dir);
} else {
$camera.target_x = $pos_x + int($dir_x * 1.5 * dir);
$camera.target_y = $pos_y + int($dir_y * 1.5 * dir);
}
return {size_t($camera.target_x), size_t($camera.target_y)};
}
void Raycaster::plan_rotate(int dir, float amount) {
$camera.t = 0.0;
double angle_dir = std::numbers::pi * amount * float(dir);
$camera.target_dir_x = $dir_x * cos(angle_dir) - $dir_y * sin(angle_dir);
$camera.target_dir_y = $dir_x * sin(angle_dir) + $dir_y * cos(angle_dir);
$camera.target_plane_x = $plane_x * cos(angle_dir) - $plane_y * sin(angle_dir);
$camera.target_plane_y = $plane_x * sin(angle_dir) + $plane_y * cos(angle_dir);
}
bool Raycaster::play_rotate() {
$camera.t += $camera.rot_speed;
$dir_x = std::lerp($dir_x, $camera.target_dir_x, $camera.t);
$dir_y = std::lerp($dir_y, $camera.target_dir_y, $camera.t);
$plane_x = std::lerp($plane_x, $camera.target_plane_x, $camera.t);
$plane_y = std::lerp($plane_y, $camera.target_plane_y, $camera.t);
return $camera.t >= 1.0;
}
bool Raycaster::play_move() {
$camera.t += $camera.move_speed;
$pos_x = std::lerp($pos_x, $camera.target_x, $camera.t);
$pos_y = std::lerp($pos_y, $camera.target_y, $camera.t);
return $camera.t >= 1.0;
}
void Raycaster::abort_plan() {
$camera.target_x = $pos_x;
$camera.target_y = $pos_y;
}
Point Raycaster::aimed_at() {
return {
size_t($pos_x + $dir_x),
size_t($pos_y + $dir_y)
};
}
Point Raycaster::camera_target() {
return {
size_t($camera.target_x),
size_t($camera.target_y)};
}