Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. void krockEffekt(Ball otherball) {
  2. distance = Math.pow(position.x - otherball.position.x, 2) - Math.pow(position.y - otherball.position.y, 2);
  3. dx = position.x - otherball.position.x / distance;
  4. dy = position.y - otherball.position.y / distance;
  5. Coord d = new Coord(dx,dy);
  6. Coord normD = d.norm();
  7.  
  8.  
  9. impuls=Coord.scal(velocity,normD) - Coord.scal(otherball.velocity,normD);
  10.  
  11. double New_velocityX1 = velocity.x - impuls*normD.x;
  12. double New_velocityY1 = velocity.y - impuls*normD.y;
  13. double New_velocityX2 = otherball.velocity.x + impuls*normD.x;
  14. double New_velocityY2 = otherball.velocity.y + impuls*normD.y;
  15.  
  16. velocity = new Coord(New_velocityX1,New_velocityY1);
  17. otherball.velocity = new Coord(New_velocityX2,New_velocityY2);
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement