Hello! So I recently went from OpenGL 2.X (using now deprecated functions like, glTranslate etc.) to using OpenGL 3.2. This also meant implementing matrices manually for all of my transformation. While this is extremely fun and very enjoyable, it's hard.
My problem is that when I move my Camera (Viewmatrix) in the +Y direction, my OBJ that I loaded into my game is moving upwards (hence im moving the camera "downwards" relative to the object). This also affects moving in +/- X. + Goes left, - Goes right.
Why is it that I have this problem? I've checked my Projectionmatrix and it seems to be correct, according to http://ogldev.atspace.co.uk/www/tutorial12/12_11.png
Projectionmatrix
perspectiveMatrix.setIdentity();
float aspectRatio = WIDTH / HEIGHT;
float zRange = zNear - zFar;
perspectiveMatrix.m00 = (float) (1.0f / (aspectRatio * Math.tan(degreesToRadians(fieldOfView / 2.0f))));
perspectiveMatrix.m11 = (float) (1.0f / (Math.tan(degreesToRadians(fieldOfView / 2.0f))));
perspectiveMatrix.m22 = (-zNear - zFar) / zRange;
perspectiveMatrix.m23 = 1;
perspectiveMatrix.m32 = (2 * zFar * zNear) / zRange;
Modelmatrix is Identity.
Viewmatrix is changed when I move:
if(moveUp)
Matrices.viewMatrix.translate(new Vector3f(0, 1.0f * moveSpeed, 0));
if(moveLeft)
Matrices.viewMatrix.translate(new Vector3f(-1.0f * moveSpeed, 0, 0));
if(moveDown)
Matrices.viewMatrix.translate(new Vector3f(0, -1.0f * moveSpeed, 0));
if(moveRight)
Matrices.viewMatrix.translate(new Vector3f(1.0f * moveSpeed, 0, 0));
Vertex Shader:
#version 330
uniform mat4 perspectiveMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
layout(location = 0) in vec3 position;
out vec4 color;
void main(){
gl_Position = perspectiveMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
color = vec4(position, 1.0);
}
All sources:
http://pastebin.com/yZExLWpp - Window.java
http://pastebin.com/yBRcdnRK - Matrices.java
http://pastebin.com/mJa1j5ri - Camera.java
http://pastebin.com/UM7BQdrR - Cube.java
Tell me if you need more. I don't believe you should though.
Thanks!, Slushy.