Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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 *;
} else if (Gdx.input.isKeyPressed(Keys.S)) {
        camera.translate(0, 0, -CAMERA_SPEED *;

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

share|improve this question
up vote 1 down vote accepted

Well first of all, you're (probably, judging by the notation) inverting the view AND projection matrices. This isn't correct. The inversion is only a part of the creation of a view matrix.

Also, an orthographic camera doesn't have a FOV, so i'm not sure if you haven't gotten some things mixed up because of that as well.

share|improve this answer
So sorry it's a PerspectiveCamera – UberLambda Mar 30 '13 at 14:32
And, yes, I'm inverting the product of the two matrices. – UberLambda Mar 30 '13 at 14:38
Aside from that, gl_Position = v_position * u_camera; should be gl_Position = u_camera * v_position; since OpenGL uses column matrices. I'd recommend you to read the Matrices tutorial on – sarahm Mar 30 '13 at 14:41
Awesome, it solved my problem. Thanks. – UberLambda Mar 30 '13 at 19:09
@TM3P I was talking to sarahm, his comment is incorrect, i have no idea why it has 2 upvotes. It applies to your situation because that's how your matrices are constructed, but it's not a rule. It's alright if you don't understand this at all, but he should if he's commenting on it. BTW, if you'd like to learn linear algebra in a very accessible manner, try Game Engine Architecture by Jason Gregory, the information is presented in a VERY accessible manner and it's by a game developer for game developers. – dreta Mar 31 '13 at 12:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.