Progress on pbrt parser

This commit is contained in:
hal8174 2025-07-31 22:54:53 +02:00
parent e16a916413
commit 16b9c32632
Signed by: hal8174
SSH key fingerprint: SHA256:JwuqS+eVfISfKr+DkDQ6NWAbGd1jFAHkPpCM1yCnlTs
2 changed files with 138 additions and 9 deletions

View file

@ -77,6 +77,27 @@ impl AffineTransform {
}
}
pub fn look_at(pos: Pos3, look: Pos3, up: Dir3) -> Self {
let dir = (look - pos).normalize();
let right = Dir3::cross(up.normalize(), dir).normalize();
let new_up = Dir3::cross(dir, right);
let mat = [
[right.x(), new_up.x(), dir.x(), pos.x()],
[right.y(), new_up.y(), dir.y(), pos.y()],
[right.z(), new_up.z(), dir.z(), pos.z()],
];
let inv = Self::invert(mat);
Self { mat, inv }
}
fn invert(mat: [[Float; 4]; 3]) -> [[Float; 3]; 3] {
eprintln!("Matrix inversion not implemented");
[[0.0; 3]; 3]
}
pub fn transform_pos(&self, pos: Pos3) -> Pos3 {
Pos3::new(
self.mat[0][0] * pos.x()
@ -93,6 +114,13 @@ impl AffineTransform {
+ self.mat[2][3],
)
}
pub fn transform_dir(&self, dir: Dir3) -> Dir3 {
Dir3::new(
self.mat[0][0] * dir.x() + self.mat[0][1] * dir.y() + self.mat[0][2] * dir.z(),
self.mat[1][0] * dir.x() + self.mat[1][1] * dir.y() + self.mat[1][2] * dir.z(),
self.mat[2][0] * dir.x() + self.mat[2][1] * dir.y() + self.mat[2][2] * dir.z(),
)
}
pub fn transform_normal(&self, pos: Pos3) -> Pos3 {
Pos3::new(
self.inv[0][0] * pos.x() + self.inv[0][1] * pos.y() + self.inv[0][2] * pos.z(),