Java Code Examples for com.badlogic.gdx.physics.box2d.Body#getAngle()

The following examples show how to use com.badlogic.gdx.physics.box2d.Body#getAngle() . 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: PhysicsConnector.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void onUpdate(final float pSecondsElapsed) {
	final IEntity entity = this.mEntity;
	final Body body = this.mBody;

	if (this.mUpdatePosition) {
		final Vector2 position = body.getPosition();
		final float pixelToMeterRatio = this.mPixelToMeterRatio;
		entity.setPosition(position.x * pixelToMeterRatio, position.y * pixelToMeterRatio);
	}

	if (this.mUpdateRotation) {
		final float angle = body.getAngle();
		entity.setRotation(-MathUtils.radToDeg(angle));
	}
}
 
Example 2
Source File: Box2dSteeringTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
protected void renderBox (ShapeRenderer shapeRenderer, Body body, float halfWidth, float halfHeight) {
	// get the bodies center and angle in world coordinates
	Vector2 pos = body.getWorldCenter();
	float angle = body.getAngle();

	// set the translation and rotation matrix
	transform.setToTranslation(Box2dSteeringTest.metersToPixels(pos.x), Box2dSteeringTest.metersToPixels(pos.y), 0);
	transform.rotate(0, 0, 1, angle * MathUtils.radiansToDegrees);

	// render the box
	shapeRenderer.begin(ShapeType.Line);
	shapeRenderer.setTransformMatrix(transform);
	shapeRenderer.setColor(1, 1, 1, 1);
	shapeRenderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2);
	shapeRenderer.end();
}
 
Example 3
Source File: Scene2dRaycastObstacleAvoidanceTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private void renderBox (ShapeRenderer shapeRenderer, Body body, float halfWidth, float halfHeight) {
	// get the bodies center and angle in world coordinates
	Vector2 pos = body.getWorldCenter();
	float angle = body.getAngle();

	// set the translation and rotation matrix
	transform.setToTranslation(pos.x, pos.y, 0);
	transform.rotate(0, 0, 1, (float)Math.toDegrees(angle));

	// render the box
	shapeRenderer.begin(ShapeType.Line);
	shapeRenderer.setTransformMatrix(transform);
	shapeRenderer.setColor(1, 1, 1, 1);
	shapeRenderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2);
	shapeRenderer.end();
}
 
Example 4
Source File: PrismaticJointDef.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world axis.
 */
public void initialize (Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis) {
	this.bodyA = bodyA;
	this.bodyB = bodyB;
	localAnchorA.set(bodyA.getLocalPoint(anchor));
	localAnchorB.set(bodyB.getLocalPoint(anchor));
	localAxis1.set(bodyA.getLocalVector(axis));
	referenceAngle = bodyB.getAngle() - bodyA.getAngle();

}
 
Example 5
Source File: WeldJointDef.java    From tilt-game-android with MIT License 5 votes vote down vote up
public void initialize (Body body1, Body body2, Vector2 anchor) {
	this.bodyA = body1;
	this.bodyB = body2;
	this.localAnchorA.set(body1.getLocalPoint(anchor));
	this.localAnchorB.set(body2.getLocalPoint(anchor));
	referenceAngle = body2.getAngle() - body1.getAngle();
}
 
Example 6
Source File: RevoluteJointDef.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * Initialize the bodies, anchors, and reference angle using a world anchor point.
 */
public void initialize (Body bodyA, Body bodyB, Vector2 anchor) {
	this.bodyA = bodyA;
	this.bodyB = bodyB;
	localAnchorA.set(bodyA.getLocalPoint(anchor));
	localAnchorB.set(bodyB.getLocalPoint(anchor));
	referenceAngle = bodyB.getAngle() - bodyA.getAngle();
}
 
Example 7
Source File: Box2dLightTest.java    From box2dlights with Apache License 2.0 4 votes vote down vote up
@Override
public void render() {
	
	/** Rotate directional light like sun :) */
	if (lightsType == 3) {
		sunDirection += Gdx.graphics.getDeltaTime() * 4f;
		lights.get(0).setDirection(sunDirection);
	}

	camera.update();

	boolean stepped = fixedStep(Gdx.graphics.getDeltaTime());
	Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

	batch.setProjectionMatrix(camera.combined);
	batch.disableBlending();
	batch.begin();
	{
		batch.draw(bg, -viewportWidth / 2f, 0, viewportWidth, viewportHeight);
		batch.enableBlending();
		for (int i = 0; i < BALLSNUM; i++) {
			Body ball = balls.get(i);
			Vector2 position = ball.getPosition();
			float angle = MathUtils.radiansToDegrees * ball.getAngle();
			batch.draw(
					textureRegion,
					position.x - RADIUS, position.y - RADIUS,
					RADIUS, RADIUS,
					RADIUS * 2, RADIUS * 2,
					1f, 1f,
					angle);
		}
	}
	batch.end();

	/** BOX2D LIGHT STUFF BEGIN */
	rayHandler.setCombinedMatrix(camera);

	if (stepped) rayHandler.update();
	rayHandler.render();
	/** BOX2D LIGHT STUFF END */

	long time = System.nanoTime();

	boolean atShadow = rayHandler.pointAtShadow(testPoint.x,
			testPoint.y);
	aika += System.nanoTime() - time;
     
	/** FONT */
	if (showText) {
		batch.setProjectionMatrix(normalProjection);
		batch.begin();
		
		font.draw(batch,
				"F1 - PointLight",
				0, Gdx.graphics.getHeight());
		font.draw(batch,
				"F2 - ConeLight",
				0, Gdx.graphics.getHeight() - 15);
		font.draw(batch,
				"F3 - ChainLight",
				0, Gdx.graphics.getHeight() - 30);
		font.draw(batch,
				"F4 - DirectionalLight",
				0, Gdx.graphics.getHeight() - 45);
		font.draw(batch,
				"F5 - random lights colors",
				0, Gdx.graphics.getHeight() - 75);
		font.draw(batch,
				"F6 - random lights distance",
				0, Gdx.graphics.getHeight() - 90);
		font.draw(batch,
				"F9 - default blending (1.3)",
				0, Gdx.graphics.getHeight() - 120);
		font.draw(batch,
				"F10 - over-burn blending (default in 1.2)",
				0, Gdx.graphics.getHeight() - 135);
		font.draw(batch,
				"F11 - some other blending",
				0, Gdx.graphics.getHeight() - 150);
		
		font.draw(batch,
				"F12 - toggle help text",
				0, Gdx.graphics.getHeight() - 180);

		font.draw(batch,
				Integer.toString(Gdx.graphics.getFramesPerSecond())
				+ "mouse at shadows: " + atShadow
				+ " time used for shadow calculation:"
				+ aika / ++times + "ns" , 0, 20);

		batch.end();
	}
}
 
Example 8
Source File: ChainLight.java    From box2dlights with Apache License 2.0 3 votes vote down vote up
/**
 * Attaches light to specified body with relative direction offset
 * 
 * @param body
 *            that will be automatically followed, note that the body
 *            rotation angle is taken into account for the light offset
 *            and direction calculations
 * @param degrees
 *            directional relative offset in degrees 
 */
public void attachToBody(Body body, float degrees) {
	this.body = body;
	this.bodyPosition.set(body.getPosition());
	bodyAngleOffset = MathUtils.degreesToRadians * degrees;
	bodyAngle = body.getAngle();
	applyAttachment();
	if (staticLight) dirty = true;
}