From f95d1c466976ecd4751d9c8e283c8d8d1f074dc5 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 13:23:37 +0100 Subject: [PATCH] add quadratic bezier mover --- src/yugecin/opsudance/Dancer.java | 3 + .../movers/QuadraticBezierMover.java | 71 +++++++++++++++++++ .../QuadraticBezierMoverFactory.java | 36 ++++++++++ 3 files changed, 110 insertions(+) create mode 100644 src/yugecin/opsudance/movers/QuadraticBezierMover.java create mode 100644 src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java diff --git a/src/yugecin/opsudance/Dancer.java b/src/yugecin/opsudance/Dancer.java index fe56baac..b8b63d94 100644 --- a/src/yugecin/opsudance/Dancer.java +++ b/src/yugecin/opsudance/Dancer.java @@ -33,6 +33,7 @@ import itdelatrisu.opsu.objects.Slider; import itdelatrisu.opsu.objects.curves.Vec2f; import yugecin.opsudance.movers.LinearMover; import yugecin.opsudance.movers.Mover; +import yugecin.opsudance.movers.QuadraticBezierMover; import yugecin.opsudance.movers.factories.*; import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController; import yugecin.opsudance.movers.slidermovers.InheritedSliderMoverController; @@ -55,6 +56,7 @@ public class Dancer { new CenterSpiralMoverFactory(), //new LinearFactory(), new ArcFactory(), + new QuadraticBezierMoverFactory(), }; public static Spinner[] spinners = new Spinner[] { @@ -131,6 +133,7 @@ public class Dancer { for (Spinner s : spinners) { s.init(); } + QuadraticBezierMover.reset(); } public int getSpinnerIndex() { diff --git a/src/yugecin/opsudance/movers/QuadraticBezierMover.java b/src/yugecin/opsudance/movers/QuadraticBezierMover.java new file mode 100644 index 00000000..94c75dbc --- /dev/null +++ b/src/yugecin/opsudance/movers/QuadraticBezierMover.java @@ -0,0 +1,71 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2016 yugecin + * + * opsu!dance is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * opsu!dance is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with opsu!dance. If not, see . + */ +package yugecin.opsudance.movers; + +import itdelatrisu.opsu.Utils; +import itdelatrisu.opsu.objects.GameObject; + +import java.awt.*; + +public class QuadraticBezierMover extends Mover { + + private static Point p; + private static double prevspeed; + + public static void reset() { + p = new Point(0, 0); + prevspeed = 0; + } + + private int startTime; + private int totalTime; + + public QuadraticBezierMover(GameObject start, GameObject end, int dir) { + super(start, end, dir); + this.startTime = start.getEndTime(); + this.totalTime = end.getTime() - startTime; + + double startAngle = Math.atan2(startY - p.y, startX - p.x); + double angDiff = Math.atan2(startY - endY, startX - endX) - startAngle; + while (angDiff < 0) angDiff += Math.PI; + while (angDiff > Math.PI) angDiff -= Math.PI; + angDiff -= Math.PI / 2; + if (angDiff < 0) angDiff = -angDiff; + double dist = Utils.distance(startX, startY, endX, endY); + //double speed = dist / 10 + dist * (Math.PI - angDiff) / Math.PI; + p.x = (int) (startX + Math.cos(startAngle) * prevspeed); + p.y = (int) (startY + Math.sin(startAngle) * prevspeed); + prevspeed = (dist / totalTime) * 50; + } + + @Override + public double[] getPointAt(int time) { + double t = (double) (time - startTime) / totalTime; + double ct = (1 - t); + return new double[] { + ct * ct * startX + ct * 2 * t * p.x + t * t * endX, + ct * ct * startY + ct * 2 * t * p.y + t * t * endY, + }; + } + + @Override + public String getName() { + return "Quadratic Bezier"; + } + +} diff --git a/src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java b/src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java new file mode 100644 index 00000000..d37c2710 --- /dev/null +++ b/src/yugecin/opsudance/movers/factories/QuadraticBezierMoverFactory.java @@ -0,0 +1,36 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2016 yugecin + * + * opsu!dance is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * opsu!dance is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with opsu!dance. If not, see . + */ +package yugecin.opsudance.movers.factories; + +import itdelatrisu.opsu.objects.GameObject; +import yugecin.opsudance.movers.Mover; +import yugecin.opsudance.movers.QuadraticBezierMover; + +public class QuadraticBezierMoverFactory implements MoverFactory { + + @Override + public Mover create(GameObject start, GameObject end, int dir) { + return new QuadraticBezierMover(start, end, dir); + } + + @Override + public String toString() { + return "Quadratic bezier"; + } + +}