3 Commits

Author SHA1 Message Date
987bbe1c98 Starting builder pattern for Camera
I'm going to change the Camera construction to use the builder pattern.
This means I need to implement trait Default for Camera, and then a
bunch of functions for setting the properties.
2024-04-27 12:03:05 -05:00
f2d1a892b7 Enable more warnings, fix a couple of them
Yay for a high quality compiler
2024-04-27 11:16:31 -05:00
8e37fd8e97 Library & multiple binaries
Been playing with EGUI, and I'm gonna patch in a GUI app. The CLI
version will need to kick around, too, but be separate from the GUI one.
Enter: A multi-target crate!
2024-01-28 13:30:42 -06:00
6 changed files with 86 additions and 33 deletions

View File

@@ -5,6 +5,15 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "rustpt_cli"
path = "src/cli_tool.rs"
[[bin]]
name = "rustpt_gui"
path = "src/gui_tool.rs"
[dependencies]
rand = { version = "0.8.5", features = ["small_rng"] }
itertools = { version = "0.11.0" }
eframe = "0.25.0"

View File

@@ -1,18 +1,14 @@
mod primitives;
mod scene;
mod renderer;
use crate::primitives::{
#![warn(clippy::all, rust_2018_idioms, rust_2018_compatibility)]
use rustpt::primitives::{
Vec2i,
Vec3,
};
use crate::scene::{
use rustpt::scene::{
Camera,
Scene
};
use crate::renderer::{
use rustpt::renderer::{
Tile,
RenderProperties,
};

36
src/gui_tool.rs Normal file
View File

@@ -0,0 +1,36 @@
#![warn(clippy::all, rust_2018_idioms)]
use eframe::{egui, Frame};
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([800.0, 600.0])
.with_min_inner_size([50.0, 50.0])
.with_title("RustPT GUI Tool"),
..Default::default()
};
eframe::run_native(
"app name?",
options,
Box::new(
| cc | Box::new(RtApp::new(cc))
))
}
#[derive(Default)]
struct RtApp;
impl RtApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
Self::default()
}
}
impl eframe::App for RtApp {
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame) {
egui::SidePanel::left("Render Properties").show(ctx, |ui| {
ui.heading("Render Properties");
ui.label("")
});
}
}

4
src/lib.rs Normal file
View File

@@ -0,0 +1,4 @@
#![warn(clippy::all, rust_2018_idioms, rust_2018_compatibility)]
pub mod primitives;
pub mod scene;
pub mod renderer;

View File

@@ -101,7 +101,7 @@ where T: std::ops::Div<Output = T>{
impl <T> Display for Vec2<T>
where T: Display { // nested type still needs to have Display
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let str = format!("{} {}", self.x, self.y);
fmt.write_str(&str)
}
@@ -370,7 +370,7 @@ impl Neg for Vec3{
}
impl Display for Vec3 {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let str = format!("{} {} {}", self.x, self.y, self.z);
fmt.write_str(&str)?;
Ok(())

View File

@@ -179,15 +179,37 @@ pub struct Camera {
}
impl Camera {
pub fn new(
lookfrom: Vec3,
lookat: Vec3,
vup: Vec3,
vfov: f32,
aspect_ratio: f32,
aperture: f32,
focus_dist: f32
) -> Camera {
pub fn new() -> Camera {
Self::default()
}
pub fn get_ray(&self, s: f32, t: f32, srng: &mut SmallRng) -> Ray {
let rd = Vec3::rand_in_unit_disk(srng) * self.lens_radius;
let offset = self.u * rd.x + self.v * rd.y;
let dir = self.lower_left_corner
+ self.horizontal * s
+ self.vertical * t
- self.origin - offset;
Ray{
orig: self.origin + offset,
dir,
}
}
}
impl Default for Camera {
fn default() -> Self {
// defaults are the same as the hard-coded properties passed from main
// ... except for the `lookfrom` position: (13.0, 2.0, 3.0) became (10.0, 0..)
let lookfrom = Vec3::new(10.0, 0.0, 0.0);
let lookat = Vec3 { x: 1.0, y: 0.0, z: 0.0 };
let vup = Vec3::new(0.0, 1.0, 0.0);
let vfov = 20.0;
let aspect_ratio = 3.0 / 2.0;
let aperture = 0.1;
let focus_dist = 10.0;
let theta = degrees_to_radians(vfov);
let h = (theta / 2.0).tan();
let vp_height = 2.0 * h;
@@ -211,20 +233,6 @@ impl Camera {
lens_radius: aperture / 2.0,
}
}
pub fn get_ray(&self, s: f32, t: f32, srng: &mut SmallRng) -> Ray {
let rd = Vec3::rand_in_unit_disk(srng) * self.lens_radius;
let offset = self.u * rd.x + self.v * rd.y;
let dir = self.lower_left_corner
+ self.horizontal * s
+ self.vertical * t
- self.origin - offset;
Ray{
orig: self.origin + offset,
dir,
}
}
}