/* 3D Renderer Copyright (C) 2017 Davis Remmel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ use std::time::Duration; use std::thread; mod ddd; fn main() { // Create the screen let mut camera = ddd::rig::Camera { sensor: ddd::rig::Sensor::new(320, 240, 16.0, 12.0), focal_point: ddd::Point::new(0.0, 0.0, -7.0), sensor_distance_z: 10.0 }; let mut test_shape_2 = ddd::space::Shape { faces: vec![ vec![ ddd::Point::new(-1.0, 1.0, -1.0), ddd::Point::new( 1.0, 1.0, -1.0), ddd::Point::new( 1.0, 1.0, 1.0), ddd::Point::new(-1.0, 1.0, 1.0) ], vec![ ddd::Point::new(-1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, 1.0), ddd::Point::new(-1.0, -1.0, 1.0) ], vec![ ddd::Point::new( 1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, 1.0), ddd::Point::new( 1.0, 1.0, 1.0), ddd::Point::new( 1.0, 1.0, -1.0) ], vec![ ddd::Point::new(-1.0, -1.0, -1.0), ddd::Point::new(-1.0, -1.0, 1.0), ddd::Point::new(-1.0, 1.0, 1.0), ddd::Point::new(-1.0, 1.0, -1.0) ], vec![ ddd::Point::new(-1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, -1.0), ddd::Point::new( 1.0, 1.0, -1.0), ddd::Point::new(-1.0, 1.0, -1.0) ], vec![ ddd::Point::new(-1.0, -1.0, 1.0), ddd::Point::new( 1.0, -1.0, 1.0), ddd::Point::new( 1.0, 1.0, 1.0), ddd::Point::new(-1.0, 1.0, 1.0) ] ], rotation: ddd::Rotation::new(0.0, 0.0, 0.0), translation: ddd::Translation::new(0.0, 0.0, 0.0) }; let mut test_shape_3 = ddd::space::Shape { faces: vec![ vec![ ddd::Point::new(-1.0, 1.0, -1.0), ddd::Point::new( 1.0, 1.0, -1.0), ddd::Point::new( 1.0, 1.0, 1.0), ddd::Point::new(-1.0, 1.0, 1.0) ], vec![ ddd::Point::new(-1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, 1.0), ddd::Point::new(-1.0, -1.0, 1.0) ], vec![ ddd::Point::new( 1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, 1.0), ddd::Point::new( 1.0, 1.0, 1.0), ddd::Point::new( 1.0, 1.0, -1.0) ], vec![ ddd::Point::new(-1.0, -1.0, -1.0), ddd::Point::new(-1.0, -1.0, 1.0), ddd::Point::new(-1.0, 1.0, 1.0), ddd::Point::new(-1.0, 1.0, -1.0) ], vec![ ddd::Point::new(-1.0, -1.0, -1.0), ddd::Point::new( 1.0, -1.0, -1.0), ddd::Point::new( 1.0, 1.0, -1.0), ddd::Point::new(-1.0, 1.0, -1.0) ], vec![ ddd::Point::new(-1.0, -1.0, 1.0), ddd::Point::new( 1.0, -1.0, 1.0), ddd::Point::new( 1.0, 1.0, 1.0), ddd::Point::new(-1.0, 1.0, 1.0) ] ], rotation: ddd::Rotation::new(0.0, 0.0, 0.0), translation: ddd::Translation::new(0.0, 0.0, 0.0) }; test_shape_2.translate_rel(ddd::Translation::new(-2.0, 0.0, 0.0)); test_shape_3.translate_rel(ddd::Translation::new(2.0, 0.0, 0.0)); loop { test_shape_2.rotate_rel(ddd::Rotation::new(0.00, 0.02, 0.02)); test_shape_3.rotate_rel(ddd::Rotation::new(-0.02, -0.02, 0.00)); camera.rasterize_faces(test_shape_2.apply_face_transformations()); camera.rasterize_faces(test_shape_3.apply_face_transformations()); camera.sensor.read_out(); thread::sleep(Duration::from_millis(1000 / 60)); // thread::sleep(Duration::from_millis(2000)); } }