Use camera settings from pbrt file
This commit is contained in:
parent
6403aabc11
commit
0a9748a1b7
4 changed files with 51 additions and 15 deletions
|
|
@ -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()],
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue