Java Code Examples for com.badlogic.gdx.math.MathUtils#cosDeg()

The following examples show how to use com.badlogic.gdx.math.MathUtils#cosDeg() . 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: RenderUtils.java    From jorbs-spire-mod with MIT License 6 votes vote down vote up
public static void renderAtlasRegionCenteredAt(SpriteBatch sb, TextureAtlas.AtlasRegion atlasRegion, float x, float y, float offsetX, float offsetY, float scale, Color color, float rotation) {
    sb.setColor(color);
    float offsetXDrawn = offsetX * scale * MathUtils.cosDeg(rotation) + offsetY * scale * MathUtils.sinDeg(rotation);
    float offsetYDrawn = offsetX * scale * MathUtils.sinDeg(rotation) - offsetY * scale * MathUtils.cosDeg(rotation);
    sb.draw(
            atlasRegion,
            x + atlasRegion.offsetX - (float) atlasRegion.packedWidth / 2.0F + offsetXDrawn,
            y + atlasRegion.offsetY - (float) atlasRegion.packedHeight / 2.0F + offsetYDrawn,
            (float) atlasRegion.packedWidth / 2.0F - atlasRegion.offsetX,
            (float) atlasRegion.packedHeight / 2.0F - atlasRegion.offsetY,
            (float) atlasRegion.packedWidth,
            (float) atlasRegion.packedHeight,
            scale,
            scale,
            rotation);
}
 
Example 2
Source File: GameWorldRenderer.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
private Vector2 orientationToPosition (Car car, float angle, float offsetX, float offsetY) {
	Vector2 carPosition = car.state().position;
	float carLength = car.getCarModel().length;

	// the body's compound shape should be created with some clever thinking
	float offx = (carLength / 2f) + .25f + offsetX;
	float offy = offsetY;

	float cos = MathUtils.cosDeg(angle);
	float sin = MathUtils.sinDeg(angle);
	float dX = offx * cos - offy * sin;
	float dY = offx * sin + offy * cos;

	float mx = Convert.px2mt(carPosition.x) + dX;
	float my = Convert.px2mt(carPosition.y) + dY;
	_o2p.set(mx, my);
	return _o2p;
}
 
Example 3
Source File: FragilePower.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
@Override
public Color getColor() {
    return new Color(
            (MathUtils.cosDeg((float) (System.currentTimeMillis() / 10L % 360L)) + 1.25F) / 2.3F,
            (MathUtils.cosDeg((float) ((System.currentTimeMillis() + 1000L) / 10L % 360L)) + 1.25F) / 2.3F,
            (MathUtils.cosDeg((float) ((System.currentTimeMillis() + 2000L) / 10L % 360L)) + 1.25F) / 2.3F,
            1.0F);
}
 
Example 4
Source File: DirectionalLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
@Override
public void setDirection (float direction) {
	this.direction = direction;
	sin = MathUtils.sinDeg(direction);
	cos = MathUtils.cosDeg(direction);
	if (staticLight) dirty = true;
}
 
Example 5
Source File: ConeLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/** Updates lights sector basing on distance, direction and coneDegree **/
protected void setEndPoints() {
	for (int i = 0; i < rayNum; i++) {
		float angle = direction + coneDegree - 2f * coneDegree * i
				/ (rayNum - 1f);
		final float s = sin[i] = MathUtils.sinDeg(angle);
		final float c = cos[i] = MathUtils.cosDeg(angle);
		endX[i] = distance * c;
		endY[i] = distance * s;
	}
}
 
Example 6
Source File: PointLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/** Updates light basing on it's distance and rayNum **/
void setEndPoints() {
	float angleNum = 360f / (rayNum - 1);
	for (int i = 0; i < rayNum; i++) {
		final float angle = angleNum * i;
		sin[i] = MathUtils.sinDeg(angle);
		cos[i] = MathUtils.cosDeg(angle);
		endX[i] = distance * cos[i];
		endY[i] = distance * sin[i];
	}
}
 
Example 7
Source File: RadixClient.java    From Radix with MIT License 5 votes vote down vote up
private void updatePositionRotationAndroid() {
    if(!MathUtils.isZero(rotateTouchpad.getKnobPercentX()) || !MathUtils.isZero(rotateTouchpad.getKnobPercentY())) {
        float rotMult = 200 * Gdx.graphics.getDeltaTime();

        player.getRotation().offset(rotateTouchpad.getKnobPercentY() * rotMult, rotateTouchpad.getKnobPercentX() * rotMult);
        updateSelectedBlock();
        gameRenderer.calculateFrustum();
    }

    if(!MathUtils.isZero(moveTouchpad.getKnobPercentX()) || !MathUtils.isZero(moveTouchpad.getKnobPercentY())) {
        float posMult = 4.5f * Gdx.graphics.getDeltaTime();

        float deltaX = 0;
        float deltaZ = 0;
        float yawSine = MathUtils.sinDeg(player.getRotation().getYaw());
        float yawCosine = MathUtils.cosDeg(player.getRotation().getYaw());
        deltaX += yawSine * moveTouchpad.getKnobPercentY() * posMult;
        deltaZ += -yawCosine * moveTouchpad.getKnobPercentY() * posMult;
        deltaX += yawCosine * moveTouchpad.getKnobPercentX() * posMult;
        deltaZ += yawSine * moveTouchpad.getKnobPercentX() * posMult;

        if(!movementHandler.checkDeltaCollision(player, deltaX, 0, deltaZ)
                && !movementHandler.checkDeltaCollision(player, deltaX, 0, deltaZ)) {
            player.getPosition().offset(deltaX, 0, deltaZ);
            gameRenderer.calculateFrustum();
        }
    }
}
 
Example 8
Source File: DirectionalLight.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
@Override
public void setDirection( float direction ) {
	super.direction = direction;
	sin = MathUtils.sinDeg( direction );
	cos = MathUtils.cosDeg( direction );
	if( staticLight )
		staticUpdate();
}
 
Example 9
Source File: ConeLight.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public void setDirection(float direction) {

		this.direction = direction;
		for (int i = 0; i < rayNum; i++) {
			float angle = direction + coneDegree - 2f * coneDegree * i
					/ (rayNum - 1f);
			final float s = sin[i] = MathUtils.sinDeg(angle);
			final float c = cos[i] = MathUtils.cosDeg(angle);
			endX[i] = distance * c;
			endY[i] = distance * s;
		}
		if (staticLight)
			staticUpdate();
	}
 
Example 10
Source File: PointLight.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
final void setEndPoints() {
	float angleNum = 360f / (rayNum - 1);
	for (int i = 0; i < rayNum; i++) {
		final float angle = angleNum * i;
		sin[i] = MathUtils.sinDeg(angle);
		cos[i] = MathUtils.cosDeg(angle);
		endX[i] = distance * cos[i];
		endY[i] = distance * sin[i];
	}
}
 
Example 11
Source File: MemoryManager.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public void update(float centerX, float centerY) {
    if (isSnapped()) {
        return;
    }

    for (int i = 0; i < memories.size(); ++i) {
        float relativeMemoryAngle = MEMORY_ARC_ANGLE * (((float)i) / (memories.size() - 1));
        float absoluteArcStartAngle = 90.0F - MEMORY_ARC_ANGLE / 2.0F;
        float absoluteAngle = absoluteArcStartAngle + relativeMemoryAngle;
        float x = MEMORY_ARC_X_RADIUS * MathUtils.cosDeg(absoluteAngle) + centerX;
        float y = MEMORY_ARC_Y_RADIUS * MathUtils.sinDeg(absoluteAngle) + centerY + MEMORY_ARC_Y_OFFSET;

        memories.get(i).update(x, y);
    }
}
 
Example 12
Source File: SnapCounter.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public void update(float centerX, float centerY, int flipMultiplier) {
    if (!isVisible()) { return; }

    int currentTurn = SnapFtueTip.shouldFakeCurrentTurn() ? SnapFtueTip.fakeCurrentTurn() : this.currentTurn;

    this.centerX = centerX;
    this.centerY = centerY;
    hb.update(centerX - hb.width / 2, centerY - hb.height / 2);

    indicatorCircleRotationTimer -= Gdx.graphics.getDeltaTime();
    if (indicatorCircleRotationTimer < 0.0) {
        indicatorCircleRotationTimer = INDICATOR_CIRCLE_ROTATION_DURATION;
    }

    indicatorParticleTimer -= Gdx.graphics.getDeltaTime();
    if (indicatorParticleTimer < 0.0) {
        indicatorParticleTimer = INDICATOR_PARTICLE_DURATION;

        Color color = colors[MathUtils.clamp(currentTurn - 1, 0, colors.length-1)];
        color.a = alpha;

        for (int i = 0; i < currentTurn; ++i) {
            if (currentTurn >= SNAP_TURN) {
                color = colors[i % SNAP_TURN];
            }
            float indicatorAngle = 360.0F * (((float)i) / (currentTurn));
            indicatorAngle += flipMultiplier * (360.0F * (indicatorCircleRotationTimer / INDICATOR_CIRCLE_ROTATION_DURATION));
            float x = flipMultiplier * INDICATOR_CIRCLE_X_RADIUS * MathUtils.cosDeg(indicatorAngle) + centerX;
            float y = flipMultiplier * INDICATOR_CIRCLE_Y_RADIUS * MathUtils.sinDeg(indicatorAngle) + centerY;

            float scaleModifier = isSnapTurn() ? 1.6F : 1.0F;
            AbstractDungeon.effectList.add(new SnapTurnCounterEffect(x, y, color, scaleModifier));
        }
    }
}
 
Example 13
Source File: NumericalValue.java    From talos with Apache License 2.0 4 votes vote down vote up
public void cos (NumericalValue out) {
	for (int i = 0; i < currentElementCount; i++) {
		out.elements[i] = MathUtils.cosDeg(elements[i]);
	}
	out.setElementsCount(elementsCount());
}
 
Example 14
Source File: Particle.java    From talos with Apache License 2.0 4 votes vote down vote up
public void update(float delta) {
    if(alpha == 1f) return;

    //scope data
    ParticleModule particleModule = particleEmitter.emitterGraph.getParticleModule();
    if(particleModule == null) return;

    life = particleModule.getLife();
    alpha += delta/life;
    if(alpha > 1f) alpha = 1f;
    particleModule.updateScopeData(this);

    //update variable values
    Vector2 target = particleModule.getTarget();
    float angle = 0;
    if(target == null) {
        angle = particleModule.getAngle(); // do we take angle or target
    } else {
        angle = target.sub(position).angle();
    }

    float velocity = particleModule.getVelocity();
    transparency = particleModule.getTransparency();

    if(particleEmitter.emitterGraph.emitterModule.isAligned()) {
        rotation = angle + particleModule.getRotation();
    } else {
        rotation = particleModule.getRotation();
    }

    drawable = particleModule.getDrawable(); // important to get drawable before size
    particleEmitter.getScope().set(ScopePayload.DRAWABLE_ASPECT_RATIO, drawable.getAspectRatio());

    size.set(particleModule.getSize());
    Vector2 positionOverride = particleModule.getPosition();
    color.set(particleModule.getColor());

    // perform inner operations
    if(positionOverride != null) {
        position.set(positionOverride);
    } else {
        position.x += MathUtils.cosDeg(angle) * velocity * delta;
        position.y += MathUtils.sinDeg(angle) * velocity * delta;
    }
}
 
Example 15
Source File: MyShapeRenderer.java    From GdxDemo3D with Apache License 2.0 4 votes vote down vote up
/** Draws a rectangle in the x/y plane using {@link ShapeType#Line} or {@link ShapeType#Filled}. The x and y specify the lower
 * left corner. The originX and originY specify the point about which to rotate the rectangle.
 * @param col1 The color at (x, y)
 * @param col2 The color at (x + width, y)
 * @param col3 The color at (x + width, y + height)
 * @param col4 The color at (x, y + height) */
