Progress on pbrt parser
This commit is contained in:
parent
e16a916413
commit
16b9c32632
2 changed files with 138 additions and 9 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue