Removed preCalc
This commit is contained in:
@ -4,7 +4,7 @@ import codedraw.CodeDraw;
|
||||
* This class represents celestial bodies like stars, planets, asteroids, etc...
|
||||
*/
|
||||
public class Body {
|
||||
private final double mass;
|
||||
private double mass;
|
||||
private Vector massCenter; // position of the mass center.
|
||||
private Vector currentMovement;
|
||||
|
||||
@ -83,6 +83,12 @@ public class Body {
|
||||
return massCenter;
|
||||
}
|
||||
|
||||
public void update(Body b) {
|
||||
double combinedMass = this.mass + b.mass;
|
||||
this.massCenter = this.massCenter.times(this.mass / combinedMass).plus(b.massCenter.times(b.mass / combinedMass));
|
||||
this.mass = combinedMass;
|
||||
}
|
||||
|
||||
public boolean collidesWith(Body body) {
|
||||
return this.distanceTo(body) < this.radius() + body.radius();
|
||||
}
|
||||
|
Reference in New Issue
Block a user