public void rect(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY,
				 float degrees, Color col1, Color col2, Color col3, Color col4) {
	check(ShapeType.Line, ShapeType.Filled, 8);

	float cos = MathUtils.cosDeg(degrees);
	float sin = MathUtils.sinDeg(degrees);
	float fx = -originX;
	float fy = -originY;
	float fx2 = width - originX;
	float fy2 = height - originY;

	if (scaleX != 1 || scaleY != 1) {
		fx *= scaleX;
		fy *= scaleY;
		fx2 *= scaleX;
		fy2 *= scaleY;
	}

	float worldOriginX = x + originX;
	float worldOriginY = y + originY;

	float x1 = cos * fx - sin * fy + worldOriginX;
	float y1 = sin * fx + cos * fy + worldOriginY;

	float x2 = cos * fx2 - sin * fy + worldOriginX;
	float y2 = sin * fx2 + cos * fy + worldOriginY;

	float x3 = cos * fx2 - sin * fy2 + worldOriginX;
	float y3 = sin * fx2 + cos * fy2 + worldOriginY;

	float x4 = x1 + (x3 - x2);
	float y4 = y3 - (y2 - y1);

	if (shapeType == ShapeType.Line) {
		renderer.color(col1.r, col1.g, col1.b, col1.a);
		renderer.vertex(x1, y1, 0);
		renderer.color(col2.r, col2.g, col2.b, col2.a);
		renderer.vertex(x2, y2, 0);

		renderer.color(col2.r, col2.g, col2.b, col2.a);
		renderer.vertex(x2, y2, 0);
		renderer.color(col3.r, col3.g, col3.b, col3.a);
		renderer.vertex(x3, y3, 0);

		renderer.color(col3.r, col3.g, col3.b, col3.a);
		renderer.vertex(x3, y3, 0);
		renderer.color(col4.r, col4.g, col4.b, col4.a);
		renderer.vertex(x4, y4, 0);

		renderer.color(col4.r, col4.g, col4.b, col4.a);
		renderer.vertex(x4, y4, 0);
		renderer.color(col1.r, col1.g, col1.b, col1.a);
		renderer.vertex(x1, y1, 0);
	} else {
		renderer.color(col1.r, col1.g, col1.b, col1.a);
		renderer.vertex(x1, y1, 0);
		renderer.color(col2.r, col2.g, col2.b, col2.a);
		renderer.vertex(x2, y2, 0);
		renderer.color(col3.r, col3.g, col3.b, col3.a);
		renderer.vertex(x3, y3, 0);

		renderer.color(col3.r, col3.g, col3.b, col3.a);
		renderer.vertex(x3, y3, 0);
		renderer.color(col4.r, col4.g, col4.b, col4.a);
		renderer.vertex(x4, y4, 0);
		renderer.color(col1.r, col1.g, col1.b, col1.a);
		renderer.vertex(x1, y1, 0);
	}

}
 
Example 16
Source File: RadialDrawable.java    From gdx-vfx with Apache License 2.0 4 votes vote down vote up
protected void calculate(float x, float y, float width, float height, float angle, float u0, float v0, float u1, float v1) {
    if (!this.dirty && this.x == x && this.y == y && this.angle == angle && this.width == width && this.height == height
            && this.u1 == u0 && this.v2 == v1 && this.u2 == u1 && this.v2 == v1)
        return;
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.angle = angle;
    this.u1 = u0;
    this.v1 = v0;
    this.u2 = u1;
    this.v2 = v1;
    final float centerX = width * 0.5f;
    final float centerY = height * 0.5f;
    final float x2 = x + width;
    final float y2 = y + height;
    final float xc = x + centerX;
    final float yc = y + centerY;
    this.xc = xc;
    this.yc = yc;
    this.x2 = x2;
    final float ax = MathUtils.cosDeg(angle+angleOffset); // positive right, negative left
    final float ay = MathUtils.sinDeg(angle+angleOffset); // positive top, negative bottom
    final float txa = ax != 0f ? Math.abs(centerX / ax) : 99999999f; // intersection on left or right "wall"
    final float tya = ay != 0f ? Math.abs(centerY / ay) : 99999999f; // intersection on top or bottom "wall"
    final float t = Math.min(txa, tya);
    // tx and ty are the intersection points relative to centerX and centerY.
    final float tx = t*ax;
    final float ty = t*ay;
    vert(verts, BOTTOMRIGHT1, x + centerX, y);
    if (ax >= 0f) { // rotation on the rights half
        vert(verts, TOPLEFT1, x, y2);
        vert(verts, TOPRIGHT1, xc, y2);
        vert(verts, BOTTOMLEFT1, x, y);
        vert(verts, BOTTOMLEFT2, xc, yc);
        vert(verts, TOPLEFT2, xc, y2);
        if (txa < tya) { // rotation on the right side
            vert(verts, TOPRIGHT2, x2, y2);
            vert(verts, BOTTOMRIGHT2, x2, yc + ty);
            draw = 2;
        } else if (ay > 0f) { // rotation on the top side
            vert(verts, BOTTOMRIGHT2, xc + tx, y2);
            vert(verts, TOPRIGHT2, xc + tx * 0.5f, y2);
            draw = 2;
        } else { // rotation on the bottom side
            vert(verts, TOPRIGHT2, x2, y2);
            vert(verts, BOTTOMRIGHT2, x2, y);
            vert(verts, TOPLEFT3, xc, yc);
            vert(verts, TOPRIGHT3, x2, y);
            vert(verts, BOTTOMLEFT3, xc + tx, y);
            vert(verts, BOTTOMRIGHT3, xc + tx * 0.5f, y);
            draw = 3;
        }
    } else { // rotation on the left half
        vert(verts, TOPRIGHT1, x + centerX, y + centerY);
        if (txa < tya) { // rotation on the left side
            vert(verts, BOTTOMLEFT1, x, y);
            vert(verts, TOPLEFT1, x, yc + ty);
            draw = 1;
        } else if (ay < 0f) { // rotation on the bottom side
            vert(verts, TOPLEFT1, xc + tx, y);
            vert(verts, BOTTOMLEFT1, xc + tx * 0.5f, y);
            draw = 1;
        } else { // rotation on the top side
            vert(verts, TOPLEFT1, x, y2);
            vert(verts, BOTTOMLEFT1, x, y);
            vert(verts, BOTTOMRIGHT2, xc, yc);
            vert(verts, BOTTOMLEFT2, x, y2);
            vert(verts, TOPLEFT2, xc + tx * 0.5f, y2);
            vert(verts, TOPRIGHT2, xc + tx, y2);
            draw = 2;
        }
    }
    this.dirty = false;
}
 
