<commit_before>use nalgebra::{normalize, cross, zero, Vec3, BaseFloat};

pub struct Camera {
    fov: f32,
    near: f32,
    far: f32,
    aspect_ratio: f32,
    pos: Vec3<f32>,
    look_at: Vec3<f32>,
}

impl Camera {
    pub fn new(pos: Vec3<f32>) -> Self {
        Camera { fov: BaseFloat::frac_pi_2(), near: 0.1, far: 1024., aspect_ratio: 4./3.,
                 pos: pos, look_at: zero() }
    }

    pub fn set_pos(&mut self, pos: Vec3<f32>) {
        self.pos = pos;
    }

    pub fn get_projection_matrix(&self) -> [[f32; 4]; 4] {
        let n = self.near;
        let f = self.far;

        let y = 1. / (self.fov / 2.).tan();
        let x = y * self.aspect_ratio;
        let a = (f + n) / (f - n);
        let b = (2. * f * n) / (f - n);

        [[x,  0., 0., 0.],
         [0., y,  0., 0.],
         [0., 0., a, -1.],
         [0., 0., b,  0.]]
    }

    pub fn get_view_matrix(&self) -> [[f32; 4]; 4] {
        // Forward vector
        let w = normalize(&(self.look_at - self.pos));
        let up = Vec3::new(0., 1., 0.);

        // The up vector cannot be parallel (in this case, the same) as the forward vector
        debug_assert!(w != up);

        // Right vector
        let u = normalize(&cross(&w, &up));<commit_msg>Fix camera<commit_after>use nalgebra::{normalize, cross, zero, Vec3, BaseFloat};

pub struct Camera {
    fov: f32,
    near: f32,
    far: f32,
    aspect_ratio: f32,
    pos: Vec3<f32>,
    look_at: Vec3<f32>,
}

impl Camera {
    pub fn new(pos: Vec3<f32>) -> Self {
        Camera { fov: BaseFloat::frac_pi_2(), near: 0.1, far: 1024., aspect_ratio: 4./3.,
                 pos: pos, look_at: zero() }
    }

    pub fn set_pos(&mut self, pos: Vec3<f32>) {
        self.pos = pos;
    }

    pub fn get_projection_matrix(&self) -> [[f32; 4]; 4] {
        let n = self.near;
        let f = self.far;

        let y = 1. / (self.fov / 2.).tan();
        let x = y * self.aspect_ratio;
        let a = (f + n) / (n - f);
        let b = (2. * f * n) / (n - f);

        [[x,  0., 0., 0.],
         [0., y,  0., 0.],
         [0., 0., a, -1.],
         [0., 0., b,  0.]]
    }

    pub fn get_view_matrix(&self) -> [[f32; 4]; 4] {
        // Forward vector
        let w = normalize(&(self.look_at - self.pos));
        let up = Vec3::new(0., 1., 0.);

        // The up vector cannot be parallel (in this case, the same) as the forward vector
        debug_assert!(w != up);

        // Right vector
        let u = normalize(&cross(&w, &up));
{'fraction_non_alphanumeric': 0.18225612203934163, 'fraction_numerical': 0.04576475311120032, 'mean_word_length': 1.6911447084233262, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1247704', 'n_tokens_mistral': 1012, 'n_tokens_neox': 931, 'n_words': 280}