Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. t_min := +∞
  2. t_max := -∞
  3. foreach axis in potential_separating_axes
  4. a_min := +∞
  5. a_max := -∞
  6. foreach vertex in a.vertices
  7. a_min = min(a_min, vertex · axis)
  8. a_max = max(a_max, vertex · axis)
  9. b_min := +∞
  10. b_max := -∞
  11. foreach vertex in b.vertices
  12. b_min = min(b_min, vertex · axis)
  13. b_max = max(b_max, vertex · axis)
  14. v := b.velocity · axis
  15. if v > 0 then
  16. if a_max < b_min then
  17. return no_intersection
  18. else if (a_min < b_min < a_max) or (b_min < a_min < b_max) then
  19. t_min = min(t_min, (a_max - b_min) / v)
  20. t_max = max(t_max, 0)
  21. else
  22. t_min = min(t_min, (a_max - b_min) / v)
  23. t_max = max(t_max, (a_min - b_max) / v)
  24. else if v < 0 then
  25. // repeat the above case with a and b swapped
  26. else if v = 0 then
  27. if a_min < b_max and b_min < a_max then
  28. t_min = min(t_min, 0)
  29. t_max = max(t_max, 0)
  30. else
  31. return no_intersection
  32. if t_max < t_min then
  33. // advance b by b.velocity * t_max
  34. return intersection
  35. else
  36. return no_intersection
  37.  
  38. vec3 vertex;
  39. float mindot = FLT_MAX;
  40. for ( vert : vertices )
  41. {
  42. if (dot(vert, MTV) < mindot)
  43. {
  44. mindot = dot(vert, MTV);
  45. vertex = vert;
  46. }
  47. }
  48.  
  49. halfstep = 1.0f;
  50. vec3 cp = vertex;
  51. vec3 v = A.velocity*framedurationSeconds;
  52. float errorThreshold = 0.01f; //choose meaningful value here
  53. while (abs(dot(cp,normal)) > errorThreshold)
  54. {
  55. v*=-1*(halfstep*0.5f);
  56. cp += v;
  57. }
  58.  
  59. return cp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement