Carsten Neumann schreef:
> Hi Jan,
>
Hi Carsten,
> Jan wrote:
>
>> Hi Carsten,
>>
>> Carsten Neumann schreef:
>>
>>> there is Camera::getWorldToScreen(Matrixr &result,
>>> const Viewport &port) which should give you the matrix
>>> for that transformation.
>>>
>>>
>> I guess that the multiplication of a vector with this transformation
>> matrix results in the clipping coordinates of my object (the 3D
>> pointer) ? After this, I rescale these coordinates according to the
>> viewport size. These two steps are done in the two routines below.
>>
>> After the WorldToViewportCoordinates() method, I'm calling the
>> calcViewRay() function with the obtained X and Y coordinates. When I use
>> the calculated ray for my picking routine, it doesn't give the expected
>> results: the picking ray is not perpendicular on the pointer into the
>> screen.
>>
>> To clarify my intentions, please look at this screenshot:
>> http://lumumba.uhasselt.be/~meskensj/opensg/opensg_picking.JPG. The red
>> sphere is my pointer, when a ray is shot from the pointer, I expect that
>> the big white box should be selected. Well, this is not the case! Can
>> someone explain this behavior and/or give me some advice to solve this
>> problem?
>>
>
> did you insert some std::cout statements to see what coordinates you
> actually get ?
>
Yes, I have. Below are some std::cout statements. In the output below, I
only translate my pointer in the X and Y direction. It's already strange
to mention that the direction of the calculated ray changes when I
translate my pointer in the x and y direction (without any rotate).
Debugging the coordinate transformations clarified also that the 0,0
point of the viewport coordinates is located at the top left of my
viewport (I think this is correct?).
The debug output below is structured like this :
Pointer position = the position of the pointer in 3D
Pointer clipping coordinates = the result of WorldToClippingCoordinates
Pointer viewport coordinates = the result of WorldToViewportCoordinates
Ray direction = the direction of the ray calculated with calViewRay
(with the pointer viewport coordinates)
This is the debugging output :
Pointer position : 0.05,0.00999999,-1
Pointer clipping coordinates : 0.090533,0.0241421,-1.07374e+008
Pointer viewport coordinates : 348.971,234.206
Ray direction : 0.0671957,0.0167989,-0.997598
Pointer position : 0.055,0.00999999,-1
Pointer clipping coordinates : 0.0995863,0.0241421,-1.07374e+008
Pointer viewport coordinates : 351.868,234.206
Ray direction : 0.0743573,0.0167904,-0.99709
Pointer position : 0.065,0.00999999,-1
Pointer clipping coordinates : 0.117693,0.0241421,-1.07374e+008
Pointer viewport coordinates : 357.662,234.206
Ray direction : 0.0886451,0.0167707,-0.995922
Pointer position : 0.07,0.00999999,-1
Pointer clipping coordinates : 0.126746,0.0241421,-1.07374e+008
Pointer viewport coordinates : 360.559,234.206
Ray direction : 0.0957691,0.0167596,-0.995263
Pointer position : 0.07,0.005,-1
Pointer clipping coordinates : 0.126746,0.0120711,-1.07374e+008
Pointer viewport coordinates : 360.559,237.103
Ray direction : 0.0957781,0.00957781,-0.995357
Pointer position : 0.07,-0.005,-1
Pointer clipping coordinates : 0.126746,-0.0120711,-1.07374e+008
Pointer viewport coordinates : 360.559,242.897
Ray direction : 0.0957822,-0.00239456,-0.995399
Pointer position : 0.07,-0.00999999,-1
Pointer clipping coordinates : 0.126746,-0.0241421,-1.07374e+008
Pointer viewport coordinates : 360.559,245.794
Ray direction : 0.0957781,-0.00957781,-0.995357
Pointer position : 0.07,-0.015,-1
Pointer clipping coordinates : 0.126746,-0.0362132,-1.07374e+008
Pointer viewport coordinates : 360.559,248.691
Ray direction : 0.0957691,-0.0167596,-0.995263
>
>> //Convert a point in the world to the clipping coordinates
>> void Renderer::WorldToClippingCoordinates(Vec3f& point, float& x, float&
>> y, float& z)
>> {
>> Matrix wts;
>> m_matrixCamera->getWorldToScreen(wts,*m_viewport);
>> Vec3f dest;
>> wts.multVecMatrix(point,dest);
>>
>> x = dest[0];
>> y = dest[1];
>> z = dest[3];
>> }
>>
>> //Map to viewport coordinates
>> void Renderer::WorldToViewportCoordinates(Vec3f& point, float& x, float& y)
>> {
>> float _x,_y,_z;
>> WorldToClippingCoordinates(point,_x,_y,_z);
>> //Map to a 0..1 interval
>> _x = (_x + 1)/2.0;
>> _y = (_y + 1)/2.0;
>> //Scale
>> x = _x * SCREEN_WIDTH;
>> y = ((_y * SCREEN_HEIGHT) - SCREEN_HEIGHT)*(-1);
>> }
>>
>
> hm, only thing that springs to mind is that you are using Vec3f and
> OpenSG handles vectors different from points, i.e. vectors ignore
> translation when transformed, so you might want to try using a Pnt3f there.
>
I changed the Vec3f's to Pnt3f's but that doens't solve the problem :-(.
I have also some extra screenshot to show the strange behavior of my
picking routine :
http://lumumba.uhasselt.be/~meskensj/opensg/opensg_picking2.JPG
Thanks in advance,
Jan Meskens
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users