List of usage examples for com.badlogic.gdx.math MathUtils radiansToDegrees
float radiansToDegrees
To view the source code for com.badlogic.gdx.math MathUtils radiansToDegrees.
Click Source Link
From source file:Tabox2D.java
License:Open Source License
/** * Updates the simulation with the given delta time * @param delta The delta time to simulate */// w w w .java 2s . co m public void update(float delta) { world.step(delta, 6, 2); // Move sprites: for (Tabody t : tabodies) { if (t.sprite != null) { float xb = t.body.getPosition().x * meterSize; float yb = t.body.getPosition().y * meterSize; xb -= t.sprite.getWidth() / 2; yb -= t.sprite.getHeight() / 2; t.sprite.setPosition(xb, yb); t.sprite.setRotation(t.body.getAngle() * MathUtils.radiansToDegrees); } // Constant force (using velocity vector): if (!t.velocity.equals(Vector2.Zero)) { t.body.setLinearVelocity(t.velocity); } } }
From source file:be.ac.ucl.lfsab1509.bouboule.game.body.Bonus.java
License:Open Source License
/** * Constructor for a Bonus object /*from www. j av a 2s. com*/ * @param px/py : initial position * @param angle : initial rotation * @param texRegionPath : Path to the image file * @param jsonFile : Path to the jsonFile if needed ( "" else) * @param jsonName : jsonName of the object ( must match the json file attribute ) * * public Bonus( final float px, final float py, * final float angle, final String texRegionPath, * final String jsonFile, final String jsonName, final short bonusType) */ public Bonus(final float angle, final String texRegionPath, final String jsonFile, final String jsonName, final Entity.BonusType bonusType) { super(); int size = GlobalSettings.ARENAWAYPOINTALLOW.size(); MapNode node = GlobalSettings.ARENAWAYPOINTALLOW.get(random.nextInt(size)); Vector2 pos = new Vector2(node.xToPixel() - 32, node.yToPixel() - 32); Vector2 radius = new Vector2(node.weightToPixel() * random.nextFloat(), 0); radius.rotate(random.nextInt(359)); pos.add(radius); this.texture = new TextureRegion(new Texture(texRegionPath)); this.sprite = new Sprite(texture); MakeBody(0, 0, 0, BodyType.StaticBody, 0, 0, true, pos, angle, jsonFile, jsonName, GraphicManager.convertToGame(texture.getRegionWidth())); //Ensure that the object don't rotate. body.setFixedRotation(true); //Create the userData of type Bonus and bonusType this.entity = new Entity(Entity.BONUS, true, bonusType); body.setUserData(this.entity); //Ensure that the body image position is set on the origin defined by //the jsonFile if (origin != null) { pos = positionVector.cpy(); pos = pos.sub(origin); sprite.setPosition(pos.x, pos.y); sprite.setOrigin(origin.x, origin.y); sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees); } // removed the bonus after a delay Timer.Task task = new Timer.Task() { @Override public void run() { entity.setAlive(false); } }; Timer timer = new Timer(); timer.scheduleTask(task, 10f); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.body.Bouboule.java
License:Open Source License
/** * (non-Javadoc)./* w w w .jav a2 s . com*/ * @see be.ac.ucl.lfsab1509.bouboule.game.body.GameBody# * draw(com.badlogic.gdx.graphics.g2d.SpriteBatch) */ public void draw(final SpriteBatch sp) { if (entity.isAlive()) { if (origin != null) { //Ensure that the body image position is set on the origin defined by //the jsonFile Vector2 pos = positionVector.cpy(); pos = pos.sub(origin); sprite.setPosition(pos.x, pos.y); sprite.setOrigin(origin.x, origin.y); sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees); sprite.draw(sp); } else { sp.draw(texture, positionVector.x, positionVector.y); } } }
From source file:be.ac.ucl.lfsab1509.bouboule.game.body.Bouboule.java
License:Open Source License
/** * Get body rotation in degrees./*from www . j a v a 2 s .c om*/ * if needed =) * * getBodyRotationInDegrees() */ public float getBodyRotationInDegrees() { return body.getAngle() * MathUtils.radiansToDegrees; }
From source file:CB_UI_Base.graphics.Geometry.Line.java
License:Open Source License
public float getAngle() { float ret = MathUtils.atan2((points[2] - points[0]), (points[3] - points[1])) * MathUtils.radiansToDegrees; ret = 90 - ret;// w ww. j av a 2 s . c om return ret; }
From source file:CB_UI_Base.graphics.GL_Path.java
License:Open Source License
public float getAverageDirection() { if (averageDirection == Float.MAX_VALUE) { // Average direction is the direction between first and last point! float firstX = items[0]; float firstY = items[1]; float lastX = items[size - 2]; float lastY = items[size - 1]; float ret = MathUtils.atan2((lastX - firstX), (lastY - firstY)) * MathUtils.radiansToDegrees; // averageDirection = 90 - ret; averageDirection = ret;/*from w w w .j a v a 2 s . c o m*/ } return averageDirection; }
From source file:CB_UI_Base.graphics.GL_Path.java
License:Open Source License
private float getAngle(int index1, int index2) { float ret = 0; try {// ww w. java 2s . co m if (index1 >= items.length || index2 >= items.length) return 0; ret = MathUtils.atan2((items[index2 * 2] - items[index1 * 2]), (items[index2 * 2 + 1] - items[index1 * 2 + 1])) * MathUtils.radiansToDegrees; ret = 90 - ret; } catch (Exception e) { } return ret; }
From source file:coder5560.gdxai.SteeringActor.java
License:Apache License
private void applySteering(SteeringAcceleration<Vector2> steering, float time) { // Update position and linear velocity. Velocity is trimmed to maximum // speed// ww w . ja va 2 s . co m position.mulAdd(linearVelocity, time); linearVelocity.mulAdd(steering.linear, time).limit(getMaxLinearSpeed()); // Update orientation and angular velocity if (independentFacing) { setRotation(getRotation() + (angularVelocity * time) * MathUtils.radiansToDegrees); angularVelocity += steering.angular * time; } else { // If we haven't got any velocity, then we can do nothing. if (!linearVelocity.isZero(MathUtils.FLOAT_ROUNDING_ERROR)) { float newOrientation = vectorToAngle(linearVelocity); angularVelocity = (newOrientation - getRotation() * MathUtils.degreesToRadians) * time; // this is superfluous if independentFacing is // always true setRotation(newOrientation * MathUtils.radiansToDegrees); } } }
From source file:com.agateau.pixelwheels.racer.Vehicle.java
License:Open Source License
/** * Returns the angle the car is facing */ public float getAngle() { return AgcMathUtils.normalizeAngle(mBody.getAngle() * MathUtils.radiansToDegrees); }
From source file:com.agateau.pixelwheels.racer.VehicleRenderer.java
License:Open Source License
private void drawTurbo(Batch batch) { TextureRegion region = mAssets.turboFlame.getKeyFrame(mVehicle.getTurboTime(), true); Body body = mVehicle.getBody();// w ww . j a v a 2 s . c o m Vector2 center = body.getPosition(); float angle = body.getAngle() * MathUtils.radiansToDegrees; float w = Constants.UNIT_FOR_PIXEL * region.getRegionWidth(); float h = Constants.UNIT_FOR_PIXEL * region.getRegionHeight(); float refH = -mVehicle.getWidth() / 2; float x = center.x + refH * MathUtils.cosDeg(angle); float y = center.y + refH * MathUtils.sinDeg(angle); batch.draw(region, x - w / 2, y - h, // pos w / 2, h, // origin w, h, // size 1, 1, // scale angle - 90); }