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

The following examples show how to use com.badlogic.gdx.math.MathUtils#degreesToRadians() . 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: SteeringActor.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private void applySteering (SteeringAcceleration<Vector2> steering, float time) {
	// Update position and linear velocity. Velocity is trimmed to maximum speed
	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(getZeroLinearSpeedThreshold())) {
			float newOrientation = vectorToAngle(linearVelocity);
			angularVelocity = (newOrientation - getRotation() * MathUtils.degreesToRadians) * time; // this is superfluous if independentFacing is always true
			setRotation(newOrientation * MathUtils.radiansToDegrees);
		}
	}
}
 
Example 2
Source File: GLTFCameraExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private GLTFCamera export(Camera camera) {
	GLTFCamera glCamera = new GLTFCamera();
	if(camera instanceof PerspectiveCamera){
		PerspectiveCamera pcam = (PerspectiveCamera)camera;
		glCamera.type = "perspective";
		glCamera.perspective = new GLTFPerspective();
		glCamera.perspective.yfov = pcam.fieldOfView * MathUtils.degreesToRadians; // TODO not sure
		glCamera.perspective.znear = camera.near;
		glCamera.perspective.zfar = camera.far;
		glCamera.perspective.aspectRatio = camera.viewportWidth / camera.viewportHeight; // TODO not sure
		// TODO aspect ratio and fov should be recomputed...
	}
	else if(camera instanceof OrthographicCamera){
		OrthographicCamera ocam = (OrthographicCamera)camera;
		glCamera.type = "orthographic";
		glCamera.orthographic = new GLTFOrthographic();
		glCamera.orthographic.znear = camera.near;
		glCamera.orthographic.zfar = camera.far;
		glCamera.orthographic.xmag = camera.viewportWidth * ocam.zoom; // TODO not sure
		glCamera.orthographic.ymag = camera.viewportHeight * ocam.zoom; // TODO not sure
	}
	else{
		throw new GdxRuntimeException("unsupported camera type " + camera.getClass());
	}
	
	return glCamera;
}
 
Example 3
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 4
Source File: VMath.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
public static Vector2 fromDegrees (float degrees) {
	float radians = degrees * MathUtils.degreesToRadians;
	retDeg.set(VMath.fromRadians(radians));
	return retDeg;
}
 
Example 5
Source File: SteeringActor.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
@Override
public float getOrientation () {
	return getRotation() * MathUtils.degreesToRadians;
}
 
Example 6
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;
}