3D Camera with modern OpenGL

Hey guys.
First of all merry christmas and happy holidays to everyone on the forum! :smiley:
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.

Hey, merry christmas to you too :slight_smile:

I suggest you check out this tutorial here, made by one our members:

http://www.java-gaming.org/topics/lwjgl-tutorial-series-creating-a-3d-camera/30871/view.html

I learned it using this article. Honestly you probably just messed up your matrices somewhere, and there’s no shame in that.

Thank you very much, using your link I’ve managed to get the camera working in just a few minutes. :smiley:
It seems like quite a basic camera, but now that at least I have something to go around with in my scene and observe the models I guess I’ll have time to expand it later on. 8)

I’ve added quite a few things to the camera, however I can’t seem to figure out how should I move it on the y axis as well (the tutorial you linked moves the camera only on the Z and the X axis).
Of course I’m not talking about increasing the or decreasing the Y value of the camera but when I move forward or backward with the camera I would like my height to increase/decrease depending on my rotation on the X axis. I’ve tried adding something like this to the move method:

position.y += amount*Math.sin(Math.toRadians(rotation.x+90*direction));

but it obviously doesn’t work (I have no idea what I’m doing, damn you trigonometry sigh :emo:).
Anyone could help me out on getting this right and hopefully understanding the math behind it? :slight_smile:

Edit: Okay, I’ve got it working, so far everything seems to be okay. If anyone is interested I did it this way:


if(direction == 1f)
	position.y += amount*Math.sin(Math.toRadians(rotation.x));

This way it only increases the Y value if you’re moving on the Z axis (so if you just want to move sideways it won’t be modified).
Still pretty much have no idea about the math behind it, I’m pretty much okay with vectors in 2D but when it comes to 3D it just almost always gets too complicated for me.
Probably will pick up a book on algebra and trigonometry. :expressionless: