I want to implement a camera that allows full 360 degree turns for yaw, pitch and roll. I'm finished with yaw and pitch, but roll seems to be a bit tricky =)
The following code is supposed to produce the correct view- and up-vectors for the gluLookAt-function (and does).
x is right, y up and z points into the screen. fU and fV are angles that describe where the camera is looking at or if you so want, yaw and pitch in a flight simulator.Code:vView.x= sin(fU) *cos(fV); vView.y= sin(fV); vView.z= cos(fV) *cos(fU); vUpVector.x= sin(fU) *cos(fV +PI/2); vUpVector.y= sin(fV +PI/2); vUpVector.z= cos(fV +PI/2) *cos(fU); gluLookAt(vPosition.x, vPosition.y, vPosition.z, vView.x +vPosition.x, vView.y+vPosition.y, vView.z+vPosition.z, vUpVector.x, vUpVector.y, vUpVector.z);
My problem now is that I don't know how to roll the camera. I know I would have to rotate the up-vector around the viewvector and possibly also modify the viewvector because if the upvector has been rolled to point left (i.e.) then a pitch would result in a yaw, wouldn't it ?...
I guess what I'm asking for is, if somebody can tell me how to rotate a vector around it's normal (that's what I need to do, right?). This and any other comments would be very appreciated.
btw, I know the code is not at all optimized. I will store sine and cosine in a variable and use that instead of calling the functions again and again once rolling is implemented. I could also write -sin(fV) instead of cos(fV +PI/2), but my primary aim is working code and thats not yet accomplished :/