It looks better now

This commit is contained in:
Awlex 2016-11-19 21:54:33 +01:00
parent eb561d8369
commit b01033edd5
4 changed files with 85 additions and 22 deletions

View File

@ -1,7 +1,10 @@
package awlex.ospu.polymover;
import Jama.Matrix;
import itdelatrisu.opsu.objects.Circle;
import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.objects.Slider;
import itdelatrisu.opsu.states.Game;
import static java.lang.Math.*;
@ -36,17 +39,39 @@ public class ArcMover extends PolyMover {
alpha = atan2(p1.end.y - ym, p1.end.x - xm);
beta = atan2(middle.end.y - ym, middle.end.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
public double[] getPointAt(int time) {
double angle;
double percent;
if (time < middle.getTime()) {
angle = alpha + beta * ((double) time - p1.getEndTime()) / ((middle.getTime() - p1.getEndTime()));
percent = ((double) time - p1.getEndTime()) / (middle.getTime() - p1.getEndTime());
angle = alpha + (beta - alpha) * percent;
}
else {
angle = beta + gamma * ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime());
percent = ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime());
angle = beta + (gamma - beta) * percent;
}
if (angle > PI)
angle -= PI;
return new double[]{
xm + r * cos(angle),
ym + r * sin(angle)
@ -63,16 +88,32 @@ public class ArcMover extends PolyMover {
}
private static Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) {
Matrix a = new Matrix(new double[][]{
{1, -p1.end.x, -p1.end.y},
{1, -middle.end.x, -middle.end.y},
{1, -p2.start.x, -p2.start.y}
});
Matrix b = new Matrix(new double[][]{
{-(pow(p1.end.x, 2) + pow(p1.end.y, 2))},
{-(pow(middle.end.x, 2) + pow(middle.end.y, 2))},
{-(pow(p2.start.x, 2) + pow(p2.start.y, 2))},
});
Matrix a, b;
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[][]{
{1, -p1.end.x, -p1.end.y},
{1, -middle.start.x, -middle.start.y},
{1, -p2.start.x, -p2.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(p2.start.x, 2) + pow(p2.start.y, 2))},
});
}
return a.solve(b);
}

View File

@ -9,7 +9,7 @@ import yugecin.opsudance.movers.LinearMover;
*/
public class LineMover extends PolyMover {
GameObject[] objects;
private GameObject[] objects;
public LineMover(GameObject[] objects, int startIndex, int count) {
this.objects = new GameObject[count];
@ -27,6 +27,6 @@ public class LineMover extends PolyMover {
@Override
public GameObject[] getItems() {
return new GameObject[0];
return objects;
}
}

View File

@ -3,6 +3,7 @@ package awlex.ospu.polymover.factory;
import awlex.ospu.polymover.ArcMover;
import awlex.ospu.polymover.LineMover;
import awlex.ospu.polymover.PolyMover;
import itdelatrisu.opsu.objects.DummyObject;
import itdelatrisu.opsu.objects.GameObject;
/**
@ -17,6 +18,8 @@ public class ArcFactory implements PolyMoverFactory {
public double[] getPointAt(int time) {
if (previous == null) {
return current.getPointAt(time);
} else if (current == null) {
return previous.getPointAt(time);
}
double[] point1 = current.getPointAt(time);
@ -32,23 +35,41 @@ public class ArcFactory implements PolyMoverFactory {
public void init(GameObject[] objects, int startIndex) {
if (objects == null)
throw new NullPointerException("Objects musn't be null");
boolean b;
if (b = startIndex == -1) {
objects = new GameObject[]{
new DummyObject(),
objects[0],
objects[1]
};
startIndex++;
}
GameObject middle = objects[startIndex + 1];
if (middle.isSlider() || middle.isSpinner() || !ArcMover.canCricleExistBetweenItems(objects[startIndex], middle, objects[startIndex + 2]))
current = new LineMover(objects, startIndex, 3);
else
current = new ArcMover(objects[startIndex], middle, objects[startIndex + 2]);
lastIndex = startIndex + 2;
if (b)
lastIndex--;
previous = null;
}
public void update(GameObject p) {
GameObject[] items = (previous == null ? current : previous).getItems();
GameObject[] items = current.getItems();
System.out.println(items.length);
GameObject last = items[items.length - 1];
if (last != p) {
if (ArcMover.canCricleExistBetweenItems(items[items.length - 2], items[items.length - 1], p)) {
previous = current;
current = new ArcMover(previous, p);
previous = current;
if (!(last.isSpinner() || last.isSlider()))
if (ArcMover.canCricleExistBetweenItems(items[items.length - 2], last, p)) {
current = new ArcMover(previous, p);
}
else {
current = new LineMover(items, 0, items.length);
}
else {
current = null;
}
}
lastIndex++;

View File

@ -266,10 +266,11 @@ public class Dancer {
double[] spinnerStartPoint = spinner.getPoint();
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
}
// polyMoverFactory.init(gameObjects, objectIndex);
if (polyMoverFactory.isInitialized() && polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getPrefferedBufferSize() - 1) {
polyMoverFactory.update(gameObjects[polyMoverFactory.getPrefferedBufferSize() - 1]);
} else {
polyMoverFactory.update(gameObjects[polyMoverFactory.getLatestIndex()]);
}
else {
polyMoverFactory.init(gameObjects, objectIndex);
}
}