refactor: rename types.rs to util.rs

This commit is contained in:
Kiana Sheibani 2024-10-14 18:11:19 -04:00
parent 763a4ff923
commit f33ee09b9d
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
10 changed files with 32 additions and 27 deletions

View file

@ -3,7 +3,7 @@ extern crate nalgebra as na;
use na::geometry::{Point2, Point3};
use na::*;
use crate::types::Ray;
use crate::util::Ray;
#[derive(Debug)]
pub struct Camera {

View file

@ -1,18 +1,22 @@
extern crate nalgebra as na;
use std::time::Instant;
use std::fs::File;
use std::io::Write;
use std::time::Instant;
use na::*;
mod camera; use camera::*;
mod types; use types::*;
mod object; use object::*;
mod render; use render::*;
mod camera;
use camera::*;
mod util;
use util::*;
mod object;
use object::*;
mod render;
use render::*;
fn render(camera: &Camera, scene: &Scene, filename: &str) -> std::io::Result<()> {
let width = camera.image_size.x;
let width = camera.image_size.x;
let height = camera.image_size.y;
let mut buffer: Vec<Color> = Vec::with_capacity((width * height) as usize);
@ -35,18 +39,22 @@ fn render(camera: &Camera, scene: &Scene, filename: &str) -> std::io::Result<()>
}
fn main() -> std::io::Result<()> {
let camera = Camera::new(Point3::new(0.0,5.0,0.0), Vector3::new(0.0,-1.0,0.0), 1.0, 16.0 / 9.0, 2.0, 720);
let camera = Camera::new(
Point3::new(0.0, 5.0, 0.0),
Vector3::new(0.0, -1.0, 0.0),
1.0,
16.0 / 9.0,
2.0,
720,
);
let scene = Scene {
objects: vec![
Object::new(Plane::xz(|_, _| Texture { color: Color::white(), albedo: 0.8 })),
],
lights: vec![
],
background: Color::gray(0.5)
objects: vec![Object::new(Plane::xz(|_, _| Texture {
color: Color::white(),
albedo: 0.8,
}))],
lights: vec![],
background: Color::gray(0.5),
};
let before = Instant::now();

View file

@ -9,7 +9,7 @@ pub use bound::*;
mod point_light;
pub use point_light::*;
use crate::types::*;
use crate::util::*;
// A trait for types that can be in Objects.
pub trait Surface {

View file

@ -3,7 +3,7 @@ extern crate nalgebra as na;
// use na::distance;
use na::geometry::Point3;
use crate::types::*;
use crate::util::*;
// A bounding sphere, used for
// intersection test optimization.

View file

@ -4,7 +4,7 @@ use na::geometry::Point3;
use na::*;
use super::{bound::*, Surface};
use crate::types::*;
use crate::util::*;
pub struct Plane {
pub center: Point3f, // Plane origin (used for texture mapping).

View file

@ -3,7 +3,7 @@ extern crate nalgebra as na;
use na::*;
use super::*;
use crate::types::*;
use crate::util::*;
pub struct PointLight {
pub pos: Point3f,

View file

@ -6,7 +6,7 @@ use na::geometry::Point3;
use na::*;
use super::{bound::*, Surface};
use crate::types::*;
use crate::util::*;
pub struct Sphere {
pub center: Point3f, // Center point of the sphere.

View file

@ -6,7 +6,7 @@ use na::geometry::Point3;
use na::*;
use super::{bound::*, Surface};
use crate::types::*;
use crate::util::*;
pub struct Triangle {
pub v1: usize, // Handles to 3 vertices.

View file

@ -3,11 +3,8 @@ extern crate nalgebra as na;
use std::cmp::Ordering;
use std::f64::consts::PI;
use na::geometry::Point3;
use na::*;
use crate::object::*;
use crate::types::*;
use crate::util::*;
fn trace(ray: Ray, objects: &Vec<Object>) -> Option<(&Object, f64)> {
objects