ArcFactory works with one Arc

This commit is contained in:
Awlex 2016-11-20 00:04:56 +01:00
parent a671f9dba2
commit 5a5c13f64c
4 changed files with 38 additions and 61 deletions

View File

@ -4,7 +4,6 @@ import Jama.Matrix;
import itdelatrisu.opsu.objects.Circle; import itdelatrisu.opsu.objects.Circle;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.objects.Slider; import itdelatrisu.opsu.objects.Slider;
import itdelatrisu.opsu.states.Game;
import static java.lang.Math.*; import static java.lang.Math.*;
@ -37,38 +36,19 @@ public class ArcMover extends PolyMover {
ym = m.get(2, 0) * 0.5; ym = m.get(2, 0) * 0.5;
r = sqrt(pow(xm, 2) + pow(ym, 2) - m.get(0, 0)); r = sqrt(pow(xm, 2) + pow(ym, 2) - m.get(0, 0));
alpha = atan2(p1.end.y - ym, p1.end.x - xm); alpha = atan2(p1.end.y - ym, p1.end.x - xm);
beta = atan2(middle.end.y - ym, middle.end.x - xm); beta = atan2(middle.start.y - ym, middle.start.x - xm);
gamma = atan2(p2.start.y - ym, p2.start.x - xm); gamma = atan2(p2.start.y - ym, p2.start.x - xm);
//fixAngles();
}
private void fixAngles() {
if (alpha < gamma && gamma < beta) {
gamma += 2 * PI;
}
else if ((beta < alpha && alpha < gamma)) {
beta += 2 * PI;
gamma += 2 * PI;
}
else if (beta < gamma && gamma < alpha) {
alpha -= 2 * PI;
}
else if (gamma < alpha && alpha < beta) {
alpha -= 2 * PI;
}
} }
@Override @Override
public double[] getPointAt(int time) { public double[] getPointAt(int time) {
double angle; double angle;
double percent;
if (time < middle.getTime()) { if (time < middle.getTime()) {
percent = ((double) time - p1.getEndTime()) / (middle.getTime() - p1.getEndTime()); double percent = ((double) time - p1.getEndTime()) / ((middle.getTime() - p1.getEndTime()));
angle = alpha + (beta - alpha) * percent; angle = alpha + (beta - alpha) * percent;
} }
else { else {
percent = ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime()); angle = beta + (gamma - beta) * ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime());
angle = beta + (gamma - beta) * percent;
} }
return new double[]{ return new double[]{
xm + r * cos(angle), xm + r * cos(angle),
@ -87,20 +67,7 @@ public class ArcMover extends PolyMover {
private static Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) { private static Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) {
Matrix a, b; Matrix a, b;
if (p2.isSlider()) { if (!p2.isSlider()) {
Circle c = (((Slider) p2).getTickPositionCircles()[0]);
a = new Matrix(new double[][]{
{1, -p1.end.x, -p1.end.y},
{1, -middle.start.x, -middle.start.y},
{1, -c.end.x, -c.end.y}
});
b = new Matrix(new double[][]{
{-(pow(p1.end.x, 2) + pow(p1.end.y, 2))},
{-(pow(middle.start.x, 2) + pow(middle.start.y, 2))},
{-(pow(c.end.x, 2) + pow(c.end.y, 2))},
});
}
else {
a = new Matrix(new double[][]{ a = new Matrix(new double[][]{
{1, -p1.end.x, -p1.end.y}, {1, -p1.end.x, -p1.end.y},
{1, -middle.start.x, -middle.start.y}, {1, -middle.start.x, -middle.start.y},
@ -111,8 +78,19 @@ public class ArcMover extends PolyMover {
{-(pow(middle.start.x, 2) + pow(middle.start.y, 2))}, {-(pow(middle.start.x, 2) + pow(middle.start.y, 2))},
{-(pow(p2.start.x, 2) + pow(p2.start.y, 2))}, {-(pow(p2.start.x, 2) + pow(p2.start.y, 2))},
}); });
} else {
Circle c = ((Slider) p2).getTickPositionCircles()[0];
a = new Matrix(new double[][]{
{1, -p1.end.x, -p1.end.y},
{1, -middle.start.x, -middle.start.y},
{1, -c.start.x, -c.start.y}
});
b = new Matrix(new double[][]{
{-(pow(p1.end.x, 2) + pow(p1.end.y, 2))},
{-(pow(middle.start.x, 2) + pow(middle.start.y, 2))},
{-(pow(c.start.x, 2) + pow(c.start.y, 2))},
});
} }
return a.solve(b); return a.solve(b);
} }

View File

@ -9,11 +9,11 @@ import yugecin.opsudance.movers.LinearMover;
*/ */
public class LineMover extends PolyMover { public class LineMover extends PolyMover {
private GameObject[] objects; GameObject[] objects;
public LineMover(GameObject[] objects, int startIndex, int count) { public LineMover(GameObject[] objects, int startIndex, int count) {
this.objects = new GameObject[count]; this.objects = new GameObject[count];
System.arraycopy(objects, startIndex, this.objects, 0, count); System.arraycopy(objects, startIndex, this.objects, 0, count - 1);
} }
@Override @Override
@ -21,7 +21,6 @@ public class LineMover extends PolyMover {
int i = 0; int i = 0;
while (time > objects[i].getTime() && i < objects.length - 1) while (time > objects[i].getTime() && i < objects.length - 1)
i++; i++;
return new LinearMover(i == 0 ? new DummyObject() : objects[i - 1], objects[i], 1).getPointAt(time); return new LinearMover(i == 0 ? new DummyObject() : objects[i - 1], objects[i], 1).getPointAt(time);
} }

View File

@ -6,6 +6,8 @@ import awlex.ospu.polymover.PolyMover;
import itdelatrisu.opsu.objects.DummyObject; import itdelatrisu.opsu.objects.DummyObject;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import java.util.Arrays;
/** /**
* Created by Awlex on 18.11.2016. * Created by Awlex on 18.11.2016.
*/ */
@ -41,13 +43,11 @@ public class ArcFactory implements PolyMoverFactory {
objects = new GameObject[]{ objects = new GameObject[]{
new DummyObject(), new DummyObject(),
objects[0], objects[0],
objects[1] objects[1],
}; };
startIndex++; startIndex = 0;
} }
GameObject middle = objects[startIndex + 1]; GameObject middle = objects[startIndex + 1];
if (middle.isSlider() || middle.isSpinner())
return;
if (!ArcMover.canCricleExistBetweenItems(objects[startIndex], middle, objects[startIndex + 2])) if (!ArcMover.canCricleExistBetweenItems(objects[startIndex], middle, objects[startIndex + 2]))
current = new LineMover(objects, startIndex, 3); current = new LineMover(objects, startIndex, 3);
else else
@ -59,19 +59,17 @@ public class ArcFactory implements PolyMoverFactory {
} }
public void update(GameObject p) { public void update(GameObject p) {
GameObject[] items = current.getItems(); GameObject[] items = (previous == null ? current : previous).getItems();
GameObject last = items[items.length - 1]; GameObject last = items[items.length - 1];
if (last != p) { if (last != p) {
previous = current; previous = current;
if (!(last.isSpinner() || last.isSlider()))
if (ArcMover.canCricleExistBetweenItems(items[items.length - 2], last, p)) { if (ArcMover.canCricleExistBetweenItems(items[items.length - 2], last, p)) {
current = new ArcMover(previous, p); current = new ArcMover(items[items.length - 2], last, p);
} } else {
else { GameObject[] lineObjects = new GameObject[PREFFERED_BUFFER_SIZE];
current = new LineMover(items, 0, items.length); System.arraycopy(items, items.length - 2, lineObjects, 0, PREFFERED_BUFFER_SIZE - 2);
} lineObjects[lineObjects.length - 1] = p;
else { current = new LineMover(lineObjects, 0, PREFFERED_BUFFER_SIZE);
current = null;
} }
} }
lastIndex++; lastIndex++;

View File

@ -267,16 +267,18 @@ public class Dancer {
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]); c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
} }
if (polyMoverFactory.isInitialized() && polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getPrefferedBufferSize()) { if (polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getPrefferedBufferSize() - 1) {
polyMoverFactory.update(gameObjects[polyMoverFactory.getLatestIndex()]); if (polyMoverFactory.isInitialized()) {
polyMoverFactory.update(gameObjects[objectIndex + polyMoverFactory.getPrefferedBufferSize()]);
} }
else { else {
polyMoverFactory.init(gameObjects, objectIndex - 1); polyMoverFactory.init(gameObjects, objectIndex - 1);
} }
} }
}
if (time < c.getTime()) { if (time < c.getTime()) {
if (!p.isSpinner() || !c.isSpinner() && polyMoverFactory.isInitialized()) { if (!(p.isSpinner() || c.isSpinner())) {
double[] point = polyMoverFactory.getPointAt(time); double[] point = polyMoverFactory.getPointAt(time);
x = (float) point[0]; x = (float) point[0];
y = (float) point[1]; y = (float) point[1];