refactor: rename types.rs to util.rs
This commit is contained in:
parent
763a4ff923
commit
f33ee09b9d
10 changed files with 32 additions and 27 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
40
src/main.rs
40
src/main.rs
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue