Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/com/group/golf/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public Computable getFunctionFor(float x, float y) {
* @return the height at (x, y)
*/
public float getHeight(float x, float y) {
if (this.isSpline() && (x < this.offsets[0] || y < this.offsets[1] || x > this.offsets[0] + Golf.VIRTUAL_WIDTH*this.scales[0] ||
y > this.offsets[1] + Golf.VIRTUAL_HEIGHT*this.scales[1])) {
return 0;
}

if (this.isSpline()) {
return this.getFunctionFor(x, y).getZ(x, y);
} else {
Expand Down
28 changes: 18 additions & 10 deletions core/src/com/group/golf/math/BicubicInterpolator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class BicubicInterpolator implements Computable {
private float[][] coefficients;

private Point3D[][] points;
private double x0;
private double y0;
private float x0;
private float y0;

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

fitter(dx, dy, dxy);

this.printInfo();
this.printInfo(dx, dy, dxy);

}

/**
* Print info about the instance of BicubicInterpolator
*/
private void printInfo() {
private void printInfo(float[][] dx, float[][] dy, float[][] dxy) {
System.out.println("Bicubic interpolator info:");
System.out.println("\tPoints:");
for (int x = 0; x < points.length; x++) {
for (int y = 0; y < points[x].length; y++) {
System.out.println("\t\t[" + x + ", " + y + "] -> " + this.points[x][y]);
}
}
System.out.println("\tCoefficients:");
for (int i = 0; i < this.coefficients.length; i++) {

this.printHelp("Coefficients", this.coefficients);
this.printHelp("Dx", dx);
this.printHelp("Dy", dy);
this.printHelp("Dxy", dxy);
}

private void printHelp(String text, float[][] matrix) {
System.out.println("\t" + text + ":");
for (int i = 0; i < matrix.length; i++) {
System.out.print("\t\t[");
for (int j = 0; j < this.coefficients[i].length; j++) {
System.out.print(this.coefficients[i][j]);
if (j != coefficients[i].length - 1) System.out.print(" ");
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j]);
if (j != matrix[i].length - 1) System.out.print(" ");
}
System.out.println("]");
}
Expand Down Expand Up @@ -103,7 +111,7 @@ private void fitter(float[][] dx, float[][] dy, float[][] dxy) {
values[3][2] = dxy[1][0];
values[3][3] = dxy[1][1];

float[][] res1 = MathLib.multiply(values, A);
float[][] res1 = MathLib.multiply(A, values);
this.coefficients = MathLib.multiply(res1, B);
}

Expand Down
19 changes: 11 additions & 8 deletions core/src/com/group/golf/screens/CourseScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public CourseScreen(final Golf game, Course course, GameMode gameMode, GameMode

System.out.println("Offsets: [" + xoffset + ", " + yoffset + "]");
System.out.println("Scales: [" + scaleX + ", " + scaleY + "]");
this.course.setOffsets(new float[]{this.xoffset, this.yoffset});
this.course.setScales(new float[]{this.scaleX, this.scaleY});
this.activeMode.setOffsets(new float[]{this.xoffset, this.yoffset});
this.activeMode.setScales(new float[]{this.scaleX, this.scaleY});
}
Expand Down Expand Up @@ -196,8 +194,8 @@ private void splineSetup() {
// Setup Offsets
BicubicInterpolator botLeftInterp = (BicubicInterpolator) this.course.getFunctions()[0][0];
Point3D[][] points = botLeftInterp.getPoints();
this.setXoffset((float)points[0][0].getX());
this.setYoffset((float)points[0][0].getY());
this.setXoffset(points[0][0].getX());
this.setYoffset(points[0][0].getY());

// Setup scales
int xLength = this.course.getFunctions().length;
Expand All @@ -206,14 +204,17 @@ private void splineSetup() {
// scaleX
BicubicInterpolator botRightInterp = (BicubicInterpolator) this.course.getFunctions()[xLength - 1][0];
Point3D[][] botRightPoints = botRightInterp.getPoints();
double rightX = botRightPoints[1][0].getX();
this.setScaleX((float)(rightX - this.getXoffset()) / Golf.VIRTUAL_WIDTH);
float rightX = botRightPoints[1][0].getX();
this.setScaleX((rightX - this.getXoffset())/ Golf.VIRTUAL_WIDTH);

// scaleY
BicubicInterpolator topLeftInterp = (BicubicInterpolator) this.course.getFunctions()[0][yLength - 1];
Point3D[][] topLeftPoints = topLeftInterp.getPoints();
double topY = topLeftPoints[0][1].getY();
this.setScaleY((float)(topY - this.getYoffset()) / Golf.VIRTUAL_HEIGHT);
float topY = topLeftPoints[0][1].getY();
this.setScaleY((topY - this.getYoffset()) / Golf.VIRTUAL_HEIGHT);

this.course.setOffsets(new float[]{this.xoffset, this.yoffset});
this.course.setScales(new float[]{this.scaleX, this.scaleY});
}

/**
Expand Down Expand Up @@ -368,6 +369,7 @@ public void calcScale() {
limitDist *= 2;
}
this.scaleY = scaleX;
this.course.setScales(new float[]{this.scaleX, this.scaleY});
}

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

/**
Expand Down