Improved all Spiral Classes.
This commit is contained in:
parent
e2e1ee2dfc
commit
ffcdeed948
|
@ -27,13 +27,30 @@ public class FakeGameObject extends GameObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FakeGameObject(GameObject start, GameObject end) {
|
public FakeGameObject(GameObject start, GameObject end) {
|
||||||
halfTime = start.getEndTime() + (end.getTime() - start.getEndTime()) / 2;
|
halfTime = Math.abs(start.getEndTime() + (end.getTime() - start.getEndTime()) / 2);
|
||||||
this.start = new Vec2f();
|
this.start = new Vec2f();
|
||||||
this.end = new Vec2f();
|
this.end = new Vec2f();
|
||||||
this.start.x = this.end.x = (start.end.x + end.start.x) / 2;
|
this.start.x = this.end.x = (start.end.x + end.start.x) / 2;
|
||||||
this.start.y = this.end.y = (start.end.y + end.start.y) / 2;
|
this.start.y = this.end.y = (start.end.y + end.start.y) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getEndTime() {
|
||||||
|
return halfTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTime() {
|
||||||
|
return halfTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(int time) {
|
||||||
|
this.halfTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Everything down here is unimportant
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics g, int trackPosition, boolean mirrored) {
|
public void draw(Graphics g, int trackPosition, boolean mirrored) {
|
||||||
|
|
||||||
|
@ -53,17 +70,7 @@ public class FakeGameObject extends GameObject {
|
||||||
public Vec2f getPointAt(int trackPosition) {
|
public Vec2f getPointAt(int trackPosition) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getEndTime() {
|
|
||||||
return halfTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTime() {
|
|
||||||
return halfTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePosition() {
|
public void updatePosition() {
|
||||||
|
|
||||||
|
@ -98,8 +105,4 @@ public class FakeGameObject extends GameObject {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(int time) {
|
|
||||||
this.halfTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,46 +1,36 @@
|
||||||
package awlex.ospu.movers;
|
package awlex.ospu.movers;
|
||||||
|
|
||||||
import itdelatrisu.opsu.Utils;
|
|
||||||
import itdelatrisu.opsu.objects.GameObject;
|
import itdelatrisu.opsu.objects.GameObject;
|
||||||
import yugecin.opsudance.movers.Mover;
|
import yugecin.opsudance.movers.Mover;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alex Wieser on 09.10.2016.
|
* Created by Alex Wieser on 09.10.2016.
|
||||||
* WHO DO YOU THINK I AM?
|
* WHO DO YOU THINK I AM?
|
||||||
*
|
* <p>
|
||||||
* This {@link Mover} starts the spiral from the start object
|
* This {@link Mover} starts the spiral from the start object
|
||||||
*/
|
*/
|
||||||
public class CentralSpiralMover extends Mover {
|
public class CentralSpiralMover extends SpiralMover {
|
||||||
|
|
||||||
/**
|
public CentralSpiralMover(GameObject start, GameObject end, int dir) {
|
||||||
* How many times the cursor goes around the center
|
super(start, end, dir);
|
||||||
* For satisfying results this musn't be a multiple of 2
|
}
|
||||||
*/
|
|
||||||
private final int CIRCLENAVIGATIONS = 1;
|
@Override
|
||||||
|
public double[] getPointAt(int time) {
|
||||||
double startAng;
|
double rad = radius * getT(time);
|
||||||
double startRad;
|
double ang = angle + 2d * Math.PI * getT(time) * dir;
|
||||||
|
return new double[]{
|
||||||
public CentralSpiralMover(GameObject start, GameObject end, int dir) {
|
startX + rad * Math.cos(ang),
|
||||||
super(start, end, dir);
|
startY + rad * Math.sin(ang)
|
||||||
startAng = Math.atan2(endY - startY, endX - startX);
|
};
|
||||||
startRad = Utils.distance(startX, startY, endX, endY);
|
}
|
||||||
if (startRad < 20)
|
|
||||||
startRad = 20 + startRad / 20d;
|
@Override
|
||||||
}
|
public boolean checkBounds() {
|
||||||
|
boolean ret = true;
|
||||||
@Override
|
int totalTime = endTime - startTime;
|
||||||
public double[] getPointAt(int time) {
|
for (int i = 0; ret && i <= 20; i++)
|
||||||
double rad = startRad * getT(time);
|
ret = checkIfPointInBounds(getPointAt((int) (startTime + totalTime * (i / 20d))));
|
||||||
double ang = CIRCLENAVIGATIONS * (startAng + 2d * Math.PI * getT(time) * dir);
|
return ret;
|
||||||
return new double[]{
|
}
|
||||||
startX + rad * Math.cos(ang),
|
|
||||||
startY + rad * Math.sin(ang)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "Spiral2";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import awlex.ospu.FakeGameObject;
|
||||||
import itdelatrisu.opsu.Options;
|
import itdelatrisu.opsu.Options;
|
||||||
import itdelatrisu.opsu.Utils;
|
import itdelatrisu.opsu.Utils;
|
||||||
import itdelatrisu.opsu.objects.GameObject;
|
import itdelatrisu.opsu.objects.GameObject;
|
||||||
|
import yugecin.opsudance.movers.CircleMover;
|
||||||
|
import yugecin.opsudance.movers.LinearMover;
|
||||||
import yugecin.opsudance.movers.Mover;
|
import yugecin.opsudance.movers.Mover;
|
||||||
import yugecin.opsudance.movers.factories.AutoMoverFactory;
|
import yugecin.opsudance.movers.factories.AutoMoverFactory;
|
||||||
|
|
||||||
|
@ -16,120 +18,100 @@ import yugecin.opsudance.movers.factories.AutoMoverFactory;
|
||||||
* 2 inner {@link Mover}s around it. This class works recursively and might lead to
|
* 2 inner {@link Mover}s around it. This class works recursively and might lead to
|
||||||
* high ram usage on very jumpy maps or even a StackOverFlow.
|
* high ram usage on very jumpy maps or even a StackOverFlow.
|
||||||
*/
|
*/
|
||||||
public class CombinedSpiralMover extends Mover {
|
public class CombinedSpiralMover extends SpiralMover {
|
||||||
|
|
||||||
private Mover[] movers;
|
private Mover[] movers;
|
||||||
private GameObject fakeObject;
|
private GameObject fakeObject;
|
||||||
private int halfTime;
|
private int halfTime;
|
||||||
private int startTime;
|
private int startTime;
|
||||||
private int endTime;
|
private int endTime;
|
||||||
|
|
||||||
public CombinedSpiralMover(GameObject middle, GameObject start, GameObject end, int dir) {
|
public CombinedSpiralMover(GameObject middle, GameObject start, GameObject end, int dir) {
|
||||||
super(start, end, dir);
|
this(true, middle, start, end, dir);
|
||||||
fakeObject = middle != null ? middle : new FakeGameObject(start, end);
|
}
|
||||||
|
|
||||||
halfTime = fakeObject.getEndTime();
|
public CombinedSpiralMover(boolean prefered, GameObject middle, GameObject start, GameObject end, int dir) {
|
||||||
startTime = start.getEndTime();
|
super(start, end, dir);
|
||||||
endTime = end.getTime();
|
fakeObject = middle != null ? middle : new FakeGameObject(start, end);
|
||||||
|
|
||||||
movers = new Mover[2];
|
halfTime = fakeObject.getEndTime();
|
||||||
movers[0] = bestPick(0, start, fakeObject, dir);
|
startTime = start.getEndTime();
|
||||||
movers[1] = bestPick(1, fakeObject, end, dir);
|
endTime = end.getTime();
|
||||||
}
|
|
||||||
|
movers = new Mover[2];
|
||||||
public CombinedSpiralMover(GameObject start, GameObject end, int dir) {
|
movers[0] = bestPick(prefered ? 0 : 1, start, fakeObject, dir);
|
||||||
this(null, start, end, dir);
|
movers[1] = bestPick(prefered ? 1 : 0, fakeObject, end, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public CombinedSpiralMover(GameObject start, GameObject end, int dir) {
|
||||||
* Method to pick the 2 inner {@link Mover}s.
|
this(null, start, end, dir);
|
||||||
* Tries to pick a {@link SpiralToMover} first position and a
|
}
|
||||||
* {@link CombinedSpiralMover} for second position for the sake of good looks
|
|
||||||
*
|
@Override
|
||||||
* @param pos index of
|
public boolean checkBounds() {
|
||||||
* @param start start object
|
/*Not needed in this case*/
|
||||||
* @param end end object
|
return true;
|
||||||
* @param dir direction
|
}
|
||||||
* @return best fitting Mover
|
|
||||||
*/
|
|
||||||
private Mover bestPick(int pos, GameObject start, GameObject end, int dir) {
|
public CombinedSpiralMover(Mover mover1, Mover mover2, int startTime, int halfTime, int endTime) {
|
||||||
|
super(new FakeGameObject(), new FakeGameObject(), 0); //With this constructor you only care about the movers
|
||||||
if (endTime - startTime < 10 || Utils.distance(start.end.x, start.end.y, end.start.x, end.start.y) < 40)
|
this.startTime = startTime;
|
||||||
return new AutoMoverFactory().create(start, end, dir);
|
this.endTime = endTime;
|
||||||
|
this.halfTime = halfTime;
|
||||||
SpiralToMover spiralTo = new SpiralToMover(start, end, dir);
|
movers = new Mover[]{
|
||||||
CentralSpiralMover center = new CentralSpiralMover(start, end, dir);
|
mover1,
|
||||||
|
mover2
|
||||||
if (pos == 0) {
|
};
|
||||||
if (inBounds1(spiralTo) || inBounds1(spiralTo = new SpiralToMover(start, end, -dir)))
|
}
|
||||||
return spiralTo;
|
|
||||||
else if (inBounds1(center) || inBounds1(center = new CentralSpiralMover(start, end, -dir)))
|
/**
|
||||||
return center;
|
* Method to pick the 2 inner {@link Mover}s.
|
||||||
} else if (pos == 1) {
|
* Tries to pick a {@link SpiralToMover} first position and a
|
||||||
if (inBounds2(center) || inBounds2(center = new CentralSpiralMover(start, end, -dir)))
|
* {@link CombinedSpiralMover} for second position for the sake of good looks
|
||||||
return center;
|
*
|
||||||
else if (inBounds2(spiralTo = new SpiralToMover(start, end, -dir)) || inBounds2(spiralTo = new SpiralToMover(start, end, dir)))
|
* @param pos index of
|
||||||
return spiralTo;
|
* @param start start object
|
||||||
} else throw new IllegalStateException("Only 2 inner Movers allowed");
|
* @param end end object
|
||||||
|
* @param dir direction
|
||||||
return new CombinedSpiralMover(start, end, dir);
|
* @return best fitting Mover
|
||||||
}
|
*/
|
||||||
|
private Mover bestPick(int pos, GameObject start, GameObject end, int dir) {
|
||||||
|
|
||||||
@Override
|
if (endTime - startTime < 40 || Utils.distance(start.end.x, start.end.y, end.start.x, end.start.y) < 40)
|
||||||
public double[] getPointAt(int time) {
|
return new LinearMover(start, end, dir);
|
||||||
if (time < halfTime)
|
|
||||||
return movers[0].getPointAt(time);
|
SpiralToMover spiralTo = new SpiralToMover(start, end, dir);
|
||||||
else if (time > halfTime)
|
CentralSpiralMover center = new CentralSpiralMover(start, end, dir);
|
||||||
return movers[1].getPointAt(time);
|
|
||||||
else return new double[]{
|
if (pos == 0) {
|
||||||
fakeObject.start.x,
|
if (spiralTo.checkBounds() || (spiralTo = new SpiralToMover(start, end, -dir)).checkBounds())
|
||||||
fakeObject.start.y
|
return spiralTo;
|
||||||
};
|
else if (center.checkBounds() || (center = new CentralSpiralMover(start, end, -dir)).checkBounds())
|
||||||
}
|
return center;
|
||||||
|
}
|
||||||
@Override
|
else if (pos == 1) {
|
||||||
public String getName() {
|
if (center.checkBounds() || (center = new CentralSpiralMover(start, end, -dir)).checkBounds())
|
||||||
return "CombinedSpiralMover";
|
return center;
|
||||||
}
|
else if ((spiralTo = new SpiralToMover(start, end, -dir)).checkBounds() || (spiralTo = new SpiralToMover(start, end, dir)).checkBounds())
|
||||||
|
return spiralTo;
|
||||||
/**
|
}
|
||||||
* /**
|
else throw new IllegalStateException("Only 2 inner Movers allowed");
|
||||||
* Check if the first object would be inbounds
|
|
||||||
*
|
return new CombinedSpiralMover(start, end, dir);
|
||||||
* @param mover - the mover to check
|
}
|
||||||
* @return is mover always inbounds
|
|
||||||
*/
|
|
||||||
public boolean inBounds1(Mover mover) {
|
@Override
|
||||||
boolean ret = true;
|
public double[] getPointAt(int time) {
|
||||||
int middle = halfTime - startTime;
|
if (time < halfTime)
|
||||||
for (int i = 1; ret && i < 15; i++) {
|
return movers[0].getPointAt(time);
|
||||||
ret = checkBounds(mover.getPointAt(startTime + (middle * i) / 16));
|
else if (time > halfTime)
|
||||||
//System.out.println("i: " + i + " = " + ret);
|
return movers[1].getPointAt(time);
|
||||||
}
|
else return new double[]{
|
||||||
|
fakeObject.start.x,
|
||||||
return ret;
|
fakeObject.start.y
|
||||||
}
|
};
|
||||||
|
}
|
||||||
/**
|
|
||||||
* /**
|
|
||||||
* Check if the second object would be inbounds
|
|
||||||
*
|
|
||||||
* @param mover - the mover to check
|
|
||||||
* @return is mover always inbounds
|
|
||||||
*/
|
|
||||||
private boolean inBounds2(Mover mover) {
|
|
||||||
boolean ret = true;
|
|
||||||
int middle = endTime - halfTime;
|
|
||||||
for (int i = 1; ret && i < 15; i++) {
|
|
||||||
ret = checkBounds(mover.getPointAt(startTime + (middle * i) / 16));
|
|
||||||
//System.out.println("i: " + i + " = " + ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkBounds(double[] pos) {
|
|
||||||
return 0 < pos[0] && pos[0] < Options.width && 0 < pos[1] && pos[1] < Options.height;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
55
src/awlex/ospu/movers/SpiralMover.java
Normal file
55
src/awlex/ospu/movers/SpiralMover.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package awlex.ospu.movers;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.Options;
|
||||||
|
import itdelatrisu.opsu.Utils;
|
||||||
|
import itdelatrisu.opsu.objects.GameObject;
|
||||||
|
import org.newdawn.slick.util.pathfinding.Mover;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Alex Wieser on 22.10.2016.
|
||||||
|
*/
|
||||||
|
abstract class SpiralMover extends yugecin.opsudance.movers.Mover {
|
||||||
|
|
||||||
|
protected double angle;
|
||||||
|
protected double radius;
|
||||||
|
|
||||||
|
int startTime;
|
||||||
|
int endTime;
|
||||||
|
|
||||||
|
SpiralMover(GameObject start, GameObject end, int dir) {
|
||||||
|
super(start, end, dir);
|
||||||
|
angle = Math.atan2(endY - startY, endX - startX);
|
||||||
|
radius = Utils.distance(startX, startY, endX, endY);
|
||||||
|
startTime = start.getEndTime();
|
||||||
|
endTime = end.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getAngle() {
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDir() {
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean checkBounds();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if a point is in bounds
|
||||||
|
*
|
||||||
|
* @param pos x and y coordinations
|
||||||
|
* @return whether this point is within the screen
|
||||||
|
*/
|
||||||
|
boolean checkIfPointInBounds(double[] pos) {
|
||||||
|
return 0 < pos[0] && pos[0] < Options.width && 0 < pos[1] && pos[1] < Options.height;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,46 +1,36 @@
|
||||||
package awlex.ospu.movers;
|
package awlex.ospu.movers;
|
||||||
|
|
||||||
import itdelatrisu.opsu.Utils;
|
|
||||||
import itdelatrisu.opsu.objects.GameObject;
|
import itdelatrisu.opsu.objects.GameObject;
|
||||||
import yugecin.opsudance.movers.Mover;
|
import yugecin.opsudance.movers.Mover;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alex Wieser on 09.10.2016.
|
* Created by Alex Wieser on 09.10.2016.
|
||||||
* WHO DO YOU THINK I AM?
|
* WHO DO YOU THINK I AM?
|
||||||
*
|
* <p>
|
||||||
* This {@link Mover} ends the spiral from the start object
|
* This {@link Mover} ends the spiral from the start object
|
||||||
*/
|
*/
|
||||||
public class SpiralToMover extends Mover {
|
public class SpiralToMover extends SpiralMover {
|
||||||
|
|
||||||
/**
|
public SpiralToMover(GameObject start, GameObject end, int dir) {
|
||||||
* How many times the cursor goes around the center
|
super(start, end, dir);
|
||||||
* For satisfying results this musn't be a multiple of 2
|
}
|
||||||
*/
|
|
||||||
private final int CIRCLENAVIGATIONS = 1;
|
@Override
|
||||||
|
public double[] getPointAt(int time) {
|
||||||
double startAng;
|
double rad = radius * (1 - getT(time));
|
||||||
double startRad;
|
double ang = angle + Math.PI + 2d * Math.PI * (1 - getT(time)) * dir;
|
||||||
|
return new double[]{
|
||||||
public SpiralToMover(GameObject start, GameObject end, int dir) {
|
endX + rad * Math.cos(ang),
|
||||||
super(start, end, dir);
|
endY + rad * Math.sin(ang)
|
||||||
startAng = Math.atan2(endY - startY, endX - startX) + Math.PI;
|
};
|
||||||
startRad = Utils.distance(startX, startY, endX, endY);
|
}
|
||||||
if (startRad < 20)
|
|
||||||
startRad = 20 + startRad / 20d;
|
@Override
|
||||||
}
|
public boolean checkBounds() {
|
||||||
|
boolean ret = true;
|
||||||
@Override
|
int totalTime = endTime - startTime;
|
||||||
public double[] getPointAt(int time) {
|
for (int i = 0; ret && i <= 20; i++)
|
||||||
double rad = startRad * (1 - getT(time));
|
ret = checkIfPointInBounds(getPointAt((int) (startTime + totalTime * (1 - i / 20d))));
|
||||||
double ang = CIRCLENAVIGATIONS * (startAng + 2d * Math.PI * (1 - getT(time)) * dir);
|
return ret;
|
||||||
return new double[]{
|
}
|
||||||
endX + rad * Math.cos(ang),
|
|
||||||
endY + rad * Math.sin(ang)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "Spiral2";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,20 +8,20 @@ import yugecin.opsudance.movers.factories.MoverFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alex Wieser on 10.10.2016.
|
* Created by Alex Wieser on 10.10.2016.
|
||||||
|
* Best With Only one direction (Left or Right)
|
||||||
*/
|
*/
|
||||||
public class CenterSpiralMoverFactory implements MoverFactory {
|
public class CenterSpiralMoverFactory implements MoverFactory {
|
||||||
|
|
||||||
private static FakeGameObject middle;
|
private static FakeGameObject middle = new FakeGameObject();
|
||||||
@Override
|
|
||||||
public Mover create(GameObject start, GameObject end, int dir) {
|
|
||||||
if (middle == null)
|
|
||||||
middle = new FakeGameObject();
|
|
||||||
middle.setTime(start.getEndTime() + (end.getTime() - start.getEndTime()) / 2);
|
|
||||||
return new CombinedSpiralMover(middle, start, end, dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public Mover create(GameObject start, GameObject end, int dir) {
|
||||||
return "CentralSpiralSpin";
|
middle.setTime(start.getEndTime() + (end.getTime() - start.getEndTime()) / 2);
|
||||||
}
|
return new CombinedSpiralMover(middle, start, end, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CentralSpiralSpin";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package awlex.ospu.movers.factories;
|
||||||
|
|
||||||
|
import awlex.ospu.movers.CombinedSpiralMover;
|
||||||
|
import itdelatrisu.opsu.objects.GameObject;
|
||||||
|
import yugecin.opsudance.movers.Mover;
|
||||||
|
import yugecin.opsudance.movers.factories.MoverFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Alex Wieser on 26.10.2016.
|
||||||
|
*/
|
||||||
|
public class CombinedSpiralMoverFactory implements MoverFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mover create(GameObject start, GameObject end, int dir) {
|
||||||
|
return new CombinedSpiralMover(start, end, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Spiral even more";
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,86 +10,84 @@ import yugecin.opsudance.spinners.Spinner;
|
||||||
*/
|
*/
|
||||||
public class SpiralSpinner extends Spinner {
|
public class SpiralSpinner extends Spinner {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many points the Spinner uses.
|
* How many points the Spinner uses.
|
||||||
* if there are not enough points the spinner looks angular.
|
* if there are not enough points the spinner looks angular.
|
||||||
* if there are too many points the spinner doesn't operate smooth
|
* if there are too many points the spinner doesn't operate smooth
|
||||||
*/
|
*/
|
||||||
private final int SIZE = 100;
|
private final int SIZE = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The density of the spinner
|
* The density of the spinner
|
||||||
* Determines how many times the spinner will around the center.
|
* Determines how many times the spinner will around the center.
|
||||||
* if the value is to high the spinner will become angular.
|
* if the value is to high the spinner will become angular.
|
||||||
* if this value goes under 2 the spinner won't be complete
|
* if this value goes under 2 the spinner won't be complete
|
||||||
*/
|
*/
|
||||||
private final int DENSITY = 10;
|
private final int DENSITY = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much the spinner will be rotated.
|
* How much the spinner will be rotated.
|
||||||
* Negative = clockwise
|
* Negative = clockwise
|
||||||
* Positive = counter clockwise
|
* Positive = counter clockwise
|
||||||
*/
|
*/
|
||||||
private final double DELTA = -Math.PI / 20;
|
private final double DELTA = -Math.PI / 20;
|
||||||
private int MAX_RAD;
|
private int MAX_RAD;
|
||||||
private int index;
|
private int index;
|
||||||
double[][] points;
|
private double[][] points;
|
||||||
boolean down;
|
private boolean down;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
points = new double[SIZE][];
|
points = new double[SIZE][];
|
||||||
double ang;
|
double ang;
|
||||||
double rad;
|
double rad;
|
||||||
for (int i = 0; i < SIZE / 2; i++) {
|
for (int i = 0; i < SIZE / 2; i++) {
|
||||||
MAX_RAD = (int) (Options.height * .35);
|
MAX_RAD = (int) (Options.height * .35);
|
||||||
ang = (DENSITY * (Math.PI / SIZE) * i);
|
ang = (DENSITY * (Math.PI / SIZE) * i);
|
||||||
rad = (MAX_RAD / (SIZE / 2)) * i;
|
rad = (MAX_RAD / (SIZE / 2)) * i;
|
||||||
int offsetX = Options.width / 2;
|
int offsetX = Options.width / 2;
|
||||||
int offsetY = Options.height / 2;
|
int offsetY = Options.height / 2;
|
||||||
points[SIZE / 2 - 1 - i] = new double[]{
|
points[SIZE / 2 - 1 - i] = new double[]{
|
||||||
offsetX + rad * Math.cos(ang),
|
offsetX + rad * Math.cos(ang),
|
||||||
offsetY + rad * Math.sin(ang)
|
offsetY + rad * Math.sin(ang)
|
||||||
};
|
};
|
||||||
points[SIZE / 2 + i] = new double[]{
|
points[SIZE / 2 + i] = new double[]{
|
||||||
offsetX + rad * (Math.cos(ang) * Math.cos(Math.PI) - Math.sin(ang) * Math.sin(Math.PI)),
|
offsetX + rad * (Math.cos(ang) * Math.cos(Math.PI) - Math.sin(ang) * Math.sin(Math.PI)),
|
||||||
offsetY + rad * -Math.sin(ang)
|
offsetY + rad * -Math.sin(ang)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Spiralspinner";
|
return "Spiralspinner";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double[] getPoint() {
|
public double[] getPoint() {
|
||||||
//if (waitForDelay()) {
|
if (down) {
|
||||||
if (down) {
|
if (--index == 0)
|
||||||
if (--index == 0)
|
down = !down;
|
||||||
down = !down;
|
} else if (++index == SIZE - 1)
|
||||||
} else if (++index == SIZE - 1)
|
down = !down;
|
||||||
down = !down;
|
|
||||||
|
|
||||||
if (!down && index == 1) {
|
if (!down && index == 1) {
|
||||||
rotatePointAroundCenter(points[0], DELTA);
|
rotatePointAroundCenter(points[0], DELTA);
|
||||||
} else if (down && index == SIZE - 2) {
|
} else if (down && index == SIZE - 2) {
|
||||||
rotatePointAroundCenter(points[SIZE - 1], DELTA);
|
rotatePointAroundCenter(points[SIZE - 1], DELTA);
|
||||||
}
|
}
|
||||||
//}
|
rotatePointAroundCenter(points[index], DELTA);
|
||||||
rotatePointAroundCenter(points[index], DELTA);
|
return points[index];
|
||||||
return points[index];
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void rotatePointAroundCenter(double[] point, double beta) {
|
private void rotatePointAroundCenter(double[] point, double beta) {
|
||||||
double angle = Math.atan2(point[1] - Options.height / 2, point[0] - Options.width / 2);
|
double angle = Math.atan2(point[1] - Options.height / 2, point[0] - Options.width / 2);
|
||||||
double rad = Utils.distance(point[0], point[1], Options.width / 2, Options.height / 2);
|
double rad = Utils.distance(point[0], point[1], Options.width / 2, Options.height / 2);
|
||||||
|
|
||||||
//rotationMatrix
|
//rotationMatrix
|
||||||
point[0] = Options.width / 2 + rad * (Math.cos(angle) * Math.cos(beta) - Math.sin(angle) * Math.sin(beta));
|
point[0] = Options.width / 2 + rad * (Math.cos(angle) * Math.cos(beta) - Math.sin(angle) * Math.sin(beta));
|
||||||
point[1] = Options.height / 2 + rad * (Math.cos(angle) * Math.sin(beta) + Math.sin(angle) * Math.cos(beta));
|
point[1] = Options.height / 2 + rad * (Math.cos(angle) * Math.sin(beta) + Math.sin(angle) * Math.cos(beta));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user