Home Game Development libgdx – The right way to hold observe of digital camera’s rotation whereas it is being rotated?

libgdx – The right way to hold observe of digital camera’s rotation whereas it is being rotated?

0
libgdx – The right way to hold observe of digital camera’s rotation whereas it is being rotated?

[ad_1]

Why do not you merely have a variable that shops your quantity rotated?

personal float totRot;   

/** Rotate digital camera by the desired levels.
 *
 * @param levels */
public void rotate(closing float levels) {
    Vector3 axis = Vector3.Z; /* Or no matter axis */
    digital camera.rotate(axis, levels);
    totRot += levels; // Monitor quantity rotated
}

/** Rotates the digital camera to the desired levels.
 *
 * @param levels */
public void rotateTo(closing float levels) {
    rotate(levels - totRot);
}

To interpolate the rotation over time you should use a helper class (untested, constructor and getters / setters omitted):

public class CameraRotator {
    personal Digital camera digital camera;
    personal Vector3 axis;
    personal Interpolation interpolation;

    personal float startRot;
    personal float rotAmount;
    personal float totRot;

    personal float rotTime;
    personal float timeCounter;

    personal boolean rotationFinished;

    public void replace(closing float delta) {
        if (rotationFinished)
            return;

        /* Increment time spent */
        timeCounter += delta;
        /* Calculate progress */
        float alpha = timeCounter / rotTime;
        alpha = MathUtils.clamp(alpha, 0, 1);

        /* Interpolate rotation utilizing alpha (progress) */
        rotateTo(interpolation.apply(startRot, rotAmount, alpha));

        /* If (alpha == 1) we're completed. */
        if (alpha == 1) {
            timeCounter = 0;
            rotationFinished = true;
        }
    }

    /** Rotate digital camera by the desired levels within the specified
     * time.
     *
     * @param levels
     * @param time */
    public void startRotation(closing float levels, closing float time) {
        startRot = totRot;
        rotAmount = levels;
        rotTime = time;
        rotationFinished = false;
    }

    /** Rotate digital camera by the desired levels.
     *
     * @param levels */
    personal void rotate(closing float levels) {
        digital camera.rotate(axis, levels);
        totRot += levels; // Monitor quantity rotated
    }

    /** Rotates the digital camera to the desired levels.
     *
     * @param levels */
    personal void rotateTo(closing float levels) {
        rotate(levels - totRot);
    }
}

In fact for those who do not want the interpolation over time and plan on immediately rotating the digital camera the primary technique ought to work simply positive.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here