Java Code Examples for com.badlogic.gdx.math.Vector2#mul()

The following examples show how to use com.badlogic.gdx.math.Vector2#mul() . 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: CalibrationActivity.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void calculateAverageGravity() {
    Vector2 gravity = Vector2Pool.obtain();

    for (int i = 10; i < _gravityPoints.size(); i++) {
        gravity.add(_gravityPoints.get(i));
    }
    gravity.mul(-1.0f / _gravityPoints.size());

    Prefs.putFloat(PrefKeys.CALIBRATION_X, gravity.x);
    Prefs.putFloat(PrefKeys.CALIBRATION_Y, gravity.y);
}
 
Example 2
Source File: Scene2dFollowPathTest.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Rotates the specified vector angle rads around the origin */
private static Vector2 rotateVectorAroundOrigin (Vector2 vector, float radians) {
	// Init and rotate the transformation matrix
	tmpMatrix3.idt().rotateRad(radians);

	// Now transform the object's vertices
	return vector.mul(tmpMatrix3);
}
 
Example 3
Source File: WorldController.java    From tilt-game-android with MIT License 4 votes vote down vote up
/**
 * Game loop
 */
@Override
public void onManagedUpdate(float pSecondsElapsed) {
    super.onManagedUpdate(pSecondsElapsed);

    if (_levelController == null) {
        return;
    }

    if (_started) {
        // update gravity from phone orientation
        EulerAngles eulerAngles = _orientationProvider.getEulerAngles();
        // get limited roll & pitch
        float roll = MathUtils.bringToBounds(-MAX_ORIENTATION_ANGLE, MAX_ORIENTATION_ANGLE, eulerAngles.getRoll());
        float pitch = MathUtils.bringToBounds(-MAX_ORIENTATION_ANGLE, MAX_ORIENTATION_ANGLE, eulerAngles.getPitch());
        // correct for screen orientation, different on tablets than on phones
        float swap;
        switch (_screenRotation) {
            case Surface.ROTATION_0:
                break;
            case Surface.ROTATION_270:
                swap = pitch;
                pitch = -roll;
                roll = swap;
                break;
            case Surface.ROTATION_180:
                pitch = -pitch;
                roll = -roll;
                break;
            case Surface.ROTATION_90:
                swap = pitch;
                pitch = roll;
                roll = -swap;
                break;
        }
        _gravity.set(_radToGravity * roll, _radToGravity * pitch);
        _gravity.add(_gravityCorrection);
        _physicsWorld.setGravity(_gravity);

        checkDestroyBall();

        // update ball location, if there's a ball, we're not animating, and the level hasn't been completed
        if (_ball != null && !_isAnimating && !_isLevelCompleted) {
            _timePassed += pSecondsElapsed;

            // update physics world
            _physicsWorld.onUpdate(pSecondsElapsed);

            // check if the ball needs to be destroyed
            checkDestroyBall();

            // recheck, since world update may have removed the ball
            if (_ball != null && !_isAnimating) {
                Vector2 ballPosition = _ball.getPosition();
                ballPosition.mul(PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
                _ballSprite.setPosition(ballPosition.x, ballPosition.y);
            }

            if (_levelDuration > 0) {
                updateTimer(pSecondsElapsed);
            }
        }
    }
}