Skip to main content

inv_rotate_vector

Function inv_rotate_vector 

Source
pub fn inv_rotate_vector(q: Rot, v: Vec2) -> Vec2
Expand description

Inverse rotate a vector

Examples found in repository?
examples/benchmark/scenes/machines.rs (line 310)
258pub fn create_washer(world: &mut World) {
259    let kinematic = true;
260
261    {
262        let body_def = default_body_def();
263        // groundId is only used to anchor the (disabled) revolute joint branch.
264        let _ground_id = create_body(world, &body_def);
265    }
266
267    {
268        let motor_speed = 25.0;
269
270        let mut body_def = default_body_def();
271        body_def.position = to_pos(Vec2 { x: 0.0, y: 10.0 });
272
273        if kinematic {
274            body_def.type_ = BodyType::Kinematic;
275            body_def.angular_velocity = (PI / 180.0) * motor_speed;
276            body_def.linear_velocity = Vec2 {
277                x: 0.001,
278                y: -0.002,
279            };
280        } else {
281            body_def.type_ = BodyType::Dynamic;
282        }
283
284        let body_id = create_body(world, &body_def);
285
286        let shape_def = default_shape_def();
287
288        let r0 = 14.0;
289        let r1 = 16.0;
290        let r2 = 18.0;
291
292        let angle = PI / 18.0;
293        let q = Rot {
294            c: angle.cos(),
295            s: angle.sin(),
296        };
297        let qo = Rot {
298            c: (0.1 * angle).cos(),
299            s: (0.1 * angle).sin(),
300        };
301        let mut u1 = Vec2 { x: 1.0, y: 0.0 };
302        for i in 0..36 {
303            let u2 = if i == 35 {
304                Vec2 { x: 1.0, y: 0.0 }
305            } else {
306                rotate_vector(q, u1)
307            };
308
309            {
310                let a1 = inv_rotate_vector(qo, u1);
311                let a2 = rotate_vector(qo, u2);
312
313                let p1 = mul_sv(r1, a1);
314                let p2 = mul_sv(r2, a1);
315                let p3 = mul_sv(r1, a2);
316                let p4 = mul_sv(r2, a2);
317
318                let points = [p1, p2, p3, p4];
319                let hull = compute_hull(&points);
320
321                let polygon = make_polygon(&hull, 0.0);
322                create_polygon_shape(world, body_id, &shape_def, &polygon);
323            }
324
325            if i % 9 == 0 {
326                let p1 = mul_sv(r0, u1);
327                let p2 = mul_sv(r1, u1);
328                let p3 = mul_sv(r0, u2);
329                let p4 = mul_sv(r1, u2);
330
331                let points = [p1, p2, p3, p4];
332                let hull = compute_hull(&points);
333
334                let polygon = make_polygon(&hull, 0.0);
335                create_polygon_shape(world, body_id, &shape_def, &polygon);
336            }
337
338            u1 = u2;
339        }
340    }
341
342    let grid_count: i32 = if BENCHMARK_DEBUG { 20 } else { 90 };
343    let a = 0.1;
344
345    let polygon = make_square(a);
346    let mut body_def = default_body_def();
347    body_def.type_ = BodyType::Dynamic;
348    let mut shape_def = default_shape_def();
349    shape_def.enable_hit_events = true;
350
351    let mut y = -1.1 * a * grid_count as f32 + 10.0;
352    for _ in 0..grid_count {
353        let mut x = -1.1 * a * grid_count as f32;
354
355        for _ in 0..grid_count {
356            body_def.position = to_pos(Vec2 { x, y });
357            let body_id = create_body(world, &body_def);
358
359            create_polygon_shape(world, body_id, &shape_def, &polygon);
360
361            x += 2.1 * a;
362        }
363
364        y += 2.1 * a;
365    }
366}