Fixing aspect ratio and fov
This commit is contained in:
@@ -92,6 +92,9 @@ impl Camera {
|
||||
|
||||
let direction = view_direction + horizontal + vertical;
|
||||
let ray = Ray::new(self.eye, Unit::new_normalize(direction));
|
||||
if i == j {
|
||||
println!("{}", ray.b.into_inner());
|
||||
}
|
||||
rays.push(ray);
|
||||
}
|
||||
}
|
||||
|
||||
33
src/main.rs
33
src/main.rs
@@ -204,36 +204,56 @@ fn main() -> Result<(), Error> {
|
||||
let event_loop = EventLoop::new();
|
||||
//SCENE
|
||||
//Camera
|
||||
let eye = Point3::new(10.0, 10.0, 10.0);
|
||||
let eye = Point3::new(100.0, 100.0, 100.0);
|
||||
let target = Point3::new(0.0, 0.0, 0.0);
|
||||
let up = Vector3::new(0.0, 1.0, 0.0);
|
||||
let camera = Camera::new(
|
||||
eye,
|
||||
target,
|
||||
up,
|
||||
120.0,
|
||||
70.0,
|
||||
(START_WIDTH as f32 / START_HEIGHT as f32) as f32,
|
||||
);
|
||||
// SETUP PRIMITIVES
|
||||
let magenta = Arc::new(Material::magenta());
|
||||
let blue = Arc::new(Material::blue());
|
||||
let turquoise = Arc::new(Material::turquoise());
|
||||
let red = Arc::new(Material::red());
|
||||
// let sphere = Arc::new(Sphere::unit(magenta.clone()));
|
||||
// primitives.push(sphere.clone());
|
||||
// let cone = Arc::new(Cone::new(0.25, 1.0, -0.5, turquoise.clone()));
|
||||
// primitives.push(cone.clone());
|
||||
let mut primitives: Vec<Box<dyn Primitive>> = Vec::new();
|
||||
let cube = Box::new(Sphere::unit(blue.clone()));
|
||||
let cube = Box::new(Cube::unit(turquoise.clone()));
|
||||
let sphere = Box::new(Sphere::new(Point3::new(0.0, 4.0, 0.0), 1.0, red.clone()));
|
||||
let cone = Box::new(Circle::new(
|
||||
Point3::new(0.0, -3.0, 0.0),
|
||||
2.0,
|
||||
Vector3::new(0.0, 1.0, 0.0),
|
||||
magenta.clone(),
|
||||
));
|
||||
primitives.push(cube);
|
||||
primitives.push(sphere);
|
||||
primitives.push(cone);
|
||||
//Lights
|
||||
let light_pos = Point3::new(10.0, 12.0, 10.0);
|
||||
let light_colour = Vector3::new(1.0, 0.0, 1.0);
|
||||
let light_pos = Point3::new(0.0, 12.0, 4.0);
|
||||
let light_colour = Vector3::new(0.4, 0.4, 0.6);
|
||||
let light_falloff = [1.0, 0.00, 0.00];
|
||||
let light = Light::new(light_colour, light_pos, light_falloff);
|
||||
|
||||
let light_pos2 = Point3::new(10.0, 12.0, -4.0);
|
||||
let light_colour2 = Vector3::new(0.4, 0.0, 0.6);
|
||||
let light_falloff2 = [1.0, 0.00, 0.00];
|
||||
let light2 = Light::new(light_colour2, light_pos2, light_falloff2);
|
||||
|
||||
let ambient_light = Vector3::new(0.0, 0.0, 0.2);
|
||||
|
||||
let scene = Scene::new(primitives, vec![light], vec![camera.clone()], ambient_light);
|
||||
let scene = Scene::new(
|
||||
primitives,
|
||||
vec![light, light2],
|
||||
vec![camera.clone()],
|
||||
ambient_light,
|
||||
);
|
||||
//State
|
||||
let window = {
|
||||
let size = LogicalSize::new(START_WIDTH, START_HEIGHT);
|
||||
@@ -253,7 +273,6 @@ fn main() -> Result<(), Error> {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
return;
|
||||
}
|
||||
WindowEvent::Resized(size) => {
|
||||
state.resize(&size);
|
||||
|
||||
@@ -24,20 +24,20 @@ impl Material {
|
||||
Material { kd, ks, shininess }
|
||||
}
|
||||
pub fn turquoise() -> Self {
|
||||
let kd = Vector3::new(0.25, 1.0, 0.7);
|
||||
let ks = Vector3::new(0.25, 1.0, 0.7);
|
||||
let kd = Vector3::new(0.25, 0.3, 0.7);
|
||||
let ks = Vector3::new(0.25, 0.3, 0.7);
|
||||
let shininess = 0.5;
|
||||
Material { kd, ks, shininess }
|
||||
}
|
||||
pub fn red() -> Self {
|
||||
let kd = Vector3::new(1.0, 0.0, 0.0);
|
||||
let ks = Vector3::new(1.0, 0.0, 0.0);
|
||||
let kd = Vector3::new(0.8, 0.0, 0.3);
|
||||
let ks = Vector3::new(0.8, 0.3, 0.0);
|
||||
let shininess = 0.5;
|
||||
Material { kd, ks, shininess }
|
||||
}
|
||||
pub fn blue() -> Self {
|
||||
let kd = Vector3::new(0.0, 0.0, 1.0);
|
||||
let ks = Vector3::new(0.0, 0.0, 1.0);
|
||||
let kd = Vector3::new(0.0, 0.3, 0.6);
|
||||
let ks = Vector3::new(0.3, 0.0, 0.6);
|
||||
let shininess = 0.5;
|
||||
Material { kd, ks, shininess }
|
||||
}
|
||||
@@ -119,7 +119,7 @@ pub struct Sphere {
|
||||
}
|
||||
|
||||
impl Sphere {
|
||||
fn new(position: Point3<f32>, radius: f32, material: Arc<Material>) -> Self {
|
||||
pub fn new(position: Point3<f32>, radius: f32, material: Arc<Material>) -> Self {
|
||||
let radius_vec = Vector3::new(radius, radius, radius);
|
||||
let bln = position - radius_vec;
|
||||
let trf = position + radius_vec;
|
||||
@@ -186,7 +186,7 @@ impl Primitive for Sphere {
|
||||
}
|
||||
|
||||
// CIRCLE -----------------------------------------------------------------
|
||||
struct Circle {
|
||||
pub struct Circle {
|
||||
position: Point3<f32>,
|
||||
radius: f32,
|
||||
normal: Vector3<f32>,
|
||||
@@ -195,7 +195,7 @@ struct Circle {
|
||||
}
|
||||
|
||||
impl Circle {
|
||||
fn new(
|
||||
pub fn new(
|
||||
position: Point3<f32>,
|
||||
radius: f32,
|
||||
normal: Vector3<f32>,
|
||||
|
||||
@@ -12,6 +12,6 @@ impl Ray {
|
||||
Ray { a, b }
|
||||
}
|
||||
pub fn at_t(&self, t: f32) -> Point3<f32> {
|
||||
self.a + self.b.as_ref() * (t + EPSILON)
|
||||
self.a + self.b.into_inner() * (t + EPSILON)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user