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

The following examples show how to use com.badlogic.gdx.math.MathUtils#atan2() . 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: ScalingLaserEffect.java    From jorbs-spire-mod with MIT License 6 votes vote down vote up
public ScalingLaserEffect(float sourceX, float sourceY, float targetX, float targetY, Color color1, Color color2, int amount) {
    if (img == null) {
        img = ImageMaster.vfxAtlas.findRegion("combat/laserThin");
    }

    this.sourceX = sourceX;
    this.sourceY = sourceY;
    this.distance = Vector2.dst(this.sourceX, this.sourceY, targetX, targetY) / Settings.scale;
    this.color = color1.cpy();
    this.color2 = color2.cpy();
    this.duration = DUR;
    this.startingDuration = DUR;
    this.rotation = MathUtils.atan2(targetX - sourceX, targetY - sourceY);
    this.rotation *= 57.295776F;
    this.rotation = -this.rotation + 90.0F;
    if (amount <= 0) {
        this.beamThickness = 0;
    } else {
        this.beamThickness = amount * 3f / 2f;
    }
}
 
Example 2
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 roll euler angle in radians, which is the rotation around the z axis. Requires that this quaternion is normalized.
 * @return the rotation around the z axis in radians (between -PI and +PI) */
public float getRollRad () {
    float w = q[0];
    float x = q[1];
    float y = q[2];
    float z = q[3];

    final int pole = getGimbalPole();
    return pole == 0 ? MathUtils.atan2(2f * (w * z + y * x), 1f - 2f * (x * x + z * z)) : (float)pole * 2f
            * MathUtils.atan2(y, w);
}
 
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 yaw euler angle in radians, which is the rotation around the y axis. Requires that this quaternion is normalized.
 * @return the rotation around the y axis in radians (between -PI and +PI) */
public float getYawRad () {
    float w = q[0];
    float x = q[1];
    float y = q[2];
    float z = q[3];

    return getGimbalPole() == 0 ? MathUtils.atan2(2f * (y * w + x * z), 1f - 2f * (y * y + x * x)) : 0f;
}
 
Example 4
Source File: MDQuaternion.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
/** Get the roll euler angle in radians, which is the rotation around the z axis. Requires that this quaternion is normalized.
 * @return the rotation around the z axis in radians (between -PI and +PI) */
public float getRollRad () {
    float w = q[0];
    float x = q[1];
    float y = q[2];
    float z = q[3];

    final int pole = getGimbalPole();
    return pole == 0 ? MathUtils.atan2(2f * (w * z + y * x), 1f - 2f * (x * x + z * z)) : (float)pole * 2f
            * MathUtils.atan2(y, w);
}
 
Example 5
Source File: MDQuaternion.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
/** Get the yaw euler angle in radians, which is the rotation around the y axis. Requires that this quaternion is normalized.
 * @return the rotation around the y axis in radians (between -PI and +PI) */
public float getYawRad () {
    float w = q[0];
    float x = q[1];
    float y = q[2];
    float z = q[3];

    return getGimbalPole() == 0 ? MathUtils.atan2(2f * (y * w + x * z), 1f - 2f * (y * y + x * x)) : 0f;
}
 
Example 6
Source File: RadialGravityActuatorSystem.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void execute(float deltaTime) {
    for (ActuatorEntity e : group.getEntities()) {
        RadialGravityActuator actuator = e.getRadialGravityActuator();
        GameEntity owner = Indexed.getInteractiveEntity(e.getLink().ownerEntity);
        Vector2 planet_position = owner.getRigidBody().body.getWorldCenter();

        SensorEntity gravitySensor = Indexed.getSensorsEntity(e.getLink().ownerEntity, "RadialGravitySensor");

        for (int index : gravitySensor.getNearSensor().distanceContactList) {
            GameEntity gameEntity = Indexed.getInteractiveEntity(index);
            body = gameEntity.getRigidBody().body;
            debris_position = body.getWorldCenter();

            planet_distance.set(0, 0);
            planet_distance.add(debris_position);
            planet_distance.sub(planet_position);
            force = -(float) ((actuator.gravity * body.getMass()) / planet_distance.len());

            if (planet_distance.len() < actuator.radius * actuator.gravityFactor) {
                planet_distance.scl(force);

                body.applyForceToCenter(planet_distance, true);

                float desiredAngle = MathUtils.atan2(-body.getLinearVelocity().x, body.getLinearVelocity().y);
                while (desiredAngle < -180 * MathUtils.degreesToRadians)
                    desiredAngle += 360 * MathUtils.degreesToRadians;
                while (desiredAngle > 180 * MathUtils.degreesToRadians)
                    desiredAngle -= 360 * MathUtils.degreesToRadians;

                body.applyTorque(desiredAngle < 0 ? planet_distance.nor().len() / 2 : -planet_distance.nor().len() / 2, true);
            }

        }

    }
}
 
Example 7
Source File: DirectionTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@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);

  builder.setLength(0);
  builder
      .append("x,y: ").append("(" + x2 + "," + y2 + ")").append('\n')
      .append("angle: ").append(angle).append('\n')
      .append("dir4: ").append(Direction.radiansToDirection(angle, 4)).append('\n')
      .append("dir8: ").append(Direction.radiansToDirection(angle, 8)).append('\n')
      .append("dir16: ").append(Direction.radiansToDirection(angle, 16)).append('\n')
      .append("dir32: ").append(Direction.radiansToDirection(angle, 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 8
Source File: DirectionTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: DirectionActor.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public void setDirections(int dirs) {
  this.dirs = dirs;
  this.angle = MathUtils.atan2(-2, -4);
  update();
}
 
Example 10
Source File: ServerBullet.java    From killingspree with MIT License 4 votes vote down vote up
@Override
public void updateState(EntityState state) {
    super.updateState(state);
    state.angle = MathUtils.atan2(body.getLinearVelocity().y, body.getLinearVelocity().x);
}
 
Example 11
Source File: ServerArrow.java    From killingspree with MIT License 4 votes vote down vote up
@Override
public void updateState(EntityState state) {
    super.updateState(state);
    state.angle = MathUtils.atan2(body.getLinearVelocity().y, body.getLinearVelocity().x);
}
 
Example 12
Source File: ServerBomb.java    From killingspree with MIT License 4 votes vote down vote up
@Override
public void updateState(EntityState state) {
    super.updateState(state);
    state.angle = MathUtils.atan2(body.getLinearVelocity().y,
            body.getLinearVelocity().x);
}