Example usage for com.badlogic.gdx.math Vector2 scl

List of usage examples for com.badlogic.gdx.math Vector2 scl

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 scl.

Prototype

public Vector2 scl(float x, float y) 

Source Link

Document

Multiplies this vector by a scalar

Usage

From source file:org.ams.testapps.prettypaint.CircleAndBackground.java

License:Open Source License

/**
 * @param screenX pixel./*w  ww .j  av  a  2  s  .  co m*/
 * @param screenY pixel.
 * @return position of touch in "world units", with center of screen as origin.
 */
public Vector2 getPositionOfTouch(int screenX, int screenY) {

    float halfWidth = Gdx.graphics.getWidth() * 0.5f;
    float halfHeight = Gdx.graphics.getHeight() * 0.5f;

    Vector2 pos = new Vector2(screenX - halfWidth, halfHeight - screenY);
    pos.scl(1f / halfWidth, 1f / halfHeight);

    pos.scl(camera.zoom);

    // convert to world units relative to center of screen
    pos.scl(camera.viewportWidth * 0.5f, camera.viewportHeight * 0.5f);

    return pos;
}