I have a camera in my Open GL ES 2.0 app. Using translation/rotation matrices, I can move and rotate the scene using the WSAD keys for movement/strafe and the arrow keys for rotation. I do this by pulling the "look at" vector from the modelview matrix on each loop iteration. I then normalize and add this to the translation matrix.
The problem I'm having is getting the rotation to work. I can either translate or rotate the scene just fine, but not both. If I try to rotate the scene, it always rotates around the origin (0,0,0). If I try to pre-multiply the translation matrix with the current rotation angle, my translation always goes in the same position prior to the translation (e.g. W goes right, instead of forward when the scene is rotated 90 degrees).
I can pull the look at, or current camer orientation vector from the modelview matrix. I can then use this value to add to the translation matrix to make the camera move forward. I use the dot product of Z and Y (which is always 1.0, since I never move up) to derive the strafe vector. This all works fine, I just need to combine the rotation!
Here's an example from my code:
I apologize if I left out a bunch of info. I'm happy to provide more if necessary.
//calculate strafe vector using cross product of Z and Y
camera_position[z] += (direction_move[z] * speed); //WS keys (fwd/back)
camera_position[x] += (direction_strafe[x] * speed); //AD keys (strafe)
//construct translation matrix
mat4x4_translate(translate, camera_position[x], 0.0, camera_position[z]); //Y is 0.0 since we never go up/down