Panning a 3d viewport in 2d direction with rotated camera

Posted by Noob Game Developer on Game Development See other posts from Game Development or by Noob Game Developer
Published on 2012-10-19T12:25:06Z Indexed on 2012/10/19 17:20 UTC
Read the original article Hit count: 249

Filed under:
|
|

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?

Update:

I am getting an Idea but I am not sure how to do it :(

  1. Get the mouseX/Y deltas (xd,yd)
  2. Get the current camera coords (pos3d)
  3. Convert to screen coords (pos2d)
  4. Add deltas to screen coords (pos2d+ (xd,yd))
  5. Convert above coords to 3d coords

© Game Development or respective owner

Related posts about 3d

Related posts about actionscript-3