Skip to content

Commit d68a1df

Browse files
authored
Merge pull request #177 from jCodingStuff/Julian
Splines fixed lol
2 parents c4b6ce7 + 1096b1c commit d68a1df

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public Computable getFunctionFor(float x, float y) {
124124
* @return the height at (x, y)
125125
*/
126126
public float getHeight(float x, float y) {
127+
if (this.isSpline() && (x < this.offsets[0] || y < this.offsets[1] || x > this.offsets[0] + Golf.VIRTUAL_WIDTH*this.scales[0] ||
128+
y > this.offsets[1] + Golf.VIRTUAL_HEIGHT*this.scales[1])) {
129+
return 0;
130+
}
131+
127132
if (this.isSpline()) {
128133
return this.getFunctionFor(x, y).getZ(x, y);
129134
} else {

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class BicubicInterpolator implements Computable {
1818
private float[][] coefficients;
1919

2020
private Point3D[][] points;
21-
private double x0;
22-
private double y0;
21+
private float x0;
22+
private float y0;
2323

2424
/**
2525
* Create a new Instance of BicubicInterpolator
@@ -35,27 +35,35 @@ public BicubicInterpolator(Point3D[][] points, float[][] dx, float[][] dy, float
3535

3636
fitter(dx, dy, dxy);
3737

38-
this.printInfo();
38+
this.printInfo(dx, dy, dxy);
3939

4040
}
4141

4242
/**
4343
* Print info about the instance of BicubicInterpolator
4444
*/
45-
private void printInfo() {
45+
private void printInfo(float[][] dx, float[][] dy, float[][] dxy) {
4646
System.out.println("Bicubic interpolator info:");
4747
System.out.println("\tPoints:");
4848
for (int x = 0; x < points.length; x++) {
4949
for (int y = 0; y < points[x].length; y++) {
5050
System.out.println("\t\t[" + x + ", " + y + "] -> " + this.points[x][y]);
5151
}
5252
}
53-
System.out.println("\tCoefficients:");
54-
for (int i = 0; i < this.coefficients.length; i++) {
53+
54+
this.printHelp("Coefficients", this.coefficients);
55+
this.printHelp("Dx", dx);
56+
this.printHelp("Dy", dy);
57+
this.printHelp("Dxy", dxy);
58+
}
59+
60+
private void printHelp(String text, float[][] matrix) {
61+
System.out.println("\t" + text + ":");
62+
for (int i = 0; i < matrix.length; i++) {
5563
System.out.print("\t\t[");
56-
for (int j = 0; j < this.coefficients[i].length; j++) {
57-
System.out.print(this.coefficients[i][j]);
58-
if (j != coefficients[i].length - 1) System.out.print(" ");
64+
for (int j = 0; j < matrix[i].length; j++) {
65+
System.out.print(matrix[i][j]);
66+
if (j != matrix[i].length - 1) System.out.print(" ");
5967
}
6068
System.out.println("]");
6169
}
@@ -103,7 +111,7 @@ private void fitter(float[][] dx, float[][] dy, float[][] dxy) {
103111
values[3][2] = dxy[1][0];
104112
values[3][3] = dxy[1][1];
105113

106-
float[][] res1 = MathLib.multiply(values, A);
114+
float[][] res1 = MathLib.multiply(A, values);
107115
this.coefficients = MathLib.multiply(res1, B);
108116
}
109117

core/src/com/group/golf/screens/CourseScreen.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ public CourseScreen(final Golf game, Course course, GameMode gameMode, GameMode
9090

9191
System.out.println("Offsets: [" + xoffset + ", " + yoffset + "]");
9292
System.out.println("Scales: [" + scaleX + ", " + scaleY + "]");
93-
this.course.setOffsets(new float[]{this.xoffset, this.yoffset});
94-
this.course.setScales(new float[]{this.scaleX, this.scaleY});
9593
this.activeMode.setOffsets(new float[]{this.xoffset, this.yoffset});
9694
this.activeMode.setScales(new float[]{this.scaleX, this.scaleY});
9795
}
@@ -196,8 +194,8 @@ private void splineSetup() {
196194
// Setup Offsets
197195
BicubicInterpolator botLeftInterp = (BicubicInterpolator) this.course.getFunctions()[0][0];
198196
Point3D[][] points = botLeftInterp.getPoints();
199-
this.setXoffset((float)points[0][0].getX());
200-
this.setYoffset((float)points[0][0].getY());
197+
this.setXoffset(points[0][0].getX());
198+
this.setYoffset(points[0][0].getY());
201199

202200
// Setup scales
203201
int xLength = this.course.getFunctions().length;
@@ -206,14 +204,17 @@ private void splineSetup() {
206204
// scaleX
207205
BicubicInterpolator botRightInterp = (BicubicInterpolator) this.course.getFunctions()[xLength - 1][0];
208206
Point3D[][] botRightPoints = botRightInterp.getPoints();
209-
double rightX = botRightPoints[1][0].getX();
210-
this.setScaleX((float)(rightX - this.getXoffset()) / Golf.VIRTUAL_WIDTH);
207+
float rightX = botRightPoints[1][0].getX();
208+
this.setScaleX((rightX - this.getXoffset())/ Golf.VIRTUAL_WIDTH);
211209

212210
// scaleY
213211
BicubicInterpolator topLeftInterp = (BicubicInterpolator) this.course.getFunctions()[0][yLength - 1];
214212
Point3D[][] topLeftPoints = topLeftInterp.getPoints();
215-
double topY = topLeftPoints[0][1].getY();
216-
this.setScaleY((float)(topY - this.getYoffset()) / Golf.VIRTUAL_HEIGHT);
213+
float topY = topLeftPoints[0][1].getY();
214+
this.setScaleY((topY - this.getYoffset()) / Golf.VIRTUAL_HEIGHT);
215+
216+
this.course.setOffsets(new float[]{this.xoffset, this.yoffset});
217+
this.course.setScales(new float[]{this.scaleX, this.scaleY});
217218
}
218219

219220
/**
@@ -368,6 +369,7 @@ public void calcScale() {
368369
limitDist *= 2;
369370
}
370371
this.scaleY = scaleX;
372+
this.course.setScales(new float[]{this.scaleX, this.scaleY});
371373
}
372374

373375
/**
@@ -382,6 +384,7 @@ public void calcOffsets() {
382384
float y2 = this.course.getGoal()[1];
383385
float yUnits = Golf.VIRTUAL_HEIGHT / (1/this.scaleY);
384386
this.yoffset = (y1 + y2 - yUnits) / 2.0f;
387+
this.course.setOffsets(new float[]{this.xoffset, this.yoffset});
385388
}
386389

387390
/**

0 commit comments

Comments
 (0)