Author Topic: How to do 2D click to 3D object picking?  (Read 21473 times)

Offline androidman

  • byte
  • *
  • Posts: 14
    • View Profile
Re: How to do 2D click to 3D object picking?
« Reply #30 on: May 13, 2011, 06:04:02 am »
Hi EgonOlsen,

Based on http://www.jpct.net/wiki/index.php/Picking, it didn't work when i touch on object but if i touch on another area that is beside object --> it work.

Code: [Select]
SimpleVector p = Interact2D.reproject2D3D(camera, frameBuffer, (int)touchPos.x,(int)touchPos.y).normalize();
  Object[] objs= world.calcMinDistanceAndObject3D(camera.getPosition(), p, 1000);

how can i fix it?

i am using  the jpct-ae version that was posted at http://www.jpct.net/forum2/index.php/topic,1561.225.html.




Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to do 2D click to 3D object picking?
« Reply #31 on: May 13, 2011, 09:37:59 am »
You are not working in world space but in camera space. Please look at that wiki page again and use the ....WS-method that it mentions. Also make sure that your touch coordinates match your frame buffer coordinates. Sometimes a status bar or similar shifts the whole thing by a few pixels.

Offline androidman

  • byte
  • *
  • Posts: 14
    • View Profile
Re: How to do 2D click to 3D object picking?
« Reply #32 on: May 16, 2011, 09:21:59 am »
Thank you very much, EgonOlsen.

You are right. it worked. :D

Offline ginopeloso

  • byte
  • *
  • Posts: 13
    • View Profile
Re: How to do 2D click to 3D object picking?
« Reply #33 on: November 05, 2014, 05:57:50 pm »
What if I don't want the first object in the direction of my click but the one behind it?
In my model I have some objects which are transparent (like glasses); if the user clicks these ones I have to ignore them and try to pick another object behind the clicked one in the same direction of the click (if this one is transparent again the one behind, until I pick a non-transparent object or nothing)

I tried with the following code but did not succeed; the app continues to pick always the same object:
Code: [Select]
SimpleVector dir = Interact2D.reproject2D3D(camera, frameBuffer, screenX, screenY);
Object[] res = world.calcMinDistanceAndObject3D(camera.getPosition(), dir, 10000);
Object3D clickedObject = (Object3D)res[1];
while (clickedObject != null && clickedObject.getName().startsWith("transparent")) {
dir.z = clickedObject.getTransformedCenter().z;
res = world.calcMinDistanceAndObject3D(camera.getPosition(), dir, 10000);
clickedObject = (Object3D)res[1];
}

Is there a way for doing it?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to do 2D click to 3D object picking?
« Reply #34 on: November 05, 2014, 10:19:24 pm »
Just make all transparent objects invisible before doing the picking (and reset them afterwards).