#### rainfalls

• byte
• Posts: 27
« on: August 24, 2013, 09:31:33 pm »
Hello, I have a question about Interact2D.reproject2D3DWS.

Basically I was to pick an object3D by the mouse click on the desktop window. Following the Picking page of jpct wiki, I used the compatible way:

fb = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
..........
..........
SimpleVector dir = Interact2D.reproject2D3DWS(cam, fb, clickX, clickY).normalize();
Object[] res = calcMinDistanceAndObject3D(cam.getPosition(), dir, 50000);

However I found that the picking only worked to the objects which were in the center area of the window AND when the camera is very close to the target object. The attached picture shows my 3D scene (each colorful triangle in the picture is an instance of Object3D).

I feel rather confused on the returned SimpleVector of Interact2D.reproject2D3DWS. Can anyone please explain it a bit or give me some suggestion on my problem? Many thanks.

#### EgonOlsen

• Posts: 11880
« Reply #1 on: August 24, 2013, 11:04:01 pm »
The returned vector is actually a transformed position vector. The Methode calculates the position in 3d camera space that lies on the view plane and will be projected onto your given 2d coordinates. But because in camera space, the camera's position is the origin, this position vector can be seen as a direction vector from the origin to that point. This vector will then be transformed into world space and returned.
However, that doesn't explain your problem. What's the scale of this world, i.e. how far away are the objects that can't be picked?

#### rainfalls

• byte
• Posts: 27
« Reply #2 on: August 26, 2013, 12:09:07 am »
Thanks Egon for the detailed explanations.

The size of the 3D box containing my objects is about 12000 * 12000 * 1000 and the length of my single object is around 100-200. When I couldn't pick anything, the distance between the camera and objects was about 10000. And when I moved the camara closer with the distance below 1000 (when the target object filled or half filled the window), it could be easily picked. However I could hardly work out an exact value as the critical point. But the objects near the window center were always more "easily" to be picked ( when I said "easily", I mean those objects could be picked when the camera was relatively farther).

I had some further tests today and found something interesting. The attached picture shows my 3D scene. I adjusted the camera and made the objects be positioned in a line along the Y axis in the window center. Then when object 1 was clicked, object 2 was selected instead; and when object 3 was clicked, object 4 was selected. I tried to repeat this test on X axis, but failed to pick anything at the similar camera distance. It looked the Y coordinate in camera space was doubled during the transformation?

Many thanks.

« Last Edit: August 26, 2013, 12:12:56 am by rainfalls »

• Posts: 11880