Skip to content

Commit 59ecad1

Browse files
authored
Merge pull request #178 from jCodingStuff/Julian
Julian
2 parents 6ca326d + a9cd158 commit 59ecad1

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

core/src/com/group/golf/Ball.java

+14
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ public void reset() {
7373
this.velocityY = 0;
7474
}
7575

76+
/**
77+
* Reset the velocityX of the ball to 0
78+
*/
79+
public void resetX() {
80+
this.velocityX = 0;
81+
}
82+
83+
/**
84+
* Reset the velocityY of the ball to 0
85+
*/
86+
public void resetY() {
87+
this.velocityY = 0;
88+
}
89+
7690
/**
7791
* Limit the velocity to a maximum
7892
* @param max the limit

core/src/com/group/golf/Physics/Physics.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,20 @@ public boolean checkCollision(boolean simulation) {
117117
* @return true if the ball was forced to stop, false otherwise
118118
*/
119119
protected boolean checkLowVelocity() {
120-
// System.out.println("ErrorBound: " + errorBound);
121-
if (Math.abs(movingBall.calcVelocity()) < errorBound) {
122-
movingBall.reset();
123-
return true;
120+
float[] slope = this.calculateSlope(new float[]{this.movingBall.getX(), this.movingBall.getY()});
121+
float vx = this.movingBall.getVelocityX();
122+
float vy = this.movingBall.getVelocityY();
123+
if (vx != 0 && ((vx < 0 && slope[0] >= 0 && vx >= -errorBound) ||
124+
(vx > 0 && slope[0] <= 0 && vx <= errorBound))) {
125+
// System.out.println("VelocityX reset!");
126+
this.movingBall.resetX();
124127
}
125-
return false;
128+
if (vy != 0 && ((vy < 0 && slope[1] >= 0 && vy >= -errorBound) ||
129+
(vy > 0 && slope[1] <= 0 && vy <= errorBound))) {
130+
// System.out.println("VelocityY reset!");
131+
this.movingBall.resetY();
132+
}
133+
return !this.movingBall.isMoving();
126134
}
127135

128136
/**

core/src/com/group/golf/Physics/RK4.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class RK4 extends Physics {
1818
*/
1919
public RK4(Course course) {
2020
super(course);
21-
errorBound = 0.15f;
21+
errorBound = 0.2f;
2222
}
2323

2424
//method to be overwritten by each subclass

core/src/com/group/golf/math/BicubicInterpolator.java

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ private void printInfo(float[][] dx, float[][] dy, float[][] dxy) {
5757
this.printHelp("Dxy", dxy);
5858
}
5959

60+
/**
61+
* Print a matrix
62+
* @param text the title of the matrix
63+
* @param matrix the matrix
64+
*/
6065
private void printHelp(String text, float[][] matrix) {
6166
System.out.println("\t" + text + ":");
6267
for (int i = 0; i < matrix.length; i++) {

0 commit comments

Comments
 (0)