Skip to content

Commit 73dc996

Browse files
committed
chapter_1
1 parent ff2a80d commit 73dc996

File tree

5 files changed

+448
-1
lines changed

5 files changed

+448
-1
lines changed

Cargo.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
float_eq = "0.7"

src/main.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
use crate::{
2+
math::{Point, Vector},
3+
sim::{Environment, Projectile, Simulator},
4+
};
5+
6+
mod math;
7+
mod sim;
8+
19
fn main() {
2-
println!("Hello, world!");
10+
println!("Canon ball initialization...\n");
11+
12+
let env = Environment {
13+
gravity: Vector::new(0., -0.1, 0.),
14+
wind: Vector::new(-0.01, 0., 0.),
15+
};
16+
let proj = Projectile {
17+
pos: Point::new(0., 1., 0.),
18+
v: Vector::new(1., 1., 0.).normalize(),
19+
};
20+
21+
let mut canon = Simulator::new(env, proj);
22+
23+
println!("Canon ball running...");
24+
25+
loop {
26+
let new_proj = canon.tick();
27+
println!("Still flying...");
28+
29+
if new_proj.pos.1 <= 0. {
30+
println!("Hit ground !!!");
31+
break;
32+
}
33+
}
334
}

0 commit comments

Comments
 (0)