This commit is contained in:
dqn 2025-08-01 02:21:49 +08:00
parent 4c851311aa
commit 4d513fb28d
2 changed files with 22 additions and 7 deletions

View File

@ -11,6 +11,26 @@ mod point;
mod ray;
fn main() {
gen_gradient_ppm();
println!("==================================");
ray_scene_render();
}
fn ray_scene_render() {
let aspect_ratio = 16.0/9.0;
let image_width = 400;
// aleast 1px
let image_height = ((image_width as f32 / aspect_ratio) as i32).max(1);
let viewport_height = 2.0;
let viewport_width = viewport_height * (image_width as f32 / image_height as f32);
println!("set image({},{}), viewport({},{})", image_width, image_height, viewport_width, viewport_height)
}
fn gen_gradient_ppm() {
let ppm_content = gen_gradient_ppm_p3(400, 225);
let v1 = Vec3::new(1.0, 1.0, 1.0);

View File

@ -1,5 +1,5 @@
use std::{fmt::Display, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}};
use std::{fmt::Display, ops::{Add, AddAssign, Div, Mul, MulAssign, Sub}};
use std::fmt;
/*
* [3]
@ -35,11 +35,6 @@ impl Vec3 {
z: self.x * other.y - self.y * other.x,
}
}
/// 向量长度
fn magnitude(self) -> f32 {
(self.x.powi(2) + self.y.powi(2) + self.z.powi(2)).sqrt()
}
}
impl Add for Vec3 {