Java Code Examples for com.badlogic.gdx.math.MathUtils#PI

The following examples show how to use com.badlogic.gdx.math.MathUtils#PI . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RectangleCircleCollisionScreen.java    From ud406 with MIT License 6 votes vote down vote up
public RectangleCircleCollisionScreen() {
    startTime = TimeUtils.nanoTime();
    shapeRenderer = new ShapeRenderer();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    rectangles = new Array<Rectangle>(new Rectangle[]{
            new Rectangle(40, 40, 20, 20), // Middle
            new Rectangle(10, 40, 10, 20), // Left
            new Rectangle(70, 45, 20, 10) // Right
    });

    circles = new Array<OscillatingCircle>(new OscillatingCircle[]{
            new OscillatingCircle(50, 65, 7, 0, 40, 3), // High horizontal
            new OscillatingCircle(50, 35, 7, 0, 40, 3.1f), // Low horizontal
            new OscillatingCircle(50, 50, 3, MathUtils.PI / 4, 40, 5f), // Diagonal
            new OscillatingCircle(25, 50, 5, 0, 11, 7f), // Middle horizontal
    });
}
 
Example 2
Source File: RectangleCircleCollisionScreen.java    From ud406 with MIT License 6 votes vote down vote up
public RectangleCircleCollisionScreen() {
    startTime = TimeUtils.nanoTime();
    shapeRenderer = new ShapeRenderer();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    rectangles = new Array<Rectangle>(new Rectangle[]{
            new Rectangle(40, 40, 20, 20), // Middle
            new Rectangle(10, 40, 10, 20), // Left
            new Rectangle(70, 45, 20, 10) // Right
    });

    circles = new Array<OscillatingCircle>(new OscillatingCircle[]{
            new OscillatingCircle(50, 65, 7, 0, 40, 3), // High horizontal
            new OscillatingCircle(50, 35, 7, 0, 40, 3.1f), // Low horizontal
            new OscillatingCircle(50, 50, 3, MathUtils.PI / 4, 40, 5f), // Diagonal
            new OscillatingCircle(25, 50, 5, 0, 11, 7f), // Middle horizontal
    });
}
 
Example 3
Source File: MDQuaternion.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
/** 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;
}
 
Example 4
Source File: MDQuaternion.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
/** 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;
}
 
Example 5
Source File: MyShapeRenderer.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
/** 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);
			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);
		}
	}
}