Example usage for com.badlogic.gdx.math Interpolation apply

List of usage examples for com.badlogic.gdx.math Interpolation apply

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Interpolation apply.

Prototype

public float apply(float start, float end, float a) 

Source Link

Usage

From source file:com.quadbits.gdxhelper.controllers.PeriodicRotationController.java

License:Apache License

@Override
public void control(Actor actor, float deltaSeconds) {
    long deltaMillis = (long) (deltaSeconds * 1000);
    timePeriodManager.update(deltaMillis);
    float angle;//from   w  ww .j ava 2  s .  c o m
    float normalizedValue;
    int subPeriod = timePeriodManager.getCurrentSubPeriod();

    // Rotate up
    if (subPeriod == rotateUpSubPeriod) {
        normalizedValue = timePeriodManager.getNormalizedCurrentSubPeriodTime();
        Interpolation interpolation = Interpolation.linear;
        if (this.interpolation != null) {
            interpolation = this.interpolation;
        }
        angle = interpolation.apply(minAngle, maxAngle, normalizedValue);
    }

    // Stall up
    else if (subPeriod == stallUpSubPeriod) {
        angle = maxAngle;
    }

    // Rotate down
    else if (subPeriod == rotateDownSubPeriod) {
        normalizedValue = timePeriodManager.getNormalizedCurrentSubPeriodTime();
        Interpolation interpolation = Interpolation.linear;
        if (this.interpolation != null) {
            interpolation = this.interpolation;
        }
        angle = interpolation.apply(maxAngle, minAngle, normalizedValue);
    }

    // Stall up
    else {
        angle = minAngle;
    }

    actor.setRotation(angle);
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.CharSequenceInterpolator.java

License:Apache License

/** @param seq the {@code CharSequence} to interpolate
 *  @param time the {@link #time}//w  w w .  j  a v  a 2 s .  c o  m
 *  @param charsPerSecond the {@link #charsPerSecond}
 *  @param beginIndex the index at which the returned {@code CharSequence} should start
 *  @param endIndex the index at which the returned {@code CharSequence} should end if the given {@code Interpolation} {@link Interpolation#apply(float, float, float) applied} 1
 *  @param interpolation the {@code Interpolation} to use
 *  @return a {@link CharSequence#subSequence(int, int) subsequence} representing the given {@code seq} from {@code beginIndex} to {@code endIndex} with its {@link CharSequence#length() length} interpolated using the given {@code interpolation} */
public static CharSequence interpolate(CharSequence seq, float time, float charsPerSecond, int beginIndex,
        int endIndex, Interpolation interpolation) {
    return seq
            .subSequence(beginIndex,
                    (int) MathUtils.clamp(
                            MathUtils.replaceNaN(interpolation.apply(beginIndex, endIndex,
                                    linear(time, charsPerSecond, endIndex - beginIndex)), 0),
                            beginIndex, endIndex));
}

From source file:mobi.shad.s3lib.gfx.g2d.BitmapFontAnim.java

License:Apache License

/**
 * @param time//from  w  ww .j a  v  a 2  s .co m
 * @param start
 * @param end
 * @param interpolation
 */
public void size(float time, float start, float end, Interpolation interpolation) {
    time = S3Math.fastCos(time);
    float range = interpolation.apply(start, end, time) / 2;

    int idx = 0;
    for (int i = 0; i < textLengh; ++i) {

        //
        // Getting position value
        //
        tempX = copyVertices[idx];
        tempY = copyVertices[idx + 1];

        tempX2 = copyVertices[idx + 10];
        tempY2 = copyVertices[idx + 6];

        tempWidth = tempX2 - tempX;
        tempHeight = tempY2 - tempY;

        tempCenterX = (tempX2 + tempX) / 2;
        tempCenterY = (tempY2 + tempY) / 2;

        //
        // Calculate new value
        //
        tempX = tempCenterX - range;
        tempX2 = tempCenterX + range;

        tempY = tempCenterY - range;
        tempY2 = tempCenterY + range;

        //
        // Setting new value on oryginal vertext array
        //
        vertices[idx] = tempX;
        vertices[idx + 1] = tempY;

        vertices[idx + 5] = tempX;
        vertices[idx + 6] = tempY2;

        vertices[idx + 10] = tempX2;
        vertices[idx + 11] = tempY2;

        vertices[idx + 15] = tempX2;
        vertices[idx + 16] = tempY;

        idx = idx + 20;
    }
}

From source file:mobi.shad.s3lib.gfx.g2d.BitmapFontAnim.java

License:Apache License

/**
 * @param time/*from   w ww . j  av  a  2  s . c  om*/
 * @param step
 * @param start
 * @param end
 * @param interpolation
 */
public void wobblingSize(float time, float step, float start, float end, Interpolation interpolation) {

    float range = 0;
    float fxTime = time;
    int idx = 0;
    for (int i = 0; i < textLengh; ++i) {

        fxTime = fxTime + step;
        time = S3Math.fastCos(fxTime);
        range = interpolation.apply(start, end, time) / 2;

        //
        // Getting position value
        //
        tempX = copyVertices[idx];
        tempY = copyVertices[idx + 1];

        tempX2 = copyVertices[idx + 10];
        tempY2 = copyVertices[idx + 6];

        tempWidth = tempX2 - tempX;
        tempHeight = tempY2 - tempY;

        tempCenterX = (tempX2 + tempX) / 2;
        tempCenterY = (tempY2 + tempY) / 2;

        //
        // Calculate new value
        //
        tempX = tempCenterX - range;
        tempX2 = tempCenterX + range;

        tempY = tempCenterY - range;
        tempY2 = tempCenterY + range;

        //
        // Setting new value on oryginal vertext array
        //
        vertices[idx] = tempX;
        vertices[idx + 1] = tempY;

        vertices[idx + 5] = tempX;
        vertices[idx + 6] = tempY2;

        vertices[idx + 10] = tempX2;
        vertices[idx + 11] = tempY2;

        vertices[idx + 15] = tempX2;
        vertices[idx + 16] = tempY;

        idx = idx + 20;
    }
}

From source file:mobi.shad.s3lib.gfx.g2d.BitmapFontAnim.java

License:Apache License

/**
 * /*  w w w  . j a va  2s .c o  m*/
 * @param time
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @param interpolation
 */
public void position(float time, float startX, float startY, float endX, float endY,
        Interpolation interpolation) {

    float timeX = S3Math.fastCos(time);
    float timeY = S3Math.fastSin(time);
    float rangeX = interpolation.apply(startX, endX, timeX);
    float rangeY = interpolation.apply(startY, endY, timeY);

    int idx = 0;
    for (int i = 0; i < textLengh; ++i) {

        //
        // Getting position value
        //
        tempX = copyVertices[idx];
        tempY = copyVertices[idx + 1];

        tempX2 = copyVertices[idx + 10];
        tempY2 = copyVertices[idx + 6];

        tempWidth = tempX2 - tempX;
        tempHeight = tempY2 - tempY;

        tempCenterX = (tempX2 + tempX) / 2;
        tempCenterY = (tempY2 + tempY) / 2;

        //
        // Calculate new value
        //
        tempX = tempX + rangeX;
        tempX2 = tempX2 + rangeX;

        tempY = tempY + rangeY;
        tempY2 = tempY2 + rangeY;

        //
        // Setting new value on oryginal vertext array
        //
        vertices[idx] = tempX;
        vertices[idx + 1] = tempY;

        vertices[idx + 5] = tempX;
        vertices[idx + 6] = tempY2;

        vertices[idx + 10] = tempX2;
        vertices[idx + 11] = tempY2;

        vertices[idx + 15] = tempX2;
        vertices[idx + 16] = tempY;

        idx = idx + 20;
    }
}

From source file:mobi.shad.s3lib.gfx.g2d.BitmapFontAnim.java

License:Apache License

/**
 *
 * @param time/*from  w w  w .  jav  a  2 s  .co m*/
 * @param stepX
 * @param stepY
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @param interpolation
 */
public void wobblingPosition(float time, float stepX, float stepY, float startX, float startY, float endX,
        float endY, Interpolation interpolation) {

    float timeX = time;
    float timeY = time;
    float rangeX = 0;
    float rangeY = 0;
    float impX = 0;
    float impY = 0;

    int idx = 0;
    for (int i = 0; i < textLengh; ++i) {

        timeX = timeX + stepX;
        timeY = timeY + stepY;
        impX = S3Math.fastCos(timeX);
        impY = S3Math.fastSin(timeY);
        rangeX = interpolation.apply(startX, endX, impX);
        rangeY = interpolation.apply(startY, endY, impY);

        //
        // Getting position value
        //
        tempX = copyVertices[idx];
        tempY = copyVertices[idx + 1];

        tempX2 = copyVertices[idx + 10];
        tempY2 = copyVertices[idx + 6];

        tempWidth = tempX2 - tempX;
        tempHeight = tempY2 - tempY;

        tempCenterX = (tempX2 + tempX) / 2;
        tempCenterY = (tempY2 + tempY) / 2;

        //
        // Calculate new value
        //
        tempX = tempX + rangeX;
        tempX2 = tempX2 + rangeX;

        tempY = tempY + rangeY;
        tempY2 = tempY2 + rangeY;

        //
        // Setting new value on oryginal vertext array
        //
        vertices[idx] = tempX;
        vertices[idx + 1] = tempY;

        vertices[idx + 5] = tempX;
        vertices[idx + 6] = tempY2;

        vertices[idx + 10] = tempX2;
        vertices[idx + 11] = tempY2;

        vertices[idx + 15] = tempX2;
        vertices[idx + 16] = tempY;

        idx = idx + 20;
    }
}

From source file:mobi.shad.s3lib.gfx.g2d.BitmapFontAnim.java

License:Apache License

/**
 *
 * @param time//from ww w  . ja  va  2  s  . c  o m
 * @param stepSizeX
 * @param stepSizeY
 * @param stepPosX
 * @param stepPosY
 * @param startSizeX
 * @param startSizeY
 * @param endSizeX
 * @param endSizeY
 * @param startPosX
 * @param startPosY
 * @param endPosX
 * @param endPosY
 * @param interpolationSize
 * @param interpolationPosistion
 */
public void wobblingSizeAndPosition(float time, float stepSizeX, float stepSizeY, float stepPosX,
        float stepPosY, float startSizeX, float startSizeY, float endSizeX, float endSizeY, float startPosX,
        float startPosY, float endPosX, float endPosY, Interpolation interpolationSize,
        Interpolation interpolationPosistion) {

    float deltaTimeSizeX = time;
    float deltaTimeSizeY = time;
    float deltaTimePosX = time;
    float deltaTimePosY = time;
    float impSizeX = 0;
    float impSizeY = 0;
    float impPosX = 0;
    float impPosY = 0;

    int idx = 0;
    for (int i = 0; i < textLengh; ++i) {
        deltaTimeSizeX = deltaTimeSizeX + stepSizeX;
        deltaTimeSizeY = deltaTimeSizeY + stepSizeY;
        deltaTimePosX = deltaTimePosX + stepPosX;
        deltaTimePosY = deltaTimePosY + stepPosY;
        impSizeX = interpolationSize.apply(startSizeX, endSizeX, S3Math.fastCos(deltaTimeSizeX)) / 2;
        impSizeY = interpolationSize.apply(startSizeY, endSizeY, S3Math.fastSin(deltaTimeSizeY)) / 2;
        impPosX = interpolationPosistion.apply(startPosX, endPosX, S3Math.fastCos(deltaTimePosX));
        impPosY = interpolationPosistion.apply(startPosY, endPosY, S3Math.fastSin(deltaTimePosY));

        //
        // Getting position value
        //
        tempX = copyVertices[idx];
        tempY = copyVertices[idx + 1];

        tempX2 = copyVertices[idx + 10];
        tempY2 = copyVertices[idx + 6];

        tempWidth = tempX2 - tempX;
        tempHeight = tempY2 - tempY;

        tempCenterX = (tempX2 + tempX) / 2;
        tempCenterY = (tempY2 + tempY) / 2;

        //
        // Calculate new value
        //
        tempX = tempX + impPosX - impSizeX;
        tempX2 = tempX2 + impPosX + impSizeX;

        tempY = tempY + impPosY - impSizeY;
        tempY2 = tempY2 + impPosY + impSizeY;

        //
        // Setting new value on oryginal vertext array
        //
        vertices[idx] = tempX;
        vertices[idx + 1] = tempY;

        vertices[idx + 5] = tempX;
        vertices[idx + 6] = tempY2;

        vertices[idx + 10] = tempX2;
        vertices[idx + 11] = tempY2;

        vertices[idx + 15] = tempX2;
        vertices[idx + 16] = tempY;

        idx = idx + 20;
    }
}

From source file:mobi.shad.s3lib.gfx.g2d.SolidFont.java

License:Apache License

/**
 * @param deltaTime/*from  www  .  j  a  v  a 2s.  co  m*/
 * @param start
 * @param end
 * @param interpolation
 */
public void animeSize(float deltaTime, float start, float end, Interpolation interpolation) {
    deltaTime = S3Math.fastCos(deltaTime);
    float imp = interpolation.apply(start, end, deltaTime) / 2;
    for (int i = 0; i < textLengh; ++i) {
        tmpCh = chars.get(i);
        tmpCh.x = (int) (tmpCh.centerX - imp);
        tmpCh.y = (int) (tmpCh.centerY - imp);
        tmpCh.width = (int) (imp * 2);
        tmpCh.height = (int) (imp * 2);
    }
}

From source file:mobi.shad.s3lib.gfx.g2d.SolidFont.java

License:Apache License

/**
 * @param deltaTime/*from w w w .java  2  s .  c om*/
 * @param step
 * @param start
 * @param end
 * @param interpolation
 */
public void animeWobbingSize(float deltaTime, float step, float start, float end, Interpolation interpolation) {
    float imp = 0;
    for (int i = 0; i < textLengh; ++i, deltaTime = deltaTime + step) {
        imp = interpolation.apply(start, end, S3Math.fastCos(deltaTime)) / 2;
        tmpCh = chars.get(i);
        tmpCh.x = (int) (tmpCh.centerX - imp);
        tmpCh.y = (int) (tmpCh.centerY - imp);
        tmpCh.width = (int) (imp * 2);
        tmpCh.height = (int) (imp * 2);
    }
}

From source file:mobi.shad.s3lib.gfx.g2d.SolidFont.java

License:Apache License

/**
 * @param deltaTime/*ww w.ja va  2 s . co  m*/
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @param interpolation
 */
public void animePosistion(float deltaTime, float startX, float startY, float endX, float endY,
        Interpolation interpolation) {
    float deltaTimeX = S3Math.fastCos(deltaTime);
    float deltaTimeY = S3Math.fastSin(deltaTime);
    float impX = interpolation.apply(startX, endX, deltaTimeX);
    float impY = interpolation.apply(startY, endY, deltaTimeY);
    for (int i = 0; i < textLengh; ++i) {
        tmpCh = chars.get(i);
        tmpCh.x = (int) (tmpCh.centerX - impX);
        tmpCh.y = (int) (tmpCh.centerY - impY);
    }
}