List of usage examples for com.badlogic.gdx.math MathUtils PI2
float PI2
To view the source code for com.badlogic.gdx.math MathUtils PI2.
Click Source Link
From source file:CB_UI_Base.graphics.CircleDrawable.java
License:Open Source License
private void createTriangles() { // calculate segment count double alpha = (360 * MIN_SEGMENTH_LENGTH) / (MathUtils.PI2 * RADIUS); SEGMENTE = Math.max(MIN_SEGMENTH_COUNT, (int) (360 / alpha)); // calculate theta step double thetaStep = (MathUtils.PI2 / SEGMENTE); if (PAINT.getGL_Style() == GL_Style.FILL) { // initialize arrays VERTICES = new float[(SEGMENTE + 1) * 2]; TRIANGLES = new short[(SEGMENTE) * 3]; int index = 0; // first point is the center point VERTICES[index++] = X;/*from ww w.ja v a 2 s . c o m*/ VERTICES[index++] = Y; int triangleIndex = 0; int verticeIdex = 1; boolean beginnTriangles = false; for (double i = 0; index < (SEGMENTE + 1) * 2; i += thetaStep) { VERTICES[index++] = (float) (X + RADIUS * Math.cos(i)); VERTICES[index++] = (float) (Y + RADIUS * Math.sin(i)); if (!beginnTriangles) { if (index % 6 == 0) beginnTriangles = true; } if (beginnTriangles) { TRIANGLES[triangleIndex++] = 0; TRIANGLES[triangleIndex++] = (short) verticeIdex++; TRIANGLES[triangleIndex++] = (short) verticeIdex; } } // last Triangle TRIANGLES[triangleIndex++] = 0; TRIANGLES[triangleIndex++] = (short) verticeIdex++; TRIANGLES[triangleIndex++] = (short) 1; } else { VERTICES = new float[(SEGMENTE) * 4]; TRIANGLES = new short[(SEGMENTE) * 6]; float halfStrokeWidth = (PAINT.strokeWidth) / 2; float radius1 = RADIUS - halfStrokeWidth; float radius2 = RADIUS + halfStrokeWidth; int index = 0; int triangleIndex = 0; int verticeIdex = 0; boolean beginnTriangles = false; for (float i = 0; index < (SEGMENTE * 4); i += thetaStep) { VERTICES[index++] = X + radius1 * MathUtils.cos(i); VERTICES[index++] = Y + radius1 * MathUtils.sin(i); VERTICES[index++] = X + radius2 * MathUtils.cos(i); VERTICES[index++] = Y + radius2 * MathUtils.sin(i); if (!beginnTriangles) { if (index % 8 == 0) beginnTriangles = true; } if (beginnTriangles) { TRIANGLES[triangleIndex++] = (short) verticeIdex++; TRIANGLES[triangleIndex++] = (short) verticeIdex++; TRIANGLES[triangleIndex++] = (short) verticeIdex--; TRIANGLES[triangleIndex++] = (short) verticeIdex++; TRIANGLES[triangleIndex++] = (short) verticeIdex++; TRIANGLES[triangleIndex++] = (short) verticeIdex--; } } // last two Triangles TRIANGLES[triangleIndex++] = (short) verticeIdex++; TRIANGLES[triangleIndex++] = (short) verticeIdex; TRIANGLES[triangleIndex++] = (short) 0; TRIANGLES[triangleIndex++] = (short) 0; TRIANGLES[triangleIndex++] = (short) 1; TRIANGLES[triangleIndex++] = (short) verticeIdex; } }
From source file:CB_UI_Base.graphics.Geometry.Circle.java
License:Open Source License
/** * Calculate the vertices of this circle with a minimum segment length of 10. <br> * OR a minimum segment count of 18. <br> * <br>/* w w w . jav a 2s . c om*/ * For every segment are compute a triangle from the segment start, end and the center of this circle. */ public void Compute() { if (!isDirty) return; // Nothing todo // calculate segment count double alpha = (360 * MIN_CIRCLE_SEGMENTH_LENGTH) / (MathUtils.PI2 * radius); int segmente = Math.max(MIN_SEG, (int) (360 / alpha)); // calculate theta step double thetaStep = (MathUtils.PI2 / segmente); // initialize arrays vertices = new float[(segmente + 1) * 2]; triangleIndices = new short[(segmente) * 3]; int index = 0; // first point is the center point vertices[index++] = centerX; vertices[index++] = centerY; int triangleIndex = 0; short verticeIdex = 1; boolean beginnTriangles = false; for (float i = 0; index < (segmente + 1) * 2; i += thetaStep) { vertices[index++] = centerX + radius * MathUtils.cos(i); vertices[index++] = centerY + radius * MathUtils.sin(i); if (!beginnTriangles) { if (index % 6 == 0) beginnTriangles = true; } if (beginnTriangles) { triangleIndices[triangleIndex++] = 0; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex; } } // last triangle triangleIndices[triangleIndex++] = 0; triangleIndices[triangleIndex++] = verticeIdex; triangleIndices[triangleIndex++] = 1; isDirty = false; }
From source file:CB_UI_Base.graphics.Geometry.CircularSegment.java
License:Open Source License
/** * Calculate the vertices of this circle with a minimum segment length of 10. <br> * OR a minimum segment count of 18. <br> * <br>/* ww w.ja va2 s .co m*/ * For every segment are compute a triangle from the segment start, end and the center of this circle. */ @Override public void Compute() { if (!isDirty) return; // Nothing todo chkStartEnd(); // calculate segment count double alpha = (360 * MIN_CIRCLE_SEGMENTH_LENGTH) / (MathUtils.PI2 * radius); int segmente = Math.max(MIN_CIRCLE_SEGMENTH_COUNT, (int) (360 / alpha)); // calculate beginn and end float length = end - start; segmente = (int) ((segmente * (Math.abs(length) / 360) + 0.5)); float thetaBeginn = start; float thetaEnd = end; // calculate theta step double thetaStep = length / segmente; segmente++; // initialize arrays vertices = new float[(segmente + 1) * 2]; triangleIndices = new short[(segmente) * 3]; int index = 0; // first point is the center point vertices[index++] = centerX; vertices[index++] = centerY; int triangleIndex = 0; short verticeIdex = 1; boolean beginnTriangles = false; for (float i = thetaBeginn; !(i > thetaEnd); i += thetaStep) { float rad = MathUtils.degreesToRadians * i; vertices[index++] = centerX + radius * MathUtils.cos(rad); vertices[index++] = centerY + radius * MathUtils.sin(rad); if (!beginnTriangles) { if (index % 6 == 0) beginnTriangles = true; } if (beginnTriangles) { triangleIndices[triangleIndex++] = 0; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex; } } // last triangle // triangleIndices[triangleIndex++] = 0; // triangleIndices[triangleIndex++] = verticeIdex; // triangleIndices[triangleIndex++] = 1; isDirty = false; }
From source file:CB_UI_Base.graphics.Geometry.Ring.java
License:Open Source License
/** * Calculate the vertices of this circle with a minimum segment length of 10. <br> * OR a minimum segment count of 18. <br> * <br>// w w w.j ava 2 s . c o m * For every segment are compute a triangle from the segment start, end and the center of this circle. */ public void Compute() { if (!isDirty) return; // Nothing todo // calculate segment count double alpha = (360 * MIN_CIRCLE_SEGMENTH_LENGTH) / (MathUtils.PI2 * outerRadius); int segmente = Math.max(MIN_CIRCLE_SEGMENTH_COUNT, (int) (360 / alpha)); // calculate theta step double thetaStep = (MathUtils.PI2 / segmente); // initialize arrays vertices = new float[(segmente) * 4]; triangleIndices = new short[(segmente) * 6]; // float halfStrokeWidth = (PAINT.strokeWidth) / 2; int index = 0; int triangleIndex = 0; short verticeIdex = 0; boolean beginnTriangles = false; for (float i = 0; index < (segmente * 4); i += thetaStep) { vertices[index++] = centerX + innerRadius * MathUtils.cos(i); vertices[index++] = centerY + innerRadius * MathUtils.sin(i); vertices[index++] = centerX + outerRadius * MathUtils.cos(i); vertices[index++] = centerY + outerRadius * MathUtils.sin(i); if (!beginnTriangles) { if (index % 8 == 0) beginnTriangles = true; } if (beginnTriangles) { triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex--; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex--; } } // last two Triangles triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex; triangleIndices[triangleIndex++] = 0; triangleIndices[triangleIndex++] = 0; triangleIndices[triangleIndex++] = 1; triangleIndices[triangleIndex++] = verticeIdex; isDirty = false; }
From source file:CB_UI_Base.graphics.Geometry.RingSegment.java
License:Open Source License
/** * Calculate the vertices of this circle with a minimum segment length of 10. <br> * OR a minimum segment count of 18. <br> * <br>//from w w w. j a va 2 s . co m * For every segment are compute a triangle from the segment start, end and the center of this circle. */ @Override public void Compute() { if (!isDirty) return; // Nothing todo // calculate segment count double alpha = (360 * MIN_CIRCLE_SEGMENTH_LENGTH) / (MathUtils.PI2 * outerRadius); if (start > end) { alpha *= -1; } int segmente = (int) (((end - start) / alpha) + 1); // calculate theta step double thetaStep = alpha; // initialize arrays vertices = new float[(segmente + 1) * 4]; triangleIndices = new short[(segmente) * 6]; // float halfStrokeWidth = (PAINT.strokeWidth) / 2; int index = 0; int triangleIndex = 0; short verticeIdex = 0; boolean beginnTriangles = false; for (float i = start; index < ((segmente + 1) * 4); i += thetaStep) { if (i > end) i = end; vertices[index++] = centerX + innerRadius * MathUtils.cos(i * MathUtils.degRad); vertices[index++] = centerY + innerRadius * MathUtils.sin(i * MathUtils.degRad); vertices[index++] = centerX + outerRadius * MathUtils.cos(i * MathUtils.degRad); vertices[index++] = centerY + outerRadius * MathUtils.sin(i * MathUtils.degRad); if (!beginnTriangles) { if (index % 8 == 0) beginnTriangles = true; } if (beginnTriangles) { triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex--; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex--; } } isDirty = false; }
From source file:com.agateau.utils.AgcMathUtils.java
License:Apache License
public static float normalizeAngleRad(float angle) { while (angle < 0) { angle += MathUtils.PI2; }//from w w w .ja v a 2s . c o m return angle % MathUtils.PI2; }
From source file:com.agateau.utils.AgcMathUtils.java
License:Apache License
public static float normalizeAnglePiRad(float angle) { angle = normalizeAngleRad(angle);//w w w .j av a2s.com if (angle > MathUtils.PI) { angle -= MathUtils.PI2; } return angle; }
From source file:com.asha.vrlib.model.MDQuaternion.java
License:Apache License
/** Sets the quaternion components from the given axis and angle around that axis. * @param x X direction of the axis// www . j a va2 s . c o m * @param y Y direction of the axis * @param z Z direction of the axis * @param radians The angle in radians * @return This quaternion for chaining. */ public void setFromAxisRad(final float x, final float y, final float z, final float radians) { float d = MDVector3D.len(x, y, z); if (d == 0f) { idt(); return; } d = 1f / d; float l_ang = radians < 0 ? MathUtils.PI2 - (-radians % MathUtils.PI2) : radians % MathUtils.PI2; float l_sin = (float) Math.sin(l_ang / 2); float l_cos = (float) Math.cos(l_ang / 2); this.set(l_cos, d * x * l_sin, d * y * l_sin, d * z * l_sin); this.nor(); }
From source file:com.cyphercove.dayinspace.gameplayscene.rendering.EntityActor.java
License:Apache License
public EntityActor(ObjectMap<String, com.cyphercove.dayinspace.shared.Sprite> library) { this.library = library; floatPhase = MathUtils.random() * MathUtils.PI2; }
From source file:com.cyphercove.dayinspace.gameplayscene.rendering.EntityActor.java
License:Apache License
public void act(float delta) { super.act(delta); spriteAge += delta;//from w w w. j a v a2 s . c o m //float offset floatTime += delta; float angle = 90 + 20 * MathUtils.sin(MathUtils.PI2 * 0.125f * floatTime + 3 + floatPhase); float radius = 2f * MathUtils.sin(MathUtils.PI2 * 0.4f * floatTime + floatPhase); floatOffset.set(radius, 0).rotate(angle); }