Guest User

Untitled

a guest
Feb 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. extern crate nalgebra as na;
  2. extern crate ncollide;
  3.  
  4. use na::{Isometry2, Point2, Vector2};
  5. use ncollide::shape::Cuboid;
  6. use ncollide::query::ContactPrediction;
  7. use ncollide::narrow_phase::{ContactDispatcher, DefaultContactDispatcher};
  8.  
  9. fn main() {
  10. let cuboid_a = Cuboid::new(Vector2::new(10.0, 10.0));
  11. let cuboid_b = Cuboid::new(Vector2::new(300.0, 1.5));
  12.  
  13. let pos_b = Isometry2::new(Vector2::new(5.0, 0.0), 1.5);
  14.  
  15. let dispatcher = DefaultContactDispatcher::<Point2<f32>, Isometry2<f32>>::new();
  16. let mut algorithm = dispatcher.get_contact_algorithm(&cuboid_a, &cuboid_b).unwrap();
  17.  
  18. let prediction = ContactPrediction::new(0.0, 0.0, 0.0);
  19.  
  20. let mut p = Vector2::new(0.0, 0.0);
  21. let mut angle = 0.0;
  22.  
  23. for i in 1..1000000 {
  24. p.x += 0.0001;
  25. angle += 0.005;
  26.  
  27. let pos_a = Isometry2::new(p, angle);
  28.  
  29. algorithm.update(&dispatcher, &pos_a, &cuboid_a, &pos_b, &cuboid_b, &prediction);
  30.  
  31. let mut contacts = Vec::new();
  32. algorithm.contacts(&mut contacts);
  33.  
  34. for contact in contacts.iter() {
  35. p -= contact.normal.unwrap() * contact.depth;
  36. }
  37.  
  38. //println!("{}", i);
  39. }
  40. }
Add Comment
Please, Sign In to add comment