Skip to main content

default_body_def

Function default_body_def 

Source
pub fn default_body_def() -> BodyDef
Expand description

Initialize a body definition with the default values. (b2DefaultBodyDef)

Examples found in repository?
examples/demo_scenes.rs (line 11)
10fn add_static_box(world: &mut World, x: f32, y: f32, hx: f32, hy: f32) -> i32 {
11    let mut body_def = default_body_def();
12    body_def.position = m::to_pos(m::Vec2 { x, y });
13    let id = create_body(world, &body_def);
14    let def = default_shape_def();
15    let poly = make_box(hx, hy);
16    create_polygon_shape(world, id, &def, &poly);
17    get_body_full_id(world, id)
18}
19
20fn add_box(world: &mut World, x: f32, y: f32, hx: f32, hy: f32) -> i32 {
21    let mut body_def = default_body_def();
22    body_def.type_ = BodyType::Dynamic;
23    body_def.position = m::to_pos(m::Vec2 { x, y });
24    let id = create_body(world, &body_def);
25    let mut def = default_shape_def();
26    def.density = 1.0;
27    def.material.friction = 0.3;
28    let poly = make_box(hx, hy);
29    create_polygon_shape(world, id, &def, &poly);
30    get_body_full_id(world, id)
31}
32
33fn add_circle(world: &mut World, x: f32, y: f32, r: f32, density: f32) -> i32 {
34    let mut body_def = default_body_def();
35    body_def.type_ = BodyType::Dynamic;
36    body_def.position = m::to_pos(m::Vec2 { x, y });
37    let id = create_body(world, &body_def);
38    let mut def = default_shape_def();
39    def.density = density;
40    def.material.friction = 0.3;
41    def.material.restitution = 0.2;
42    let circle = box2d_rust::collision::Circle {
43        center: m::VEC2_ZERO,
44        radius: r,
45    };
46    create_circle_shape(world, id, &def, &circle);
47    get_body_full_id(world, id)
48}