Search in sources :

Example 1 with CubicBezierPoint

use of com.helospark.tactview.core.util.bezier.CubicBezierPoint in project tactview by helospark.

the class BezierSplineCurveEditor method onMouseDrag.

private boolean onMouseDrag(CurveEditorMouseRequest mouseEvent, boolean revertable) {
    if (dragged == null) {
        return false;
    }
    TreeMap<TimelinePosition, CubicBezierPoint> bezierValues = ((BezierDoubleInterpolator) mouseEvent.currentDoubleInterpolator).getBezierValues();
    CubicBezierPoint pointToModify = null;
    TimelinePosition positionToModify = null;
    int draggedIndex = dragged.draggedIndex;
    BezierPointType draggedPointType = dragged.draggedPointType;
    int i = 0;
    for (var entry : bezierValues.entrySet()) {
        if (i == draggedIndex) {
            pointToModify = entry.getValue();
            positionToModify = entry.getKey();
        }
        ++i;
    }
    if (pointToModify != null) {
        TimelinePosition newTime = positionToModify.add(new BigDecimal(mouseEvent.mouseDelta.x));
        double newValue = pointToModify.value + mouseEvent.mouseDelta.y;
        double newPosition = mouseEvent.remappedMousePosition.y;
        double relativeX = newTime.getSeconds().doubleValue() - positionToModify.getSeconds().doubleValue();
        double relativeY = newValue - pointToModify.value;
        Point relativePoint = new Point(relativeX, relativeY);
        if (draggedPointType == BezierPointType.IN) {
            commandInterpreter.synchronousSend(BezierCurveEditorPointChangeInOutPointCommand.builder().withToUpdate((BezierDoubleInterpolator) mouseEvent.currentDoubleInterpolator).withOriginalPosition(dragged.originalControlPointIn).withPositionToModify(positionToModify).withRevertable(revertable).withType(BezierPointType.IN).withNewPoint(pointToModify.controlPointIn.add(relativePoint)).withEffectParametersRepository(effectParametersRepository).withProviderId(mouseEvent.currentProvider.getId()).build());
        } else if (draggedPointType == BezierPointType.OUT) {
            commandInterpreter.synchronousSend(BezierCurveEditorPointChangeInOutPointCommand.builder().withToUpdate((BezierDoubleInterpolator) mouseEvent.currentDoubleInterpolator).withOriginalPosition(dragged.originalControlPointOut).withPositionToModify(positionToModify).withRevertable(revertable).withType(BezierPointType.OUT).withNewPoint(pointToModify.controlPointOut.add(relativePoint)).withEffectParametersRepository(effectParametersRepository).withProviderId(mouseEvent.currentProvider.getId()).build());
        } else {
            commandInterpreter.synchronousSend((BezierCurveEditorPointChangePointCommand.builder().withToUpdate((BezierDoubleInterpolator) mouseEvent.currentDoubleInterpolator).withPositionToModify(positionToModify).withRevertable(revertable).withNewPosition(newPosition).withEffectParametersRepository(effectParametersRepository).withProviderId(mouseEvent.currentProvider.getId()).withOriginalValue(dragged.originalValue).withOriginalPosition(dragged.originalPosition).withNewTime(newTime).build()));
        }
        return true;
    }
    return false;
}
Also used : CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BezierDoubleInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.bezier.BezierDoubleInterpolator) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) BigDecimal(java.math.BigDecimal)

Example 2 with CubicBezierPoint

use of com.helospark.tactview.core.util.bezier.CubicBezierPoint in project tactview by helospark.

the class StandardDoubleInterpolatorFactoryConfiguration method bezierDoubleInterpolator.

