neurodoom 0.6.7

Deterministic no_std Doom engine with semantic and depth perception buffers for AI
Documentation
use crate::math::*;
use crate::tables::FINETANGENT;

use super::Renderer;

/// Field of view in fine angles (2048 fine angles = 90 degrees).
pub const FIELDOFVIEW: usize = 2048;

impl Renderer {
    /// Build the viewangletox and xtoviewangle lookup tables.
    pub fn init_texture_mapping(&mut self) {
        let width = SCREENWIDTH as i32;
        let center_x_frac = self.center_x_frac;

        // Focal length for perspective projection
        let focal_length = fixed_div(
            center_x_frac,
            FINETANGENT[FINEANGLES / 4 + FIELDOFVIEW / 2],
        );

        // Build viewangletox: fine angle → screen x
        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;
        }

        // Build xtoviewangle: screen x → angle
        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);
        }

        // Clip angle = half FOV
        self.clip_angle = self.xtoviewangle[0];
    }
}