Replace xy float[] arrays with Vec2f (mostly in game objects).

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-09-05 12:53:42 -05:00
parent 1b8f85942f
commit 01fb9c50c9
12 changed files with 114 additions and 117 deletions

View File

@@ -115,10 +115,8 @@ public class CircumscribedCircle extends Curve {
// calculate points
float step = hitObject.getPixelLength() / CURVE_POINTS_SEPERATION;
curve = new Vec2f[(int) step + 1];
for (int i = 0; i < curve.length; i++) {
float[] xy = pointAt(i / step);
curve[i] = new Vec2f(xy[0], xy[1]);
}
for (int i = 0; i < curve.length; i++)
curve[i] = pointAt(i / step);
}
/**
@@ -157,12 +155,12 @@ public class CircumscribedCircle extends Curve {
}
@Override
public float[] pointAt(float t) {
public Vec2f pointAt(float t) {
float ang = Utils.lerp(startAng, endAng, t);
return new float[] {
return new Vec2f(
(float) (Math.cos(ang) * radius + circleCenter.x),
(float) (Math.sin(ang) * radius + circleCenter.y)
};
);
}
@Override

View File

@@ -106,9 +106,9 @@ public abstract class Curve {
/**
* Returns the point on the curve at a value t.
* @param t the t value [0, 1]
* @return the point [x, y]
* @return the position vector
*/
public abstract float[] pointAt(float t);
public abstract Vec2f pointAt(float t);
/**
* Draws the full curve to the graphics context.

View File

@@ -124,20 +124,19 @@ public abstract class EqualDistanceMultiCurve extends Curve {
}
@Override
public float[] pointAt(float t) {
public Vec2f pointAt(float t) {
float indexF = t * ncurve;
int index = (int) indexF;
if (index >= ncurve) {
Vec2f poi = curve[ncurve];
return new float[] { poi.x, poi.y };
} else {
if (index >= ncurve)
return curve[ncurve].cpy();
else {
Vec2f poi = curve[index];
Vec2f poi2 = curve[index + 1];
float t2 = indexF - index;
return new float[] {
return new Vec2f(
Utils.lerp(poi.x, poi2.x, t2),
Utils.lerp(poi.y, poi2.y, t2)
};
);
}
}

View File

@@ -40,6 +40,16 @@ public class Vec2f {
*/
public Vec2f() {}
/**
* Sets the x and y components of this vector.
* @return itself (for chaining)
*/
public Vec2f set(float nx, float ny) {
x = nx;
y = ny;
return this;
}
/**
* Finds the midpoint between this vector and another vector.
* @param o the other vector