Java Code Examples for com.badlogic.gdx.math.MathUtils#PI2
The following examples show how to use
com.badlogic.gdx.math.MathUtils#PI2 .
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: BulletFollowPathTest.java From gdx-ai with Apache License 2.0 | 6 votes |
/** Creates a random path which is bound by rectangle described by the min/max values */ private static Array<Vector3> createRandomPath (int numWaypoints, float minX, float minY, float maxX, float maxY, float height) { Array<Vector3> wayPoints = new Array<Vector3>(); float midX = (maxX + minX) / 2f; float midY = (maxY + minY) / 2f; float smaller = Math.min(midX, midY); float spacing = MathUtils.PI2 / numWaypoints; for (int i = 0; i < numWaypoints; i++) { float radialDist = MathUtils.random(smaller * 0.2f, smaller); tmpVector2.set(radialDist, 0.0f); // rotates the specified vector angle rads around the origin // init and rotate the transformation matrix tmpMatrix3.idt().rotateRad(i * spacing); // now transform the object's vertices tmpVector2.mul(tmpMatrix3); wayPoints.add(new Vector3(tmpVector2.x, height, tmpVector2.y)); } return wayPoints; }
Example 2
Source File: ShapeDrawerTest.java From shapedrawer with MIT License | 6 votes |
void refreshPolygonVertices() { if (2*sides!=vertices.length) vertices = new float[2*sides]; srPreview.localToStageCoordinates(v.set(srPreview.getWidth(), srPreview.getHeight()).scl(0.5f)); int srX = (int) v.x, srY = (int) v.y; preview.localToStageCoordinates(v.set(preview.getWidth(), preview.getHeight()).scl(0.5f)); int X = (int) v.x, Y = (int) v.y; float angleInterval = MathUtils.PI2 / sides; float xRadius = anchor.dst(X, Y); float rotation = v.set(anchor).sub(X, Y).angleRad(); float sin = (float) Math.sin(rotation), cos = (float) Math.cos(rotation); v2.set(1, 0); for (int i = 0; i < 2*sides; i+=2) { float x = v2.x*xRadius, y = v2.y*200; vertices[i] = x*cos-y*sin + srX; vertices[i+1] = x*sin+y*cos + srY; v2.rotateRad(angleInterval); } triangles = triangulator.computeTriangles(vertices); }
Example 3
Source File: DefensiveCircleFormationPattern.java From gdx-ai with Apache License 2.0 | 6 votes |
@Override public Location<T> calculateSlotLocation (Location<T> outLocation, int slotNumber) { if (numberOfSlots > 1) { // Place the slot around the circle based on its slot number float angleAroundCircle = (MathUtils.PI2 * slotNumber) / numberOfSlots; // The radius depends on the radius of the member, // and the number of members in the circle: // we want there to be no gap between member's shoulders. float radius = memberRadius / (float)Math.sin(Math.PI / numberOfSlots); // Fill location components based on the angle around circle. outLocation.angleToVector(outLocation.getPosition(), angleAroundCircle).scl(radius); // The members should be facing out outLocation.setOrientation(angleAroundCircle); } else { outLocation.getPosition().setZero(); outLocation.setOrientation(MathUtils.PI2 * slotNumber); } // Return the slot location return outLocation; }
Example 4
Source File: BulletRaycastObstacleAvoidanceTest.java From gdx-ai with Apache License 2.0 | 6 votes |
private void createWalls () { float side = 20; // Wall length int sides = MathUtils.random(4, 12); float angle = MathUtils.PI2 / sides; float radius = side / (2 * MathUtils.sin(MathUtils.PI / sides)); float apothem = radius * MathUtils.cos(MathUtils.PI / sides); Vector3 v = new Vector3(); for (int i = 0; i < sides; i++) { float a = angle * i; BulletSteeringUtils.angleToVector(v, a).scl(apothem); BulletEntity wall = world.add("staticwall", v.x, 0, v.z); wall.setColor(MathUtils.random(0.25f, 0.75f), MathUtils.random(0.25f, 0.75f), MathUtils.random(0.25f, 0.75f), 1f); wall.transform.rotateRad(Vector3.Y, a + MathUtils.PI / 2); wall.body.setWorldTransform(wall.transform); } }
Example 5
Source File: MDQuaternion.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 5 votes |
/** Sets the quaternion components from the given axis and angle around that axis. * @param x X direction of the axis * @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(); }
Example 6
Source File: MDQuaternion.java From MD360Player4Android with Apache License 2.0 | 5 votes |
/** Sets the quaternion components from the given axis and angle around that axis. * @param x X direction of the axis * @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(); }
Example 7
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x += KICK_VELOCITY * MathUtils.cos(angle); velocity.y += KICK_VELOCITY * MathUtils.sin(angle); }
Example 8
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { float angle = MathUtils.PI2 * MathUtils.random(); velocity.x = KICK_VELOCITY * MathUtils.cos(angle); velocity.y = KICK_VELOCITY * MathUtils.sin(angle); }
Example 9
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x += KICK_VELOCITY * MathUtils.cos(angle); velocity.y += KICK_VELOCITY * MathUtils.sin(angle); }
Example 10
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x = KICK_VELOCITY * MathUtils.cos(angle); velocity.y = KICK_VELOCITY * MathUtils.sin(angle); }
Example 11
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x += KICK_VELOCITY * MathUtils.cos(angle); velocity.y += KICK_VELOCITY * MathUtils.sin(angle); }
Example 12
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x = KICK_VELOCITY * MathUtils.cos(angle); velocity.y = KICK_VELOCITY * MathUtils.sin(angle); }
Example 13
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x = KICK_VELOCITY * MathUtils.cos(angle); velocity.y = KICK_VELOCITY * MathUtils.sin(angle); }
Example 14
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x = KICK_VELOCITY * MathUtils.cos(angle); velocity.y = KICK_VELOCITY * MathUtils.sin(angle); }
Example 15
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x = KICK_VELOCITY * MathUtils.cos(angle); velocity.y = KICK_VELOCITY * MathUtils.sin(angle); }
Example 16
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x += KICK_VELOCITY * MathUtils.cos(angle); velocity.y += KICK_VELOCITY * MathUtils.sin(angle); }
Example 17
Source File: BouncingBall.java From ud405 with MIT License | 4 votes |
private void randomKick() { Random random = new Random(); float angle = MathUtils.PI2 * random.nextFloat(); velocity.x += KICK_VELOCITY * MathUtils.cos(angle); velocity.y += KICK_VELOCITY * MathUtils.sin(angle); }
Example 18
Source File: FilledPolygonDrawer.java From shapedrawer with MIT License | 4 votes |
@Override void polygon(float centreX, float centreY, int sides, float radiusX, float radiusY, float rotation, float startAngle, float radians, float innerColor, float outerColor) { if (radians==0) return; radians = Math.min(radians, ShapeUtils.PI2); boolean wasCaching = batchManager.startCaching(); float angleInterval = MathUtils.PI2 / sides; float endAngle = startAngle + radians; float cos = (float) Math.cos(angleInterval), sin = (float) Math.sin(angleInterval); float cosRot = (float) Math.cos(rotation), sinRot = (float) Math.sin(rotation); int start = (int) Math.ceil(sides * (startAngle / ShapeUtils.PI2)); int end = (int) Math.floor(sides * (endAngle / ShapeUtils.PI2)) + 1; if (ShapeUtils.epsilonEquals(start * angleInterval, startAngle)) start++; int n = end-start; batchManager.ensureSpace(n + 2); int vertexOffset = batchManager.getVerticesArrayIndex(); //centre point - triangle index 0 vert1(centreX, centreY); color1(innerColor); batchManager.pushVertex(); //first perimeter vertex (at start angle) - triangle index 1 A.set(1, 0).rotateRad(startAngle).scl(radiusX, radiusY); x1(A.x*cosRot-A.y*sinRot + centreX); y1(A.x*sinRot+A.y*cosRot + centreY); color1(outerColor); batchManager.pushVertex(); batchManager.pushTriangleIndices((short) vertexOffset, (short) (vertexOffset+1), (short) (vertexOffset+2)); //loop through evenly spaced perimeter vertices dir.set(1, 0).rotateRad(Math.min(start * angleInterval, endAngle)); A.set(dir).scl(radiusX, radiusY); for (int i = 0; i < n-1; i++) { x1(A.x*cosRot-A.y*sinRot + centreX); y1(A.x*sinRot+A.y*cosRot + centreY); color1(outerColor); batchManager.pushVertex(); dir.set(dir.x * cos - dir.y * sin, dir.x * sin + dir.y * cos); A.set(dir).scl(radiusX, radiusY); batchManager.pushTriangleIndices((short) vertexOffset, (short) (vertexOffset+i+2), (short) (vertexOffset+i+3)); } //last perimeter vertex (at end angle) - triangle index n+1 (already included in loop) A.set(1, 0).rotateRad(endAngle).scl(radiusX, radiusY); x1(A.x*cosRot-A.y*sinRot + centreX); y1(A.x*sinRot+A.y*cosRot + centreY); color1(outerColor); batchManager.pushVertex(); if (!wasCaching) batchManager.endCaching(); }
Example 19
Source File: FilledPolygonDrawer.java From shapedrawer with MIT License | 4 votes |
@Override void polygon(float centreX, float centreY, int sides, float radiusX, float radiusY, float rotation, float startAngle, float radians, float innerColor, float outerColor) { if (radians==0) return; radians = Math.min(radians, ShapeUtils.PI2); boolean wasCaching = batchManager.startCaching(); float angleInterval = MathUtils.PI2 / sides; float endAngle = startAngle + radians; float cos = (float) Math.cos(angleInterval), sin = (float) Math.sin(angleInterval); float cosRot = (float) Math.cos(rotation), sinRot = (float) Math.sin(rotation); int start = (int) Math.ceil(sides * (startAngle / ShapeUtils.PI2)); int end = (int) Math.floor(sides * (endAngle / ShapeUtils.PI2)) + 1; if (ShapeUtils.epsilonEquals(start * angleInterval, startAngle)) start++; B.set(1, 0).rotateRad(startAngle).scl(radiusX, radiusY); int n = end-start; if (n<2) { // there are no "regular" segments, will never enter loop, // so just push the one triangle from start angle to end angle batchManager.ensureSpaceForTriangle(); A.set(1, 0).rotateRad(startAngle).scl(radiusX, radiusY); B.set(1, 0).rotateRad(endAngle).scl(radiusX, radiusY); vert1(centreX, centreY); x2(A.x*cosRot-A.y*sinRot + centreX); y2(A.x*sinRot+A.y*cosRot + centreY); x3(B.x*cosRot-B.y*sinRot + centreX); y3(B.x*sinRot+B.y*cosRot + centreY); color(innerColor,outerColor,outerColor); batchManager.pushTriangle(); } else { //prepare for regular segments dir.set(1, 0).rotateRad(Math.min(start * angleInterval, endAngle)); C.set(dir).scl(radiusX, radiusY); } for (int i = 0; i < n-1; i++) { A.set(B); B.set(C); if (i<n-2) { dir.set(dir.x * cos - dir.y * sin, dir.x * sin + dir.y * cos); C.set(dir).scl(radiusX, radiusY); } else { C.set(1, 0).rotateRad(endAngle).scl(radiusX, radiusY); } if (i%2==0) { //skip every second triangle so that we can draw it as a quad with the next triangle batchManager.ensureSpaceForQuad(); vert1(centreX, centreY); x2(A.x*cosRot-A.y*sinRot + centreX); y2(A.x*sinRot+A.y*cosRot + centreY); x3(B.x*cosRot-B.y*sinRot + centreX); y3(B.x*sinRot+B.y*cosRot + centreY); x4(C.x*cosRot-C.y*sinRot + centreX); y4(C.x*sinRot+C.y*cosRot + centreY); color(innerColor, outerColor, outerColor, outerColor); batchManager.pushQuad(); } else if (i==n-2) { //draw final triangle batchManager.ensureSpaceForTriangle(); C.set(1, 0).rotateRad(endAngle).scl(radiusX, radiusY); vert1(centreX, centreY); x2(B.x*cosRot-B.y*sinRot + centreX); y2(B.x*sinRot+B.y*cosRot + centreY); x3(C.x*cosRot-C.y*sinRot + centreX); y3(C.x*sinRot+C.y*cosRot + centreY); color(innerColor, outerColor, outerColor); batchManager.pushTriangle(); } } if (!wasCaching) batchManager.endCaching(); }
Example 20
Source File: PolygonDrawer.java From shapedrawer with MIT License | 4 votes |
void drawPolygonWithJoin(Vector2 centre, int sides, float halfLineWidth, float rotation, Vector2 radius, float startAngle, float radians, boolean smooth) { float c = batchManager.floatBits; boolean full = ShapeUtils.epsilonEquals(radians, ShapeUtils.PI2); float angleInterval = MathUtils.PI2 / sides; float endAngle = startAngle + radians; float cos = (float) Math.cos(angleInterval), sin = (float) Math.sin(angleInterval); float cosRot = (float) Math.cos(rotation), sinRot = (float) Math.sin(rotation); int start, end; if (full) { start = 1; end = sides; dir.set(1, 0).rotateRad(start * angleInterval); A.set(1, 0).rotateRad((start-2) * angleInterval).scl(radius); C.set(dir).scl(radius); B.set(1, 0).rotateRad((start-1) * angleInterval).scl(radius); } else { start = (int) Math.ceil(sides * (startAngle / ShapeUtils.PI2)); if (ShapeUtils.epsilonEquals(start * angleInterval, startAngle)) start++; end = (int) Math.floor(sides * (endAngle / ShapeUtils.PI2)) + 1; end = Math.min(end, start + sides); dir.set(1, 0).rotateRad(Math.min(start * angleInterval, endAngle)); A.set(1, 0).rotateRad((start-1) * angleInterval).scl(radius); B.set(1, 0).rotateRad(startAngle).scl(radius); C.set(dir).scl(radius); } for (int i = start; i <= end; i++) { batchManager.ensureSpaceForQuad(); if (!full && i==start) { Joiner.prepareRadialEndpoint(B, D, E, halfLineWidth); } else { if (smooth) { Joiner.prepareSmoothJoin(A, B, C, D, E, halfLineWidth, true); } else { Joiner.preparePointyJoin(A, B, C, D, E, halfLineWidth); } } vert1(E.x*cosRot-E.y*sinRot + centre.x, E.x*sinRot+E.y*cosRot + centre.y); vert2(D.x*cosRot-D.y*sinRot + centre.x, D.x*sinRot+D.y*cosRot + centre.y); if (full || i<end) { A.set(B); B.set(C); dir.set(dir.x * cos - dir.y * sin, dir.x * sin + dir.y * cos); C.set(dir).scl(radius); } else { B.set(1, 0).rotateRad(endAngle).scl(radius); } if (full || i<end) { if (smooth) { Joiner.prepareSmoothJoin(A, B, C, D, E, halfLineWidth, false); } else { Joiner.preparePointyJoin(A, B, C, D, E, halfLineWidth); } } else { Joiner.prepareRadialEndpoint(B, D, E, halfLineWidth); } vert3(D.x*cosRot-D.y*sinRot + centre.x, D.x*sinRot+D.y*cosRot + centre.y); vert4(E.x*cosRot-E.y*sinRot + centre.x, E.x*sinRot+E.y*cosRot + centre.y); color(c,c,c,c); batchManager.pushQuad(); //push current AB if (smooth && (full || i<end)) drawSmoothJoinFill(A, B, C, D, E, centre, cosRot, sinRot, halfLineWidth); } }