I use this code in my GLSL vertex shader, where v_position
is the vertex position:
gl_Position = v_position * u_camera;
and set u_camera
as follows:
meshShader.setUniformMatrix("u_camera",
camera.view.mul(camera.projection).inv());
With the camera being an PerspectiveCamera
of fov 45, width = aspect ratio and height = 1
This code is working when translating the camera over the z axis:
if (Gdx.input.isKeyPressed(Keys.W)) {
camera.translate(0, 0, CAMERA_SPEED * Gdx.graphics.getDeltaTime());
} else if (Gdx.input.isKeyPressed(Keys.S)) {
camera.translate(0, 0, -CAMERA_SPEED * Gdx.graphics.getDeltaTime());
}
But not when doing the same thing as above on the x axis, with the A or D keys.
The mesh (a triangle) looks like this before i press A or D (Translating with W and S is fine)
But when translating over the X axis it it looks like this:
I don't know anything of matrix math, and I made this code experimenting with the various matrices of the Camera
class
EDIT : This code camera.projection.mul(camera.view.inv())
does a similiar thing