Author Topic: question about Interact2D.reproject2D3DWS  (Read 2650 times)

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
question about Interact2D.reproject2D3DWS
« 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.



[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: question about Interact2D.reproject2D3DWS
« 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?

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Re: question about Interact2D.reproject2D3DWS
« 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.


[attachment deleted by admin]
« Last Edit: August 26, 2013, 12:12:56 am by rainfalls »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: question about Interact2D.reproject2D3DWS
« Reply #3 on: August 26, 2013, 08:42:32 pm »
Which renderer are you using? Make sure that your mouse coordinates match the frame buffer coordinates. Depending on the renderer and the configuration, window's title bars and offsets might be counted as part of the frame buffer but are not taken into account for the mouse coordinates. Make sure that 0,0 in the frame buffer matches 0,0 in the window.

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Re: question about Interact2D.reproject2D3DWS
« Reply #4 on: August 27, 2013, 01:14:01 am »
Egon, many thanks for your help. That's exactly what my problem was caused. I added the Y offset between the window and the canvas (I used GLCanvasRenderer) to the mouse position and the picking works perfectly now.