Example usage for com.badlogic.gdx.math MathUtils PI

List of usage examples for com.badlogic.gdx.math MathUtils PI

Introduction

In this page you can find the example usage for com.badlogic.gdx.math MathUtils PI.

Prototype

float PI

To view the source code for com.badlogic.gdx.math MathUtils PI.

Click Source Link

Usage

From source file:com.agateau.pixelwheels.racer.SpinningComponent.java

License:Open Source License

public void start() {
    mActive = true;
    setGripEnabled(false);
    mOriginalAngle = mVehicle.getAngle();
    mTargetBodyAngle = mVehicle.getBody().getAngle() + 2 * MathUtils.PI;
}

From source file:com.agateau.utils.AgcMathUtils.java

License:Apache License

public static float normalizeAnglePiRad(float angle) {
    angle = normalizeAngleRad(angle);/*from  w w  w .  j ava  2  s .co  m*/
    if (angle > MathUtils.PI) {
        angle -= MathUtils.PI2;
    }
    return angle;
}

From source file:com.apptogo.roperace.custom.MyShapeRenderer.java

License:Apache License

/** Draws an arc using {@link ShapeType#Line} or {@link ShapeType#Filled}. */
public void arc(float x, float y, float radius, float start, float degrees, int segments) {
    if (segments <= 0)
        throw new IllegalArgumentException("segments must be > 0.");
    float colorBits = color.toFloatBits();
    float theta = (2 * MathUtils.PI * (degrees / 360.0f)) / segments;
    float cos = MathUtils.cos(theta);
    float sin = MathUtils.sin(theta);
    float cx = radius * MathUtils.cos(start * MathUtils.degreesToRadians);
    float cy = radius * MathUtils.sin(start * MathUtils.degreesToRadians);

    if (shapeType == ShapeType.Line) {
        check(ShapeType.Line, ShapeType.Filled, segments * 2 + 2);

        renderer.color(colorBits);//from  ww  w .j  a  v  a  2  s  . c  om
        renderer.vertex(x, y, 0);
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, 0);
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
            float temp = cx;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
        }
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, 0);
    } else {
        check(ShapeType.Line, ShapeType.Filled, segments * 3 + 3);

        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);
            renderer.vertex(x, y, 0);
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
            float temp = cx;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
        }
        renderer.color(colorBits);
        renderer.vertex(x, y, 0);
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, 0);
    }

    float temp = cx;
    cx = 0;
    cy = 0;
    renderer.color(colorBits);
    renderer.vertex(x + cx, y + cy, 0);
}

From source file:com.apptogo.roperace.custom.MyShapeRenderer.java

License:Apache License

/** Draws a circle using {@link ShapeType#Line} or {@link ShapeType#Filled}. */
public void circle(float x, float y, float radius, int segments) {
    if (segments <= 0)
        throw new IllegalArgumentException("segments must be > 0.");
    float colorBits = color.toFloatBits();
    float angle = 2 * MathUtils.PI / segments;
    float cos = MathUtils.cos(angle);
    float sin = MathUtils.sin(angle);
    float cx = radius, cy = 0;
    if (shapeType == ShapeType.Line) {
        check(ShapeType.Line, ShapeType.Filled, segments * 2 + 2);
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);// w ww . j  a v a  2 s  . c  om
            renderer.vertex(x + cx, y + cy, 0);
            float temp = cx;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
        }
        // Ensure the last segment is identical to the first.
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, 0);
    } else {
        check(ShapeType.Line, ShapeType.Filled, segments * 3 + 3);
        segments--;
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);
            renderer.vertex(x, y, 0);
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
            float temp = cx;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
        }
        // Ensure the last segment is identical to the first.
        renderer.color(colorBits);
        renderer.vertex(x, y, 0);
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, 0);
    }

    float temp = cx;
    cx = radius;
    cy = 0;
    renderer.color(colorBits);
    renderer.vertex(x + cx, y + cy, 0);
}

From source file:com.apptogo.roperace.custom.MyShapeRenderer.java

License:Apache License

/** Draws an ellipse using {@link ShapeType#Line} or {@link ShapeType#Filled}. */
public void ellipse(float x, float y, float width, float height, int segments) {
    if (segments <= 0)
        throw new IllegalArgumentException("segments must be > 0.");
    check(ShapeType.Line, ShapeType.Filled, segments * 3);
    float colorBits = color.toFloatBits();
    float angle = 2 * MathUtils.PI / segments;

    float cx = x + width / 2, cy = y + height / 2;
    if (shapeType == ShapeType.Line) {
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);/* www. j ava  2s  .  c om*/
            renderer.vertex(cx + (width * 0.5f * MathUtils.cos(i * angle)),
                    cy + (height * 0.5f * MathUtils.sin(i * angle)), 0);

            renderer.color(colorBits);
            renderer.vertex(cx + (width * 0.5f * MathUtils.cos((i + 1) * angle)),
                    cy + (height * 0.5f * MathUtils.sin((i + 1) * angle)), 0);
        }
    } else {
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);
            renderer.vertex(cx + (width * 0.5f * MathUtils.cos(i * angle)),
                    cy + (height * 0.5f * MathUtils.sin(i * angle)), 0);

            renderer.color(colorBits);
            renderer.vertex(cx, cy, 0);

            renderer.color(colorBits);
            renderer.vertex(cx + (width * 0.5f * MathUtils.cos((i + 1) * angle)),
                    cy + (height * 0.5f * MathUtils.sin((i + 1) * angle)), 0);
        }
    }
}

