Basic Implementation of a Mover with more than 2 points (GameObjects) and added Jama (Java Matrix) library to the project
This commit is contained in:
parent
ffcdeed948
commit
5c5f6bd621
5
pom.xml
5
pom.xml
|
@ -209,5 +209,10 @@
|
|||
<artifactId>lzma-java</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gov.nist.math</groupId>
|
||||
<artifactId>jama</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
88
src/awlex/ospu/polymover/Arc.java
Normal file
88
src/awlex/ospu/polymover/Arc.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package awlex.ospu.polymover;
|
||||
|
||||
import Jama.Matrix;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 13.11.2016.
|
||||
*/
|
||||
public class Arc extends PolyMover {
|
||||
|
||||
private GameObject p1, middle, p2;
|
||||
private double xm, ym, r, alpha, beta, gamma;
|
||||
|
||||
public Arc(GameObject p1, GameObject middle, GameObject p2) {
|
||||
this.p1 = p1;
|
||||
this.middle = middle;
|
||||
this.p2 = p2;
|
||||
init();
|
||||
}
|
||||
|
||||
public Arc(PolyMover mover, GameObject p) {
|
||||
GameObject[] items = mover.getItems();
|
||||
p1 = items[items.length - 2];
|
||||
middle = items[items.length - 1];
|
||||
p2 = p;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Matrix m = prepareMatrix(p1, middle, p2);
|
||||
xm = m.get(2, 1);
|
||||
ym = m.get(3, 1);
|
||||
r = pow(xm, 2) + pow(ym, 2) - m.get(1, 1);
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getPoint(int time) {
|
||||
double percent;
|
||||
double angle;
|
||||
if (time < middle.getTime()) {
|
||||
time -= p1.getEndTime();
|
||||
percent = ((double) time) / ((middle.getTime() - p1.getEndTime()));
|
||||
angle = alpha + beta * percent;
|
||||
}
|
||||
else {
|
||||
time -= middle.getTime();
|
||||
percent = ((double) time) / (p2.getTime() - middle.getTime());
|
||||
angle = beta + gamma * percent;
|
||||
}
|
||||
return new double[]{
|
||||
xm + r * cos(angle),
|
||||
ym + r * sin(angle)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject[] getItems() {
|
||||
return new GameObject[]{
|
||||
p1,
|
||||
middle,
|
||||
p2
|
||||
};
|
||||
}
|
||||
|
||||
private 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))},
|
||||
});
|
||||
|
||||
return a.solve(b);
|
||||
}
|
||||
|
||||
public static boolean canCricleExistBetweenItems(GameObject p1, GameObject p2, GameObject p3) {
|
||||
return !((p1.end.x == p2.start.x && p1.end.x == p3.start.x) || (p1.end.y == p2.start.y && p1.end.y == p3.start.y));
|
||||
}
|
||||
}
|
12
src/awlex/ospu/polymover/PolyMover.java
Normal file
12
src/awlex/ospu/polymover/PolyMover.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package awlex.ospu.polymover;
|
||||
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public abstract class PolyMover {
|
||||
public abstract double[] getPoint(int time);
|
||||
|
||||
public abstract GameObject[] getItems();
|
||||
}
|
54
src/awlex/ospu/polymover/factory/ArcFactory.java
Normal file
54
src/awlex/ospu/polymover/factory/ArcFactory.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package awlex.ospu.polymover.factory;
|
||||
|
||||
import awlex.ospu.polymover.Arc;
|
||||
import awlex.ospu.polymover.PolyMover;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public class ArcFactory implements MultiMoverFactory {
|
||||
|
||||
private static final int PREFFERED_BUFFER_SIZE = 3;
|
||||
private PolyMover arc1, arc2;
|
||||
|
||||
@Override
|
||||
public double[] getPoint(int time) {
|
||||
if (arc2 == null) {
|
||||
return arc1.getPoint(time);
|
||||
}
|
||||
|
||||
double[] point1 = arc1.getPoint(time);
|
||||
double[] point2 = arc2.getPoint(time);
|
||||
|
||||
return new double[]{
|
||||
(point1[0] + point2[0]) * 0.5,
|
||||
(point1[1] + point2[1]) * 0.5
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void init(GameObject[] objects, int startIndex) {
|
||||
if (objects == null)
|
||||
throw new NullPointerException("Objects musn't be null");
|
||||
if (objects.length < startIndex + 2)
|
||||
arc1 = new Arc(objects[startIndex], objects[startIndex + 1], objects[startIndex + 2]);
|
||||
arc2 = null;
|
||||
}
|
||||
|
||||
public void update(GameObject p) {
|
||||
if (arc2 != null)
|
||||
arc1 = arc2;
|
||||
arc2 = new Arc(arc1, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrefferedBufferSize() {
|
||||
return PREFFERED_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Arcs";
|
||||
}
|
||||
}
|
27
src/awlex/ospu/polymover/factory/MultiMoverFactory.java
Normal file
27
src/awlex/ospu/polymover/factory/MultiMoverFactory.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package awlex.ospu.polymover.factory;
|
||||
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public interface MultiMoverFactory {
|
||||
|
||||
|
||||
/**
|
||||
* @param time point in time whose cursor position has to be calculated
|
||||
* @return [x, y]
|
||||
*/
|
||||
double[] getPoint(int time);
|
||||
|
||||
void init(GameObject[] objects, int startIndex);
|
||||
|
||||
void update(GameObject g);
|
||||
|
||||
/**
|
||||
* How many items the Factory would like to look in the future
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getPrefferedBufferSize();
|
||||
}
|
Loading…
Reference in New Issue
Block a user