@Bean
public StandardDoubleInterpolatorFactory<?> bezierDoubleInterpolator() {
    return new StandardDoubleInterpolatorFactory<>("bezierDoubleInterpolator", BezierDoubleInterpolator.class, (previousProvider, previousInterpolator) -> {
        TreeMap<TimelinePosition, CubicBezierPoint> values = new TreeMap<>();
        double defaultValue = 0.0;
        if (previousInterpolator instanceof KeyframeSupportingDoubleInterpolator) {
            for (var entry : ((KeyframeSupportingDoubleInterpolator) previousInterpolator).getValues().entrySet()) {
                values.put(entry.getKey(), new CubicBezierPoint((Double) entry.getValue(), new Point(-1, 0), new Point(1, 0)));
            }
            defaultValue = ((KeyframeSupportingDoubleInterpolator) previousInterpolator).getDefaultValue();
        }
        BezierDoubleInterpolator result = new BezierDoubleInterpolator(defaultValue, values);
        if (previousInterpolator instanceof KeyframeSupportingDoubleInterpolator) {
            result.setUseKeyframes(((KeyframeSupportingDoubleInterpolator) previousInterpolator).isUsingKeyframes());
        }
        return result;
    });
}
Also used : CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TreeMap(java.util.TreeMap) KeyframeSupportingDoubleInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.KeyframeSupportingDoubleInterpolator) BezierDoubleInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.bezier.BezierDoubleInterpolator) Bean(com.helospark.lightdi.annotation.Bean)

Example 3 with CubicBezierPoint

use of com.helospark.tactview.core.util.bezier.CubicBezierPoint in project tactview by helospark.

the class BezierSplineCurveEditor method drawAdditionalUi.

@Override
public void drawAdditionalUi(CurveDrawRequest drawRequest) {
    TreeMap<TimelinePosition, CubicBezierPoint> bezierValues = ((BezierDoubleInterpolator) drawRequest.currentDoubleInterpolator).getBezierValues();
    int closeIndex = -1;
    BezierPointType closePointType = null;
    if (close != null) {
        closeIndex = close.draggedIndex;
        closePointType = close.draggedPointType;
    }
    GraphicsContext graphics = drawRequest.graphics;
    graphics.setFill(Color.GRAY);
    graphics.setStroke(Color.GRAY);
    int i = 0;
    for (var entry : bezierValues.entrySet()) {
        double secondValue = entry.getKey().getSeconds().doubleValue();
        Point actualPoint = new Point(secondValue, entry.getValue().value);
        Point absolueInPoint = entry.getValue().controlPointIn.add(actualPoint);
        Point absolueOutPoint = entry.getValue().controlPointOut.add(actualPoint);
        Point screenSpaceCenterPosition = remapPointToScreenSpace(drawRequest, actualPoint);
        if (i == closeIndex && BezierPointType.IN == closePointType) {
            graphics.setFill(Color.RED);
        } else {
            graphics.setFill(Color.GRAY);
        }
        drawControlPoint(drawRequest, screenSpaceCenterPosition, absolueInPoint);
        if (i == closeIndex && BezierPointType.OUT == closePointType) {
            graphics.setFill(Color.RED);
        } else {
            graphics.setFill(Color.GRAY);
        }
        drawControlPoint(drawRequest, screenSpaceCenterPosition, absolueOutPoint);
        if (i == closeIndex && BezierPointType.VALUE == closePointType) {
            graphics.setFill(Color.RED);
        } else {
            graphics.setFill(Color.BLUE);
        }
        drawPoint(graphics, screenSpaceCenterPosition);
        ++i;
    }
}
Also used : GraphicsContext(javafx.scene.canvas.GraphicsContext) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BezierDoubleInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.bezier.BezierDoubleInterpolator) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint)

Example 4 with CubicBezierPoint

use of com.helospark.tactview.core.util.bezier.CubicBezierPoint in project tactview by helospark.

the class BezierSplineCurveEditor method getElementUnderMouseOrNull.

