Hey guys, I'm trying to create a camera class that will move the camera exactly as the camera moves in games like Unreal Tournament.
The pitch is always calculated first, and the yaw is always rotated around the Y axis.
Assume that if the camera is pointing straight down, it is at a 180 degree angle. If it is pointing straight up, it is at a 0 degree angle. If the pitch is at 160 degrees (almost facing directly down), then the pitch should always remain at 160 degrees while you yaw left and right with the camera. This is how the Unreal Tournament camera works.
My camera class has three 3D vectors: LookAt, EyePosition, and UpVector. I've tried applying a rotation matrix to the LookAt position and then rotating that. Here's my math:
1) Assume in this example that the Eye is at [10,10,10] and LookAt is at [0,0,0]. You first move the eye to the origin temporarily for the rotation of the yaw.
TempAt = LookAt - EyePosition;
| | |
[-10,-10,-10] = [0,0,0] - [10,10,10]
2) Secondly, convert TempAt into a matrix and then rotate it. 'r' in this example is the angle (theta) in radians to which you wish to rotate the camera around the Y axis
TempAt
|
[-10,-10,-10]
|
[-10 0 0 0] [cos(r) 0 -sin(r) 0]
[0 -10 0 0] * [0 1 0 0]
[0 0 -10 0] [sin(r) 0 cos(r) 0]
[0 0 0 1] [0 0 0 1]
3) Thirdly, I convert the resulting product of the above matrix multiplication back into a vector, which is my new rotated lookat point. Also I move the look at point back in its original position. In this example, 'r' is the new value received from the rotation. 'nr' is the new absolute lookat point.
LookAt = TempAt + EyePosition;
| | |
[nr,nr,nr] = [r,r,r] + [10,10,10]
-----------
I am using OpenGL. I can't seem to figure out how to do this, and so far the camera isn't doing what I want it to do. IF anyone could help I would greatly appreciate it.
So far the X and Z values of the yaw always come out to be the same exact point after concatenating the rotation matrix. This results in a straight up and down movement of the camera (pitch) instead of a right and left movement (yaw).
Thank you!