How do I move the camera sideways in Libgdx?
- by Bubblewrap
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:
Create a Matrix4 mat
Determine the orthogonal vector v between camera.direction and camera.up
Translate mat by v*x
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));