private BezierMousePointDescriptor getElementUnderMouseOrNull(CurveEditorMouseRequest mouseEvent) {
    int i = 0;
    TreeMap<TimelinePosition, CubicBezierPoint> bezierValues = ((BezierDoubleInterpolator) mouseEvent.currentDoubleInterpolator).getBezierValues();
    for (var entry : bezierValues.entrySet()) {
        Point actualPoint = new Point(entry.getKey().getSeconds().doubleValue(), entry.getValue().value);
        Point actualPointInScreenSpace = remapPointToScreenSpace(mouseEvent, actualPoint);
        Point inPointInScreenSpace = remapPointToScreenSpace(mouseEvent, entry.getValue().controlPointIn.add(actualPoint));
        Point outPointInScreenSpace = remapPointToScreenSpace(mouseEvent, entry.getValue().controlPointOut.add(actualPoint));
        BezierMousePointDescriptor result = null;
        if (isClose(actualPointInScreenSpace, mouseEvent.screenMousePosition)) {
            result = new BezierMousePointDescriptor();
            result.draggedIndex = i;
            result.draggedPointType = BezierPointType.VALUE;
        } else if (isClose(outPointInScreenSpace, mouseEvent.screenMousePosition)) {
            result = new BezierMousePointDescriptor();
            result.draggedIndex = i;
            result.draggedPointType = BezierPointType.OUT;
        } else if (isClose(inPointInScreenSpace, mouseEvent.screenMousePosition)) {
            result = new BezierMousePointDescriptor();
            result.draggedIndex = i;
            result.draggedPointType = BezierPointType.IN;
        }
        if (result != null) {
            result.originalPosition = entry.getKey();
            result.originalValue = entry.getValue().value;
            result.originalControlPointIn = entry.getValue().controlPointIn;
            result.originalControlPointOut = entry.getValue().controlPointOut;
            return result;
        }
        ++i;
    }
    return null;
}
Also used : CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint) BezierDoubleInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.bezier.BezierDoubleInterpolator)

Example 5 with CubicBezierPoint

use of com.helospark.tactview.core.util.bezier.CubicBezierPoint in project tactview by helospark.

the class BezierDoubleInterpolator method cubicBezier.

// https://stackoverflow.com/questions/37642168/how-to-convert-quadratic-bezier-curve-code-into-cubic-bezier-curve/37642695#37642695
private double cubicBezier(TimelinePosition lowKey, TimelinePosition highKey, CubicBezierPoint lowElement, CubicBezierPoint highElement, double percent) {
    Point startPoint = new Point(lowKey.getSeconds().doubleValue(), lowElement.value);
    Point endPoint = new Point(highKey.getSeconds().doubleValue(), highElement.value);
    Point controlPoint = startPoint.add(lowElement.controlPointOut);
    Point secondControlPoint = endPoint.add(highElement.controlPointIn);
    double x1 = startPoint.x;
    double y1 = startPoint.y;
    double x2 = controlPoint.x;
    double y2 = controlPoint.y;
    double x3 = secondControlPoint.x;
    double y3 = secondControlPoint.y;
    double x4 = endPoint.x;
    double y4 = endPoint.y;
    double i = percent;
    // The Green Lines
    double xa = getPt(x1, x2, i);
    double ya = getPt(y1, y2, i);
    double xb = getPt(x2, x3, i);
    double yb = getPt(y2, y3, i);
    double xc = getPt(x3, x4, i);
    double yc = getPt(y3, y4, i);
    // The Blue Line
    double xm = getPt(xa, xb, i);
    double ym = getPt(ya, yb, i);
    double xn = getPt(xb, xc, i);
    double yn = getPt(yb, yc, i);
    // The Black Dot
    double x = getPt(xm, xn, i);
    double y = getPt(ym, yn, i);
    return y;
}
Also used : Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) CubicBezierPoint(com.helospark.tactview.core.util.bezier.CubicBezierPoint)

Aggregations

CubicBezierPoint (com.helospark.tactview.core.util.bezier.CubicBezierPoint)7 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)5 Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)5 BezierDoubleInterpolator (com.helospark.tactview.core.timeline.effect.interpolation.interpolator.bezier.BezierDoubleInterpolator)4 Bean (com.helospark.lightdi.annotation.Bean)1 KeyframeSupportingDoubleInterpolator (com.helospark.tactview.core.timeline.effect.interpolation.interpolator.KeyframeSupportingDoubleInterpolator)1 BigDecimal (java.math.BigDecimal)1 TreeMap (java.util.TreeMap)1 GraphicsContext (javafx.scene.canvas.GraphicsContext)1