Hey guys.
First of all merry christmas and happy holidays to everyone on the forum!
Currently I’m trying to write my own engine on top of LWJGL to understand modern OpenGL better and get some basics down but I’m stuck at the part of writing a 3D camera.
The only decent tutorial I managed to find on the subject is this: http://games.greggman.com/game/webgl-3d-cameras/ (it’s for WebGL but it’s really easy to port it to LWJGL).
I’ve tried to make my own camera class based on the tutorial but it produces weird effects (turns models upside down and such) so I obviously mess up somewhere, the only question is where?! ???
Here are my classes:
Camera.java - http://pastebin.com/LkfMR4NH
TestCamera.java (an instance of the camera class) - http://pastebin.com/gmP84PGQ
In the vertex shader the vertex position get’s calculated as follows: projectionMatrixviewMatrixvec4(in_Position, 1.0);
, where in_Position is a vec3 of the vertex’s local position. Currently I’m not using model matrices but I will implement that later.
If I understand the tutorial correctly to get the forward vector (or z axis vector) I have to subtract the target vector from the camera position vector, then normalise the result.
To get the right vector (or x axis) I have to take the cross product of my forward vector and a unit vector that points upwards on the Y axis.
To get the real up vector (or y axis) I have to take the cross product of the up and the right vector and voilá.
Of course to get the backward, left and down vectors I just have to negate the appropriate vectors.
After I did this all to apply the transformations I can just fill up a 4x4 matrix with the given data and use it as my view matrix.
However, as you can see in my code I do exactly this and it just doesn’t seem to work.
Any help would be very much appreciated since I’m trying to solve this problem for quite a few hours now.