Repository navigation
Expand file tree
/
Copy pathdebug_long_chain3.rs
More file actions
67 lines (56 loc) · 1.79 KB
/
Copy pathdebug_long_chain3.rs
File metadata and controls
67 lines (56 loc) · 1.79 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use rapier_testbed3d::TestbedViewer;
use rapier3d::prelude::*;
pub async fn run(viewer: &mut TestbedViewer) -> anyhow::Result<()> {
/*
* World
*/
let mut world = PhysicsWorld::new();
let use_articulations = true;
/*
* Create the long chain.
*/
let num = 85;
let rad = 0.2;
let shift = rad * 2.2;
let mut body_handles = Vec::new();
for i in 0..num {
let fi = i as f32;
let status = if i == 0 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
let rigid_body =
RigidBodyBuilder::new(status).translation(Vector::new(0.0, 0.0, fi * shift));
let collider = ColliderBuilder::ball(rad);
let (child_handle, _) = world.insert(rigid_body, collider);
// Vertical joint.
if i > 0 {
let parent_handle = *body_handles.last().unwrap();
let joint = if i == 1 {
SphericalJointBuilder::new().local_anchor2(Vector::new(0.0, 0.0, -shift))
} else {
SphericalJointBuilder::new()
.local_anchor1(Vector::new(0.0, 0.0, shift / 2.0))
.local_anchor2(Vector::new(0.0, 0.0, -shift / 2.0))
};
if use_articulations {
world.insert_multibody_joint(parent_handle, child_handle, joint);
} else {
world.insert_impulse_joint(parent_handle, child_handle, joint);
}
}
body_handles.push(child_handle);
}
/*
* Set up the testbed.
*/
viewer.set_world(&mut world);
viewer.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
while viewer.render_frame(&mut world).await {
if viewer.simulating() {
world.step();
}
}
Ok(())
}