I am using below code to pan the viewport (action script 3 code using flare3d framework)
_mainCamera.x-= Input3D.mouseXSpeed; _mainCamera.z+= Input3D.mouseYSpeed;
Where as Input3D.mouse[X|Y]Speed gives the displacement of the mouse on the X/Y axis starting from the position of the last frame.
This works perfect if my camera is not rotated. However, if I rotate the camera (x by 30, y by 60) and pan the camera then it goes wrong. Which is actually correctly panning according to the code. But this is not desired and I know I need to do some math to get the correct x/y which I am not aware of it.
Can some one help me achieving it?
I am getting an Idea but I am not sure how to do it :(
- Get the mouseX/Y deltas (xd,yd)
- Get the current camera coords (pos3d)
- Convert to screen coords (pos2d)
- Add deltas to screen coords (pos2d+ (xd,yd))
- Convert above coords to 3d coords