Click on 3d object not working

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Click on 3d object not working

Postby androdever » Tue Sep 05, 2017 3:37 pm

Hi guys!
I read tutorial about interacting with 3d objects https://xoppa.github.io/blog/interactin ... d-objects/.
This sample it is work prefectly.

My application contains one 3d object at (0,0,0) and Camera.
Code: Select all
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 10, 20);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 300f;


I'm using MVP matrix provided from ARCore to rotate the camera like this:
Code: Select all
cam.combined.set(getMVPMatrix());
in render method.
It looks good, the object keeps constant position while I move my phone.

The problem is next:
How to detect click on object after
Code: Select all
 cam.combined.set(getMVPMatrix())
?
I get the ray from camera
Code: Select all
 Ray ray = cam.getPickRay(screenX, screenY);

But ray does not take into account the transformation. It is like [(0, 10, 20):(-0.16254206, -0.74434984, -0.6477063)] but position has been already changed.
I try to mutliply it to MVP matrix but it doesn't work too.
Code: Select all
 ray.mul(getMVPMatrix());


Help me please!
Thank you.
androdever
 
Posts: 3
Joined: Tue Sep 05, 2017 3:04 pm

Re: Click on 3d object not working

Postby androdever » Wed Sep 06, 2017 2:27 pm

I found the solution.
Click not working because I don't calculate invProjection matrix of camera.

Just add this code in render method after cam.combined.set(mvpMatrix);
Code: Select all
 cam.invProjectionView.set(cam.combined);
Matrix4.inv(cam.invProjectionView.val);
cam.frustum.update(cam.invProjectionView);
androdever
 
Posts: 3
Joined: Tue Sep 05, 2017 3:04 pm


Return to General Development

Who is online

Users browsing this forum: No registered users and 4 guests