aboutsummaryrefslogtreecommitdiff
path: root/examples3d/damping3.rs
blob: 992afbede6ba258fed8ef8a3c9f6110e69bb3d55 (plain)
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
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;

pub fn init_world(testbed: &mut Testbed) {
    /*
     * World
     */
    let mut bodies = RigidBodySet::new();
    let mut colliders = ColliderSet::new();
    let impulse_joints = ImpulseJointSet::new();
    let multibody_joints = MultibodyJointSet::new();

    /*
     * Create the cubes
     */
    let num = 10;
    let rad = 0.2;

    let subdiv = 1.0 / (num as f32);

    for i in 0usize..num {
        let (x, y) = (i as f32 * subdiv * std::f32::consts::PI * 2.0).sin_cos();

        // Build the rigid body.
        let rb = RigidBodyBuilder::dynamic()
            .translation(vector![x, y, 0.0])
            .linvel(vector![x * 10.0, y * 10.0, 0.0])
            .angvel(Vector::z() * 100.0)
            .linear_damping((i + 1) as f32 * subdiv * 10.0)
            .angular_damping((num - i) as f32 * subdiv * 10.0);
        let rb_handle = bodies.insert(rb);

        // Build the collider.
        let co = ColliderBuilder::cuboid(rad, rad, rad);
        colliders.insert_with_parent(co, rb_handle, &mut bodies);
    }

    /*
     * Set up the testbed.
     */
    testbed.set_world_with_params(
        bodies,
        colliders,
        impulse_joints,
        multibody_joints,
        Vector::zeros(),
        (),
    );
    testbed.look_at(point![2.0, 2.5, 20.0], point![2.0, 2.5, 0.0]);
}