Small bug in AbstractCamera

Hi,



I'm using jME for a while and I have accidentally found a small bug in AbstractCamera. I made a simple jME app with multiple viewports and had some problems with mouse picking. I've used the Camera object associated with each viewport to convert the screen coordinates of mouse cursor to world coordinates:


        Vector2f screenPos = new Vector2f();
   screenPos.set(mouseX, renderer.getHeight()-mouseY);
   Vector3f worldCoords = viewportCamera.getWorldCoordinates(screenPos, 0);
   Vector3f worldCoords2 = viewportCamera.getWorldCoordinates(screenPos, 1);
   Ray mouseRay = new Ray(worldCoords, worldCoords2.subtractLocal(worldCoords));
   viewportRoot.findPick(mouseRay, pickResults);



Seems like the position of mouse cursor is in some cases converted incorrectly, resulting in incorrect Ray used for picking.

The problem lies in the getWorldCoordinates method in AbstractCamera class. Instead of

        tmp_quat.set(
                ( screenPosition.x / getWidth() - viewPortLeft ) * 2 - 1,
                ( screenPosition.y / getHeight() - viewPortBottom ) * 2 - 1,
                zPos * 2 - 1, 1 );


               
probably should be   
   

      tmp_quat.set(
                (( screenPosition.x / getWidth() - viewPortLeft ) / (viewPortRight - viewPortLeft)) * 2 - 1,
                (( screenPosition.y / getHeight() - viewPortBottom )  / (viewPortTop - viewPortBottom)) * 2 - 1,
                zPos * 2 - 1, 1 );




The method getScreenCoordinates of the same class should be fixed in the same manner. Instead of   
   

        store.x = ( ( tmp_quat.x + 1 ) / 2 + viewPortLeft ) * getWidth();
        store.y = ( ( tmp_quat.y + 1 ) / 2 + viewPortBottom ) * getHeight();



should be
   

        store.x = ( (( tmp_quat.x + 1 ) / 2) * (viewPortRight - viewPortLeft) + viewPortLeft ) * getWidth();
        store.y = ( (( tmp_quat.y + 1 ) / 2) * (viewPortTop - viewPortBottom) + viewPortBottom ) * getHeight();


     
     

     
Myrousz     

verfied, and committed



Thanks Myrousz!!