Fix camera for egui renderer

This commit is contained in:
hal8174 2024-11-29 20:24:49 +01:00
parent 1bfef16afa
commit 632cb97007
3 changed files with 8 additions and 5 deletions

View file

@ -6,6 +6,7 @@ pub trait Camera<R: Rng> {
fn height(&self) -> u32;
}
#[derive(Debug)]
pub struct BasicCamera {
width: u32,
height: u32,
@ -55,10 +56,11 @@ impl BasicCamera {
impl<R: Rng> Camera<R> for BasicCamera {
fn forward(&self, x: u32, y: u32, rng: &mut R) -> Ray {
// normalize x and y to -0.5 to 0.5
let x = ((x as Float + rng.gen::<Float>()) / (self.width as Float)) - 0.5;
let y = ((y as Float + rng.gen::<Float>()) / (self.height as Float)) - 0.5;
let dir = self.dir + x * self.h + y * self.v;
let x_float = ((x as Float + rng.gen::<Float>()) / (self.width as Float)) - 0.5;
let y_float = ((y as Float + rng.gen::<Float>()) / (self.height as Float)) - 0.5;
let dir = self.dir + x_float * self.h + y_float * self.v;
Ray::new(self.pos, dir.normalize(), 0.0)
}