Compare commits
3 Commits
trunk
...
camera-bui
| Author | SHA1 | Date | |
|---|---|---|---|
| 987bbe1c98 | |||
| f2d1a892b7 | |||
| 8e37fd8e97 |
@@ -5,6 +5,15 @@ edition = "2021"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# 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]
|
[dependencies]
|
||||||
rand = { version = "0.8.5", features = ["small_rng"] }
|
rand = { version = "0.8.5", features = ["small_rng"] }
|
||||||
itertools = { version = "0.11.0" }
|
itertools = { version = "0.11.0" }
|
||||||
|
eframe = "0.25.0"
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
|
#![warn(clippy::all, rust_2018_idioms, rust_2018_compatibility)]
|
||||||
mod primitives;
|
use rustpt::primitives::{
|
||||||
mod scene;
|
|
||||||
mod renderer;
|
|
||||||
|
|
||||||
use crate::primitives::{
|
|
||||||
Vec2i,
|
Vec2i,
|
||||||
Vec3,
|
Vec3,
|
||||||
};
|
};
|
||||||
use crate::scene::{
|
use rustpt::scene::{
|
||||||
Camera,
|
Camera,
|
||||||
Scene
|
Scene
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::renderer::{
|
use rustpt::renderer::{
|
||||||
Tile,
|
Tile,
|
||||||
RenderProperties,
|
RenderProperties,
|
||||||
};
|
};
|
||||||
36
src/gui_tool.rs
Normal file
36
src/gui_tool.rs
Normal 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
4
src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#![warn(clippy::all, rust_2018_idioms, rust_2018_compatibility)]
|
||||||
|
pub mod primitives;
|
||||||
|
pub mod scene;
|
||||||
|
pub mod renderer;
|
||||||
@@ -101,7 +101,7 @@ where T: std::ops::Div<Output = T>{
|
|||||||
|
|
||||||
impl <T> Display for Vec2<T>
|
impl <T> Display for Vec2<T>
|
||||||
where T: Display { // nested type still needs to have Display
|
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);
|
let str = format!("{} {}", self.x, self.y);
|
||||||
fmt.write_str(&str)
|
fmt.write_str(&str)
|
||||||
}
|
}
|
||||||
@@ -370,7 +370,7 @@ impl Neg for Vec3{
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Display 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);
|
let str = format!("{} {} {}", self.x, self.y, self.z);
|
||||||
fmt.write_str(&str)?;
|
fmt.write_str(&str)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
54
src/scene.rs
54
src/scene.rs
@@ -179,15 +179,37 @@ pub struct Camera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Camera {
|
impl Camera {
|
||||||
pub fn new(
|
pub fn new() -> Camera {
|
||||||
lookfrom: Vec3,
|
Self::default()
|
||||||
lookat: Vec3,
|
}
|
||||||
vup: Vec3,
|
|
||||||
vfov: f32,
|
pub fn get_ray(&self, s: f32, t: f32, srng: &mut SmallRng) -> Ray {
|
||||||
aspect_ratio: f32,
|
let rd = Vec3::rand_in_unit_disk(srng) * self.lens_radius;
|
||||||
aperture: f32,
|
let offset = self.u * rd.x + self.v * rd.y;
|
||||||
focus_dist: f32
|
|
||||||
) -> Camera {
|
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 theta = degrees_to_radians(vfov);
|
||||||
let h = (theta / 2.0).tan();
|
let h = (theta / 2.0).tan();
|
||||||
let vp_height = 2.0 * h;
|
let vp_height = 2.0 * h;
|
||||||
@@ -211,20 +233,6 @@ impl Camera {
|
|||||||
lens_radius: aperture / 2.0,
|
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user