Example 17
Source File: Scene3dDemo.java    From Scene3d with Apache License 2.0 4 votes vote down vote up
@Override
  public void render () {
      Gdx.gl.glClearColor(1, 1, 1, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
      stage3d.act();
  	stage3d.draw();
  	stage2d.act();
   	stage2d.draw();
  	camController.update();
  	fpsLabel.setText("Fps: " + Gdx.graphics.getFramesPerSecond());
  	visibleLabel.setText("Visible: " + stage3d.getRoot().visibleCount);
  	positionLabel.setText("Knight X:" + knight.getX()+" Y:"+knight.getY()+" Z:"+knight.getZ());
  	rotationLabel.setText("Knight Yaw:" + knight.getYaw()+" Pitch:"+knight.getPitch()+" "
  			+ "Roll:"+knight.getRoll());
  	positionCameraLabel.setText("Camera X:" + stage3d.getCamera().position.x
  			+" Y:"+stage3d.getCamera().position.y+" Z:"+stage3d.getCamera().position.z);
  	rotationCameraLabel.setText("Camera Yaw:" + stage3d.getCamera().direction.x
  			+" Pitch:"+stage3d.getCamera().direction.y+" "+ "Roll:"+stage3d.getCamera().direction.z);
  	
  	angle = MathUtils.cosDeg(knight.getYaw() - 90); //90 degrees is correction factor
  	angle2 = -MathUtils.sinDeg(knight.getYaw() - 90);
if (upKey) {
	knight.addAction3d(Actions3d.moveBy(angle, 0f, angle2));
	stage3d.getCamera().translate(angle, 0f, angle2);
} 
else if (downKey) {
	knight.addAction3d(Actions3d.moveBy(-angle, 0f, -angle2));
	stage3d.getCamera().translate(-angle, 0f, -angle2);
}
else if (rightKey) {
	knight.rotateYaw(-2f);
	if(stage3d.getCamera().direction.z > -0.76f)
		Camera3d.rotateBy(-2f, 0f, 0f, 0f);
	//stage3d.getCamera().translate(angle, 0f, angle2); //get the angle calculations rite to make
	// the camera truly follow knight
} 
else if (leftKey) {
	knight.rotateYaw(2f);
	if(stage3d.getCamera().direction.z < -0.63f)
		Camera3d.rotateBy(2f, 0f, 0f, 0f);
	
} 
/* private float stateTime;
    float angleDegrees;
    stateTime+= delta;
	angleDegrees = stateTime * 10.0f;
	camera.position.set(200f * MathUtils.sinDeg(angleDegrees),
		20, -200.0f * MathUtils.cosDeg(angleDegrees));
	camera.rotate(Vector3.Y, angleDegrees/10f*delta);*/
  }