<commit_before>use base::math::*;

pub struct Camera {
    pub position: Point3f, // PRP
    pub view_up_vector: Vector3f, // VUV
    // used to calculate the look_at_point
    pub theta: f32,
    pub phi: f32,
}

impl Default for Camera {
    fn default() -> Camera {
        Camera {
            position: Point3::new(0.0, 0.0, 60.0),
            phi: 0.0,
            theta: 0.0,
            view_up_vector: Vector3::unit_z(),
        }
    }
}

impl Camera {
    /// Returns the projection matrix
    pub fn proj_matrix(&self) -> Matrix4<f32> {
        perspective(deg(60.0), 16.0 / 9.0, 0.1, 100.0)
    }

    /// Returns view matrix
    pub fn view_matrix(&self) -> Matrix4<f32> {
        Matrix4::look_at(self.position, self.get_look_at_point(), self.view_up_vector)
    }

    /// Calculates the look_at_point by using theta and phi on the unit sphere
    pub fn get_look_at_point(&self) -> Point3f {
        self.position + self.get_look_at_vector()
    }

    pub fn get_look_at_vector(&self) -> Vector3f {
        Vector3f::new(self.theta.sin() * self.phi.cos(),
                      self.theta.sin() * self.phi.sin(),
                      self.theta.cos())
    }

    pub fn move_by(&mut self, pos_diff: Vector3f) {
        self.position += pos_diff;
    }

    /// Method to call when forward or backward movement is needed
    /// `factor` is a factor to scale the movement speed
    /// `factor` has to be positive for foward movement
    pub fn move_forward(&mut self, factor: f32) {
        let mut lookatvector = self.get_look_at_vector();
        lookatvector.z = 0.0;
        lookatvector.normalize();
        lookatvector *= factor;
        self.move_by(lookatvector);
    }

    // Implement forwars, backward, left and right seperately

    /// Method to call when left or right movement is needed
    /// `factor` is a factor to scale the movement speed
    /// `factor` has to be positive for left movement
    /// `factor` has to be negative for right movement
    // pub fn move_left_right(&mut self, factor: f32) {
    //     let mut lookatvector = self.get_look_at_vector();
    //     lookatvector.z = 0.0;
    //     lookatvector.normalize();
    //     // Get the orthogonal 2d-vector, which is 90 degrees to the left
    // let mut move_dir = Vector3f::new(-lookatvector.y, lookatvector.x,
    // 0.0);
    //     move_dir *= factor;
    //     self.move_by(move_dir);
    //
    // }
    /// Method to call when upward or downward movement is needed
    /// `factor` is a factor to scale the movement speed
    /// `factor` has to be positive for upward movement
    /// `factor` has to be negative for downward movement
    // pub fn move_up_down(&mut self, factor: f32) {
    //     self.move_by(Vector3f::new(0.0, 0.0, factor));
    // }


    pub fn change_dir(&mut self, theta_diff: f32, phi_diff: f32) {
        self.theta += theta_diff;
        self.phi += phi_diff;
        // new matrix will be calculated
    }
}
<commit_msg>add documentation<commit_after>use base::math::*;

pub struct Camera {
    pub position: Point3f, // PRP
    pub view_up_vector: Vector3f, // VUV
    // used to calculate the look_at_point
    pub theta: f32,
    pub phi: f32,
}

// Initinal values
impl Default for Camera {
    fn default() -> Camera {
        Camera {
            position: Point3::new(0.0, 0.0, 60.0),
            phi: 0.0,
            theta: 0.0,
            view_up_vector: Vector3::unit_z(),
        }
    }
}

impl Camera {
    /// Returns the projection matrix
    pub fn proj_matrix(&self) -> Matrix4<f32> {
        perspective(deg(60.0), 16.0 / 9.0, 0.1, 100.0)
    }

    /// Returns view matrix
    pub fn view_matrix(&self) -> Matrix4<f32> {
        Matrix4::look_at(self.position, self.get_look_at_point(), self.view_up_vector)
    }

    /// Calculates the look_at_point by adding the current position to the
    /// look_at_vector
    pub fn get_look_at_point(&self) -> Point3f {
        self.position + self.get_look_at_vector()
    }

    /// Calculates the look_at_vector by using theta and phi on the unit sphere
    pub fn get_look_at_vector(&self) -> Vector3f {
        Vector3f::new(self.theta.sin() * self.phi.cos(),
                      self.theta.sin() * self.phi.sin(),
                      self.theta.cos())
    }

    /// Internal function to move the position of the camera
    /// Will be called by the other functions (move_forwars etc)
    pub fn move_by(&mut self, pos_diff: Vector3f) {
        self.position += pos_diff;
    }

    /// Method to call when forward or backward movement is needed
    /// `factor` is a factor to scale the movement speed
    /// `factor` has to be positive for foward movement
    pub fn move_forward(&mut self, factor: f32) {
        let mut lookatvector = self.get_look_at_vector();
        lookatvector.z = 0.0;
        lookatvector.normalize();
        lookatvector *= factor;
        self.move_by(lookatvector);
    }

    // Implement forwars, backward, left and right seperately

    /// Method to call when left or right movement is needed
    /// `factor` is a factor to scale the movement speed
    /// `factor` has to be positive for left movement
    /// `factor` has to be negative for right movement
    // pub fn move_left_right(&mut self, factor: f32) {
    //     let mut lookatvector = self.get_look_at_vector();
    //     lookatvector.z = 0.0;
    //     lookatvector.normalize();
    //     // Get the orthogonal 2d-vector, which is 90 degrees to the left
    // let mut move_dir = Vector3f::new(-lookatvector.y, lookatvector.x,
    // 0.0);
    //     move_dir *= factor;
    //     self.move_by(move_dir);
    //
    // }
    /// Method to call when upward or downward movement is needed
    /// `factor` is a factor to scale the movement speed
    /// `factor` has to be positive for upward movement
    /// `factor` has to be negative for downward movement
    // pub fn move_up_down(&mut self, factor: f32) {
    //     self.move_by(Vector3f::new(0.0, 0.0, factor));
    // }
    /// Changes `theta` and `phi` to essentially change the direction the
    /// camera looks
    pub fn change_dir(&mut self, theta_diff: f32, phi_diff: f32) {
        self.theta += theta_diff;
        self.phi += phi_diff;
    }
}

{'fraction_non_alphanumeric': 0.11855174623518103, 'fraction_numerical': 0.022108298622236462, 'mean_word_length': 2.162613981762918, 'pattern_counts': {'":': 0, '<': 7, '<?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': '311151', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1961, 'n_words': 601}