2015-01-30 02:36:23 +01:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
|
|
|
*
|
|
|
|
* opsu! 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! 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!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu.objects.curves;
|
|
|
|
|
2015-04-12 16:25:03 +02:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2015-01-30 02:36:23 +01:00
|
|
|
import itdelatrisu.opsu.OsuHitObject;
|
2015-04-12 16:25:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
2015-04-12 16:25:03 +02:00
|
|
|
import org.newdawn.slick.Image;
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Representation of a curve.
|
2015-02-11 08:56:02 +01:00
|
|
|
*
|
|
|
|
* @author fluddokt (https://github.com/fluddokt)
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
|
|
|
public abstract class Curve {
|
2015-04-13 04:33:20 +02:00
|
|
|
/** Points generated along the curve should be spaced this far apart. */
|
2015-04-12 19:19:33 +02:00
|
|
|
protected static float CURVE_POINTS_SEPERATION = 5;
|
2015-04-13 04:33:20 +02:00
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
/** The associated OsuHitObject. */
|
|
|
|
protected OsuHitObject hitObject;
|
|
|
|
|
2015-03-13 01:12:43 +01:00
|
|
|
/** The scaled starting x, y coordinates. */
|
|
|
|
protected float x, y;
|
|
|
|
|
|
|
|
/** The scaled slider x, y coordinate lists. */
|
|
|
|
protected float[] sliderX, sliderY;
|
|
|
|
|
2015-04-13 04:33:20 +02:00
|
|
|
/** Points along the curve (set by inherited classes). */
|
2015-04-12 16:25:03 +02:00
|
|
|
protected Vec2f[] curve;
|
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param hitObject the associated OsuHitObject
|
|
|
|
* @param color the color of this curve
|
|
|
|
*/
|
|
|
|
protected Curve(OsuHitObject hitObject, Color color) {
|
|
|
|
this.hitObject = hitObject;
|
2015-03-13 01:12:43 +01:00
|
|
|
this.x = hitObject.getScaledX();
|
|
|
|
this.y = hitObject.getScaledY();
|
|
|
|
this.sliderX = hitObject.getScaledSliderX();
|
|
|
|
this.sliderY = hitObject.getScaledSliderY();
|
2015-01-30 02:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the point on the curve at a value t.
|
|
|
|
* @param t the t value [0, 1]
|
|
|
|
* @return the point [x, y]
|
|
|
|
*/
|
|
|
|
public abstract float[] pointAt(float t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the full curve to the graphics context.
|
2015-04-08 08:05:12 +02:00
|
|
|
* @param color the color filter
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
2015-04-12 16:25:03 +02:00
|
|
|
public void draw(Color color) {
|
2015-04-13 04:33:20 +02:00
|
|
|
if (curve == null)
|
2015-04-12 16:25:03 +02:00
|
|
|
return;
|
2015-04-13 04:33:20 +02:00
|
|
|
|
2015-04-12 16:25:03 +02:00
|
|
|
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
|
|
|
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
|
|
|
for (int i = 0; i < curve.length; i++)
|
|
|
|
hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
|
|
|
|
for (int i = 0; i < curve.length; i++)
|
|
|
|
hitCircle.drawCentered(curve[i].x, curve[i].y, color);
|
|
|
|
}
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the angle of the first control point.
|
|
|
|
*/
|
|
|
|
public abstract float getEndAngle();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the angle of the last control point.
|
|
|
|
*/
|
|
|
|
public abstract float getStartAngle();
|
|
|
|
|
|
|
|
/**
|
2015-03-13 01:12:43 +01:00
|
|
|
* Returns the scaled x coordinate of the control point at index i.
|
|
|
|
* @param i the control point index
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
2015-03-13 01:12:43 +01:00
|
|
|
public float getX(int i) { return (i == 0) ? x : sliderX[i - 1]; }
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
2015-03-13 01:12:43 +01:00
|
|
|
* Returns the scaled y coordinate of the control point at index i.
|
|
|
|
* @param i the control point index
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
2015-03-13 01:12:43 +01:00
|
|
|
public float getY(int i) { return (i == 0) ? y : sliderY[i - 1]; }
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Linear interpolation of a and b at t.
|
|
|
|
*/
|
|
|
|
protected float lerp(float a, float b, float t) {
|
|
|
|
return a * (1 - t) + b * t;
|
|
|
|
}
|
|
|
|
}
|