calculate Smooth Rotation - Java java.lang

Java examples for java.lang:Math Calculation

Description

calculate Smooth Rotation

Demo Code


//package com.java2s;

public class Main {
    public static float calcSmoothRotation(float parRotation,
            float parTargetRotation, int parIterations, float parRange) {
        float i = 0;

        for (int j = 0; j < parIterations; j++) {
            i = parTargetRotation - parRotation;
            i += i < -180F ? 360F : i > 180F ? -360F : 0F;

            parRotation += i < -parRange ? -1F : i > parRange ? 1F : 0F;
            parRotation = clampWithMod(parRotation, 360F);
        }//from   w ww.j  a  va 2s .co m

        return parRotation;
    }

    public static float clampWithMod(float parFloat, float parMax) {
        return (parFloat + parMax) % parMax;
    }
}

Related Tutorials