How do I move the camera sideways in Libgdx?

Posted by Bubblewrap on Game Development See other posts from Game Development or by Bubblewrap
Published on 2012-04-02T08:37:43Z Indexed on 2012/04/02 17:42 UTC
Read the original article Hit count: 400

Filed under:
|

I want to move the camera sideways (strafe). I had the following in mind, but it doesn't look like there are standard methods to achieve this in Libgdx.

If I want to move the camera sideways by x, I think I need to do the following:

  1. Create a Matrix4 mat
  2. Determine the orthogonal vector v between camera.direction and camera.up
  3. Translate mat by v*x
  4. Multiply camera.position by mat

Will this approach do what I think it does, and is it a good way to do it? And how can I do this in libgdx? I get "stuck" at step 2, as I have not found any standard method in Libgdx to calculate an orthogonal vector.

EDIT: I think I can use camera.direction.crs(camera.up) to find v. I'll try this approach tonight and see if it works.

EDIT2: I got it working and didn't need the matrix after all:

Vector3 right = camera.direction.cpy().crs(camera.up).nor();
camera.position.add(right.mul(x));

© Game Development or respective owner

Related posts about camera

Related posts about libgdx