Compare commits
2 Commits
1a414bc485
...
1e57661ace
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e57661ace | ||
|
|
ed3773a299 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
target
|
target
|
||||||
rusty-tags.vi
|
rusty-tags.vi
|
||||||
out.ppm
|
*.ppm
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ impl Tuple {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn point_zero() -> Tuple {
|
||||||
|
Tuple {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
z: 0.0,
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn point(x: f32, y: f32, z: f32) -> Tuple {
|
pub fn point(x: f32, y: f32, z: f32) -> Tuple {
|
||||||
Tuple {
|
Tuple {
|
||||||
|
|||||||
80
src/main.rs
80
src/main.rs
@@ -3,6 +3,7 @@ use features::color::Color;
|
|||||||
use features::structs::Tuple;
|
use features::structs::Tuple;
|
||||||
use features::matrix::Matrix;
|
use features::matrix::Matrix;
|
||||||
|
|
||||||
|
use std::f32::consts::PI;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@@ -57,7 +58,23 @@ fn init_env() -> Environment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn write_canvas_to_file(canvas: Canvas, file_path: &str) {
|
||||||
|
let ppm = canvas.to_ppm();
|
||||||
|
|
||||||
|
let mut f = match File::create(file_path) {
|
||||||
|
Ok(f) => f,
|
||||||
|
Err(e) => panic!("file error. {}", e),
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = match f.write_all(ppm.as_bytes()) {
|
||||||
|
Ok(w) => w,
|
||||||
|
Err(e) => panic!("did not write. {}", e),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn before_clock() {
|
||||||
let env = init_env();
|
let env = init_env();
|
||||||
|
|
||||||
let mut ball = Projectile::new(
|
let mut ball = Projectile::new(
|
||||||
@@ -95,19 +112,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ppm = canvas.to_ppm();
|
write_canvas_to_file(canvas, "out.ppm");
|
||||||
|
|
||||||
let mut f = match File::create("out.ppm") {
|
|
||||||
Ok(f) => f,
|
|
||||||
Err(e) => panic!("file error. {}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = match f.write_all(ppm.as_bytes()) {
|
|
||||||
Ok(w) => w,
|
|
||||||
Err(e) => panic!("did not write. {}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
let i = Matrix::identity(4);
|
let i = Matrix::identity(4);
|
||||||
println!("The identity matrix is: {:#?}", i);
|
println!("The identity matrix is: {:#?}", i);
|
||||||
let inverse_i = i.inverse();
|
let inverse_i = i.inverse();
|
||||||
@@ -140,3 +145,50 @@ fn main() {
|
|||||||
println!("{:?}", id);
|
println!("{:?}", id);
|
||||||
println!("{:?}", q);
|
println!("{:?}", q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
before_clock();
|
||||||
|
clock();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clock() {
|
||||||
|
println!("Starting clock!");
|
||||||
|
|
||||||
|
let mut canvas = Canvas::new(1024, 1024);
|
||||||
|
let color = Color::new(1.0, 0.0, 0.0);
|
||||||
|
let middle = 1024.0 / 2.0;
|
||||||
|
let three_fourths_middle = middle / 4.0 * 3.0;
|
||||||
|
let center = &Tuple::point_zero() * &Matrix::translation(0.0, 1.0, 0.0);
|
||||||
|
// canvas.write_pixel(center.x() as usize, center.y() as usize, color);
|
||||||
|
canvas.write_pixel(middle as usize, middle as usize, Color::new(0.0, 1.0, 0.0));
|
||||||
|
|
||||||
|
for i in 1..13 {
|
||||||
|
let twelve = Tuple::point_zero();
|
||||||
|
|
||||||
|
let twelve = &Matrix::translation(0.0, -12.0, 0.0) * &twelve;
|
||||||
|
let twelve = &Matrix::scaling(0.0, 10.0, 0.0) * &twelve;
|
||||||
|
let twelve = &Matrix::rotation_z((i as f32 / 12.0) * (2.0 * PI)) * &twelve;
|
||||||
|
let twelve = &Matrix::translation(middle, middle, 0.0) * &twelve;
|
||||||
|
println!("{}", twelve);
|
||||||
|
|
||||||
|
canvas.write_pixel(twelve.x() as usize, twelve.y() as usize, color);
|
||||||
|
|
||||||
|
}
|
||||||
|
//for i in 0..=-1 {
|
||||||
|
// let position = ((2.0 * PI) / 12.0) * (i as f32);
|
||||||
|
// println!("i: {} pos: {}", i, position);
|
||||||
|
// let transform = &(&(&Matrix::identity(4)
|
||||||
|
// * &Matrix::translation(0.0, 1.0 , 0.0))
|
||||||
|
// * &Matrix::rotation_z(position))
|
||||||
|
// //* &Matrix::identity(4))
|
||||||
|
// * &Matrix::translation(middle, middle, 0.0);
|
||||||
|
// let point = &Tuple::point_zero() * &(&transform * &Matrix::scaling(three_fourths_middle, three_fourths_middle, 0.0));
|
||||||
|
// //let point = &Tuple::point_zero() * &(&Matrix::translation(i as f32 * 6.0, 0.0, 0.0) * &Matrix::translation(middle, middle, 0.0));
|
||||||
|
// println!("point rotated: {}", &point);
|
||||||
|
// canvas.write_pixel(point.x() as usize, point.y() as usize, color);
|
||||||
|
|
||||||
|
//}
|
||||||
|
write_canvas_to_file(canvas, "clock.ppm");
|
||||||
|
|
||||||
|
println!("Ending clock!");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user