1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use rusting_engine::{CollisionType, Engine, Material, Physics, Transform};
/// # Physics Gravity & Collision Example
/// This example demonstrates how hundreds of instanced objects can dynamically interact
/// via compute shader acceleration without taxing the CPU.
pub fn main() {
let mut engine = Engine::new("RustingEngine - Physics Demo");
engine.set_light([30.0, 30.0, 30.0], [1.0, 0.95, 0.9], 450.0);
let red = Material::standard().color([1.0, 0.0, 0.0]).build();
let green = Material::standard().color([0.0, 1.0, 0.0]).build();
// Generate a massive multi-layered block pile
for i in 0..10 {
for j in 0..3 {
for k in 0..10 {
let pos =
[i as f32 * 1.5, j as f32 * 2.0 + 7.0, k as f32 * 1.5];
engine.add_cube(
Transform {
position: pos,
..Default::default()
},
&red,
&Physics::default()
.collision_type(CollisionType::Box)
.gravity_scale(0.0), // Starts with zero gravity
);
}
}
}
// Add an enormous heavy boulder falling from the sky to crash into the blocks!
engine.add_sphere(
Transform {
position: [7.0, 100.0, 7.0],
scale: [7.5, 7.5, 7.5],
..Default::default()
},
&green,
&Physics::default()
.mass(100000.0) // Very heavy
.collision_type(CollisionType::Sphere),
2,
);
// Call run to begin simulation!
engine.run();
}