1
0
Fork 0

Vector2D - rescaling fix - zero issue

This commit is contained in:
rxbn_ 2019-12-07 17:09:56 +01:00
parent 010cb5853a
commit 8af4e653b2
1 changed files with 4 additions and 2 deletions

View File

@ -86,7 +86,9 @@ public class Vector2D implements IVector2D {
public void rescale() {
// calc unit vector and set it
double vectorLength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2)); //using the square root of x and y
setDx((1 / vectorLength) * getDx() * Constants.BALL_SPEED);
setDy((1 / vectorLength) * getDy() * Constants.BALL_SPEED);
// rescaling only needed, if value is not zero
if(getDx() != 0) setDx((1 / vectorLength) * getDx() * Constants.BALL_SPEED);
if(getDy() != 0) setDy((1 / vectorLength) * getDy() * Constants.BALL_SPEED);
}
}