Add percent complete readout in terminal
This commit is contained in:
63
src/main.rs
63
src/main.rs
@@ -1,5 +1,4 @@
|
||||
use std::f32;
|
||||
//use std::ops::{Add,Mul};
|
||||
|
||||
mod camera;
|
||||
use crate::camera::PerspectiveCamera;
|
||||
@@ -23,27 +22,11 @@ use nalgebra::*;
|
||||
use bmp::Image;
|
||||
use bmp::Pixel;
|
||||
|
||||
fn main() {
|
||||
//let mut camera = OrthoCamera {
|
||||
// pos: Vec3::new(0.0, 0.0, -1000.0),
|
||||
// output_img: Image::new(2560,2560),
|
||||
// elements: Vec::new(),
|
||||
// lights: Vec::new(),
|
||||
// shadow_bias: 1e-3,
|
||||
// max_recursion_depth: 5
|
||||
//};
|
||||
let mut camera = PerspectiveCamera {
|
||||
pos: Vec3::new(1280.0, 1280.0, -1000.0),
|
||||
output_img: Image::new(2560,2560),
|
||||
elements: Vec::new(),
|
||||
lights: Vec::new(),
|
||||
shadow_bias: 1e-3,
|
||||
max_recursion_depth: 5,
|
||||
fov: 90.0,
|
||||
scene_width: 2560,
|
||||
scene_height: 2560,
|
||||
};
|
||||
use std::{thread,time};
|
||||
use std::io::{Write,stdout};
|
||||
use crossterm::{QueueableCommand,cursor,terminal,ExecutableCommand};
|
||||
|
||||
fn initialize_scene(camera: &mut PerspectiveCamera) {
|
||||
camera.lights.push(LightSrc::new(Vec3::new(200.0, 800.0, 300.0), 5.0));
|
||||
camera.lights.push(LightSrc::new(Vec3::new(1200.0, 800.0, 300.0), 5.0));
|
||||
|
||||
@@ -102,14 +85,48 @@ fn main() {
|
||||
};
|
||||
camera.elements.push(Element::Sphere(top_sphere));
|
||||
|
||||
println!("Raytracing ...");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut camera = PerspectiveCamera {
|
||||
pos: Vec3::new(1280.0, 1280.0, -1000.0),
|
||||
output_img: Image::new(2560,2560),
|
||||
elements: Vec::new(),
|
||||
lights: Vec::new(),
|
||||
shadow_bias: 1e-3,
|
||||
max_recursion_depth: 5,
|
||||
fov: 90.0,
|
||||
scene_width: 2560,
|
||||
scene_height: 2560,
|
||||
};
|
||||
|
||||
initialize_scene(&mut camera);
|
||||
|
||||
println!("Rusty Rays v1.0 Alpha\n");
|
||||
println!("Raytracing...\n");
|
||||
|
||||
let mut stdout = stdout();
|
||||
stdout.execute(cursor::Hide).unwrap();
|
||||
|
||||
stdout.write_all(format!("Progress: ").as_bytes()).unwrap();
|
||||
// TODO: Uncomment
|
||||
for (x, y) in camera.output_img.coordinates() {
|
||||
stdout.queue(cursor::SavePosition).unwrap();
|
||||
stdout.write_all(format!("{:.1}%", camera.percent_complete(y)).as_bytes()).unwrap();
|
||||
//stdout.write_all(format!("Raytracing.. {} : {}", x, y).as_bytes()).unwrap();
|
||||
stdout.queue(cursor::RestorePosition).unwrap();
|
||||
stdout.flush().unwrap();
|
||||
//thread::sleep(time::Duration::from_millis(100));
|
||||
|
||||
stdout.queue(cursor::RestorePosition).unwrap();
|
||||
stdout.queue(terminal::Clear(terminal::ClearType::FromCursorDown)).unwrap();
|
||||
camera.output_img.set_pixel(x, y, px!(20, 20, 20));
|
||||
//let prime_ray = Ray::new(Vec3::new(x as f64, y as f64, camera.pos.z as f64), Vec3::new(0.0, 0.0, 1.0));
|
||||
let prime_ray = camera.create_prime(x, y);
|
||||
let pixel = cast_ray(&camera, &prime_ray, 0);
|
||||
camera.output_img.set_pixel(x, y, px!(pixel.red, pixel.green, pixel.blue));
|
||||
}
|
||||
stdout.queue(cursor::RestorePosition).unwrap();
|
||||
println!("Render complete! 🎉");
|
||||
|
||||
let _ = camera.output_img.save("img.bmp");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user