From source file:com.apptogo.roperace.custom.MyShapeRenderer.java

License:Apache License

/** Draws an ellipse using {@link ShapeType#Line} or {@link ShapeType#Filled}. */
public void ellipse(float x, float y, float width, float height, float rotation, int segments) {
    if (segments <= 0)
        throw new IllegalArgumentException("segments must be > 0.");
    check(ShapeType.Line, ShapeType.Filled, segments * 3);
    float colorBits = color.toFloatBits();
    float angle = 2 * MathUtils.PI / segments;

    rotation = MathUtils.PI * rotation / 180f;
    float sin = MathUtils.sin(rotation);
    float cos = MathUtils.cos(rotation);

    float cx = x + width / 2, cy = y + height / 2;
    float x1 = width * 0.5f;
    float y1 = 0;
    if (shapeType == ShapeType.Line) {
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);//from  w w w .j  a  v  a  2s  . c o m
            renderer.vertex(cx + cos * x1 - sin * y1, cy + sin * x1 + cos * y1, 0);

            x1 = (width * 0.5f * MathUtils.cos((i + 1) * angle));
            y1 = (height * 0.5f * MathUtils.sin((i + 1) * angle));

            renderer.color(colorBits);
            renderer.vertex(cx + cos * x1 - sin * y1, cy + sin * x1 + cos * y1, 0);
        }
    } else {
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);
            renderer.vertex(cx + cos * x1 - sin * y1, cy + sin * x1 + cos * y1, 0);

            renderer.color(colorBits);
            renderer.vertex(cx, cy, 0);

            x1 = (width * 0.5f * MathUtils.cos((i + 1) * angle));
            y1 = (height * 0.5f * MathUtils.sin((i + 1) * angle));

            renderer.color(colorBits);
            renderer.vertex(cx + cos * x1 - sin * y1, cy + sin * x1 + cos * y1, 0);
        }
    }
}

From source file:com.apptogo.roperace.custom.MyShapeRenderer.java

License:Apache License

/** Draws a cone using {@link ShapeType#Line} or {@link ShapeType#Filled}. */
public void cone(float x, float y, float z, float radius, float height, int segments) {
    if (segments <= 0)
        throw new IllegalArgumentException("segments must be > 0.");
    check(ShapeType.Line, ShapeType.Filled, segments * 4 + 2);
    float colorBits = color.toFloatBits();
    float angle = 2 * MathUtils.PI / segments;
    float cos = MathUtils.cos(angle);
    float sin = MathUtils.sin(angle);
    float cx = radius, cy = 0;
    if (shapeType == ShapeType.Line) {
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);//from   w ww . j  a va  2 s  .  c  om
            renderer.vertex(x + cx, y + cy, z);
            renderer.color(colorBits);
            renderer.vertex(x, y, z + height);
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, z);
            float temp = cx;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, z);
        }
        // Ensure the last segment is identical to the first.
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, z);
    } else {
        segments--;
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);
            renderer.vertex(x, y, z);
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, z);
            float temp = cx;
            float temp2 = cy;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, z);

            renderer.color(colorBits);
            renderer.vertex(x + temp, y + temp2, z);
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, z);
            renderer.color(colorBits);
            renderer.vertex(x, y, z + height);
        }
        // Ensure the last segment is identical to the first.
        renderer.color(colorBits);
        renderer.vertex(x, y, z);
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, z);
    }
    float temp = cx;
    float temp2 = cy;
    cx = radius;
    cy = 0;
    renderer.color(colorBits);
    renderer.vertex(x + cx, y + cy, z);
    if (shapeType != ShapeType.Line) {
        renderer.color(colorBits);
        renderer.vertex(x + temp, y + temp2, z);
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, z);
        renderer.color(colorBits);
        renderer.vertex(x, y, z + height);
    }
}

From source file:com.asha.vrlib.model.MDQuaternion.java

License:Apache License

/** Get the pitch euler angle in radians, which is the rotation around the x axis. Requires that this quaternion is normalized.
 * @return the rotation around the x axis in radians (between -(PI/2) and +(PI/2)) */
public float getPitchRad() {
    float w = q[0];
    float x = q[1];
    float y = q[2];
    float z = q[3];

    final int pole = getGimbalPole();
    return pole == 0 ? (float) Math.asin(MathUtils.clamp(2f * (w * x - z * y), -1f, 1f))
            : (float) pole * MathUtils.PI * 0.5f;
}

From source file:com.badlogic.gdx.tests.dragome.examples.GearsDemo.java

static void gear_angle(int i, int teeth, float[] ar) {
    float angle = i * 2.0f * MathUtils.PI / teeth;
    float da = 2.0f * MathUtils.PI / teeth / 4.0f;
    ar[0] = angle;//from  w  w  w.  j  a v  a  2s  .c o  m
    ar[1] = angle + 1.0f * da;
    ar[2] = angle + 2.0f * da;
    ar[3] = angle + 3.0f * da;
}

From source file:com.blastedstudios.ledge.ui.postprocessing.filters.CrtScreen.java

License:Apache License

public void setTime(float elapsedSecs) {
    this.elapsedSecs = elapsedSecs;
    setParam(Param.Time, (elapsedSecs % MathUtils.PI));
}