pub fn world_set_gravity(world: &mut World, gravity: Vec2)Expand description
Set the gravity vector for the entire world. Box2D has no concept of an up direction and this is left as a decision for the application. (b2World_SetGravity)
Examples found in repository?
examples/benchmark/scenes/machines.rs (line 153)
152pub fn create_smash(world: &mut World) {
153 world_set_gravity(world, VEC2_ZERO);
154
155 {
156 let box_shape = make_box(4.0, 4.0);
157
158 let mut body_def = default_body_def();
159 body_def.type_ = BodyType::Dynamic;
160 body_def.position = to_pos(Vec2 { x: -20.0, y: 0.0 });
161 body_def.linear_velocity = Vec2 { x: 40.0, y: 0.0 };
162 let body_id = create_body(world, &body_def);
163
164 let mut shape_def = default_shape_def();
165 shape_def.density = 8.0;
166 create_polygon_shape(world, body_id, &shape_def, &box_shape);
167 }
168
169 let d = 0.4;
170 let box_shape = make_square(0.5 * d);
171
172 let mut body_def = default_body_def();
173 body_def.type_ = BodyType::Dynamic;
174 body_def.is_awake = false;
175
176 let shape_def = default_shape_def();
177
178 let columns: i32 = if BENCHMARK_DEBUG { 20 } else { 120 };
179 let rows: i32 = if BENCHMARK_DEBUG { 10 } else { 80 };
180
181 for i in 0..columns {
182 for j in 0..rows {
183 body_def.position = to_pos(Vec2 {
184 x: i as f32 * d + 30.0,
185 y: (j as f32 - rows as f32 / 2.0) * d,
186 });
187 let body_id = create_body(world, &body_def);
188 create_polygon_shape(world, body_id, &shape_def, &box_shape);
189 }
190 }
191}