Use camera settings from pbrt file

This commit is contained in:
hal8174 2025-09-12 21:58:58 +02:00
parent 6403aabc11
commit 0a9748a1b7
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
4 changed files with 51 additions and 15 deletions

View file

@ -40,6 +40,10 @@ impl AffineTransform {
Some(Self { mat, inv })
}
pub fn get(&self, i: usize, j: usize) -> Float {
self.mat[j][i]
}
pub fn identity() -> Self {
Self {
mat: [
@ -127,7 +131,7 @@ impl AffineTransform {
pub fn look_at(pos: Pos3, look: Pos3, up: Dir3) -> Option<Self> {
let dir = (look - pos).normalize();
let right = Dir3::cross(up.normalize(), dir).normalize();
let new_up = Dir3::cross(dir, right);
let new_up = Dir3::cross(right, dir);
let mat = [
[right.x(), new_up.x(), dir.x(), pos.x()],

View file

@ -1,4 +1,4 @@
use crate::prelude::*;
use crate::{affine_transform::AffineTransform, prelude::*};
pub trait Camera<R: Rng> {
fn forward(&self, x: u32, y: u32, rng: &mut R) -> Ray;
@ -41,6 +41,25 @@ impl BasicCamera {
}
}
pub fn from_affine_transform(
width: u32,
height: u32,
tm: AffineTransform,
horizontal_fov: Float,
) -> Self {
assert!(horizontal_fov < FloatConsts::PI);
let l = Float::sin(0.5 * horizontal_fov);
Self {
width,
height,
pos: Pos3::new(tm.get(3, 0), tm.get(3, 1), tm.get(3, 2)),
dir: Dir3::new(tm.get(2, 0), tm.get(2, 1), tm.get(2, 2)),
h: l * Dir3::new(tm.get(0, 0), tm.get(0, 1), tm.get(0, 2)),
v: l * Dir3::new(tm.get(1, 0), tm.get(1, 1), tm.get(1, 2)),
}
}
pub fn from_look_at(
width: u32,
height: u32,