Java Code Examples for com.badlogic.gdx.math.MathUtils#cos()
The following examples show how to use
com.badlogic.gdx.math.MathUtils#cos() .
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: 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 2
Source File: FrigateAI.java From libgdx-demo-pax-britannica with MIT License | 6 votes |
public void retarget() { target = Targeting.getNearestOfType(frigate, 0); if (target == null) { target = Targeting.getNearestOfType(frigate, 1); } if (target == null) { target = Targeting.getNearestOfType(frigate, 2); } if (target == null) { target = Targeting.getNearestOfType(frigate, 3); } if (target != null) { Vector2 random = new Vector2(MathUtils.cos((float) ((MathUtils.random() * MathUtils.PI * 2) * Math.sqrt(MathUtils.random()))), MathUtils.sin((float) ((MathUtils.random() * MathUtils.PI * 2) * Math.sqrt(MathUtils.random())))); target_fuzzy_pos.set(target.collisionCenter).add(random.scl(250)); } }
Example 3
Source File: DirectionTool.java From riiablo with Apache License 2.0 | 5 votes |
@Override public void render() { Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); float radius = 64; float angle = MathUtils.atan2(y2 - y1, x2 - x1); float x = radius * MathUtils.cos(angle); float y = radius * MathUtils.sin(angle); float rads = tmpVec2b.sub(tmpVec2a).nor().angleRad(); builder.setLength(0); builder .append("x,y: ").append("(" + x2 + "," + y2 + ")").append('\n') .append("angle: ").append(rads).append('\n') .append("dir4: ").append(Direction.radiansToDirection(rads, 4)).append('\n') .append("dir8: ").append(Direction.radiansToDirection(rads, 8)).append('\n') .append("dir16: ").append(Direction.radiansToDirection(rads, 16)).append('\n') .append("dir32: ").append(Direction.radiansToDirection(rads, 32)).append('\n'); shapes.begin(ShapeRenderer.ShapeType.Line); drawDiamond(shapes, x1 - 80, y1 - 40, 160, 80); shapes.line(x1, y1, x1 + x, y1 + y); shapes.end(); batch.begin(); font.draw(batch, builder.toString(), 0, Gdx.graphics.getHeight()); batch.end(); }
Example 4
Source File: PositionalLight.java From uracer-kotd with Apache License 2.0 | 5 votes |
@Override void update() { if( body != null && !staticLight ) { final Vector2 vec = body.getPosition(); float angle = body.getAngle(); final float cos = MathUtils.cos( angle ); final float sin = MathUtils.sin( angle ); final float dX = bodyOffsetX * cos - bodyOffsetY * sin; final float dY = bodyOffsetX * sin + bodyOffsetY * cos; start.x = vec.x + dX; start.y = vec.y + dY; setDirection( angle * MathUtils.radiansToDegrees ); } if( rayHandler.culling ) { culled = ((!rayHandler.intersect( start.x, start.y, distance + softShadowLenght ))); if( culled ) return; } if( staticLight ) return; for( int i = 0; i < rayNum; i++ ) { rayHandler.m_index = i; rayHandler.m_f[i] = 1f; tmpEnd.x = endX[i] + start.x; rayHandler.m_x[i] = tmpEnd.x; tmpEnd.y = endY[i] + start.y; rayHandler.m_y[i] = tmpEnd.y; if( /* rayHandler.world != null && */!xray ) { rayHandler.doRaycast( this, start, tmpEnd ); } } setMesh(); }
Example 5
Source File: FactorySelector.java From libgdx-demo-pax-britannica with MIT License | 5 votes |
public void reset() { picked = false; cpuSelect = false; playerSelect = false; fade = 0.2f; fadeButton = 0.0f; pulse_time = 0; float pulse = (1 + MathUtils.cos((pulse_time/180.f)*2.f*MathUtils.PI))/2.f; float color = fade * pulse + 1 * (1-pulse); this.setColor(color, color, color, 1); button.setColor(color, color, color, 1); cpuButton.setColor(color, color, color, 1); }
Example 6
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 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: PointF.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
public PointF polar( float a, float l ) { this.x = l * MathUtils.cos(a); this.y = l * MathUtils.sin( a ); return this; }
Example 9
Source File: OscillatingCircle.java From ud406 with MIT License | 4 votes |
public Circle getCurrentCircle(float elapsedTime) { float x = originX + magnitude * MathUtils.cos(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); float y = originY + magnitude * MathUtils.sin(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); return new Circle(x, y, radius); }
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() { float angle = MathUtils.PI2 * MathUtils.random(); 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: CCNode.java From cocos2d-java with MIT License | 4 votes |
private CCAffineTransform nodeToParentTransform(){ if (m_bTransformDirty){ // CCPoint zero = CCPoint.getZero(); // m_sTransform.setToIdentity(); // // // if (m_fRotation != 0) // m_sTransform.rotate(-m_fRotation * MathUtils.degreesToRadians); // // m_bTransformDirty = false; // Translate values float x = m_obPosition.x; float y = m_obPosition.y; if (m_bIgnoreAnchorPointForPosition) { x += m_obAnchorPointInPoints.x; y += m_obAnchorPointInPoints.y; } // Rotation values // Change rotation code to handle X and Y // If we skew with the exact same value for both x and y then we're simply just rotating float cx = 1, sx = 0, cy = 1, sy = 0; if ( (m_fRotationX != 0) || (m_fRotationY != 0) ) { float radiansX = -MathUtil.CC_DEGREES_TO_RADIANS(m_fRotationX); float radiansY = -MathUtil.CC_DEGREES_TO_RADIANS(m_fRotationY); cx = MathUtils.cos(radiansX); sx = MathUtils.sin(radiansX); cy = MathUtils.cos(radiansY); sy = MathUtils.sin(radiansY); } boolean needsSkewMatrix = ( (m_fSkewX != 0) || (m_fSkewY != 0) ); // optimization: // inline anchor point calculation if skew is not needed // Adjusted transform calculation for rotational skew if (! needsSkewMatrix && !m_obAnchorPointInPoints.equalToPoint(CCPoint.Zero)) { x += cy * -m_obAnchorPointInPoints.x * m_fScaleX + -sx * -m_obAnchorPointInPoints.y * m_fScaleY; y += sy * -m_obAnchorPointInPoints.x * m_fScaleX + cx * -m_obAnchorPointInPoints.y * m_fScaleY; } // Build Transform Matrix // Adjusted transform calculation for rotational skew // m_sTransform = new CCAffineTransform( cy * m_fScaleX, sy * m_fScaleX, // -sx * m_fScaleY, cx * m_fScaleY, // x, y ); m_sTransform.set(cy * m_fScaleX, sy * m_fScaleX, -sx * m_fScaleY, cx * m_fScaleY, x, y); // XXX: Try to inline skew // If skew is needed, apply skew and then anchor point if (needsSkewMatrix) { CCAffineTransform skewMatrix = new CCAffineTransform(1.0f, MathUtil.tanf(MathUtil.CC_DEGREES_TO_RADIANS(m_fSkewY)), MathUtil.tanf(MathUtil.CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, 0.0f, 0.0f ); m_sTransform = CCAffineTransform.multiply(skewMatrix, m_sTransform); // adjust anchor point if (!m_obAnchorPointInPoints.equalToPoint(CCPoint.Zero)) { m_sTransform = CCAffineTransform.CCAffineTransformTranslate(m_sTransform, -m_obAnchorPointInPoints.x, -m_obAnchorPointInPoints.y); } } if (m_bAdditionalTransformDirty) { //m_sTransform = CCAffineTransform.multiply(m_sTransform, m_sAdditionalTransform); m_sTransform.multiply(m_sAdditionalTransform); m_bAdditionalTransformDirty = false; } m_bTransformDirty = false; } return m_sTransform; }
Example 18
Source File: OscillatingCircle.java From ud406 with MIT License | 4 votes |
public Circle getCurrentCircle(float elapsedTime) { float x = originX + magnitude * MathUtils.cos(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); float y = originY + magnitude * MathUtils.sin(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); return new Circle(x, y, radius); }
Example 19
Source File: CCParticleActor.java From cocos-ui-libgdx with Apache License 2.0 | 4 votes |
private void updatePosWithParticle(Particle _particleData, Vector2 newPosition, float size, float rotation, int pidx) { float[] toUpdate = vertices[pidx]; float size_2 = size / 2; float x1 = -size_2; float y1 = -size_2; float x2 = size_2; float y2 = size_2; float x = newPosition.x + this.getX(); float y = newPosition.y + this.getY(); float r = (float) -CC_DEGREES_TO_RADIANS(rotation); float cr = (float) MathUtils.cos(r); float sr = (float) MathUtils.sin(r); float ax = x1 * cr - y1 * sr + x; float ay = x1 * sr + y1 * cr + y; float bx = x2 * cr - y1 * sr + x; float by = x2 * sr + y1 * cr + y; float cx = x2 * cr - y2 * sr + x; float cy = x2 * sr + y2 * cr + y; float dx = x1 * cr - y2 * sr + x; float dy = x1 * sr + y2 * cr + y; // bottom-left toUpdate[X1] = ax; toUpdate[Y1] = ay; // bottom-right vertex: toUpdate[X4] = bx; toUpdate[Y4] = by; // top-left vertex: toUpdate[X2] = dx; toUpdate[Y2] = dy; // top-right vertex: toUpdate[X3] = cx; toUpdate[Y3] = cy; toUpdate[U1] = 0; toUpdate[V1] = 1; toUpdate[U2] = 0; toUpdate[V2] = 0; toUpdate[U3] = 1; toUpdate[V3] = 0; toUpdate[U4] = 1; toUpdate[V4] = 1; }
Example 20
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); }