LibGDX - Get TouchPoint X and Y in Perspective?

Hi,

I add a perspective camera.

    cam = new PerspectiveCamera(45, 480, 320);

When I try to get the touchpoints with

    (Gdx.input.getX(), Gdx.input.getY())

I get wrong numbers. My Perspective width is 480.

When I touch with my finger the screen (rightmost), I get 1196.

This is my screen resolution of my device.

EDIT: I also get wrong numbers when I try:

      private Vector3 touchPoint;

       cam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));

       System.out.println(touchPoint.x+" | "+touchPoint.y);

I get something like this with touchpoint.x: -6 to 0.75

Not sure if this helps…

ProjectTest.java

Nevermind that’s the wrong file… Give me a sec to find the one I was actually talking about lol.

Hi,

I solved it now so:


float X = MathUtils.round(Gdx.input.getX()*(480f/1196f));

float Y = MathUtils.round(Gdx.input.getY()*(320f/720f));

If there is a better solution, then please post it.