use crate::math::*;
use crate::tables::FINETANGENT;
use super::Renderer;
pub const FIELDOFVIEW: usize = 2048;
impl Renderer {
pub fn init_texture_mapping(&mut self) {
let width = SCREENWIDTH as i32;
let center_x_frac = self.center_x_frac;
let focal_length = fixed_div(
center_x_frac,
FINETANGENT[FINEANGLES / 4 + FIELDOFVIEW / 2],
);
for (i, &tan) in FINETANGENT.iter().enumerate().take(FINEANGLES / 2) {
let t;
if tan > 2 * FRACUNIT {
t = -1;
} else if tan < -2 * FRACUNIT {
t = width + 1;
} else {
let x = fixed_mul(tan, focal_length);
let raw = (center_x_frac - x + FRACUNIT - 1) >> FRACBITS;
t = raw.clamp(-1, width + 1);
};
self.viewangletox[i] = t;
}
for x in 0..=SCREENWIDTH {
let mut i = 0;
while i < FINEANGLES / 2 && self.viewangletox[i] > x as i32 {
i += 1;
}
self.xtoviewangle[x] =
((i as u32) << ANGLETOFINESHIFT).wrapping_sub(ANG90);
}
self.clip_angle = self.xtoviewangle[0];
}
}