Skip to main content
gamedev.net
🔒 Locked

camera rotation

Started by magneeto 1 reply 400+ views
Original Post
magneeto
magneeto
hi, i can't understand how the following rotations of the camera is working. the rotations are done to make a camera's frustum point at the focal point. (xcam_1,ycam_1,zcam_1) is the camera's position. xfoc, yfoc and zfoc is focal point. GLdouble a = xfoc_1 - xcam_1, b = yfoc_1 - ycam_1, c = zfoc_1 - zcam_1; GLdouble v = sqrt(b * b + c * c); GLdouble alpha = atan( b/c)*180./3.1416; GLdouble beta = -atan(a/v)*180./3.1416; GLdouble g = far_1, h = g * tan(fovy_1*(width/winHeight_1)/2* 3.1416/180.); GLdouble e = near_1, f = e * tan(fovy_1/2. * 3.1416/180.); glTranslatef( xcam_1, ycam_1, zcam_1); glRotatef( -alpha, 1., 0., 0.); glRotatef( -beta, 0., 1., 0.);
Zakwayda
Zakwayda
Quote:
Original post by magneeto
hi,

i can't understand how the following rotations of the camera is working. the rotations are done to make a camera's frustum point at the focal point.
(xcam_1,ycam_1,zcam_1) is the camera's position. xfoc, yfoc and zfoc is focal point.

GLdouble a = xfoc_1 - xcam_1, b = yfoc_1 - ycam_1, c = zfoc_1 - zcam_1;
GLdouble v = sqrt(b * b + c * c);
GLdouble alpha = atan( b/c)*180./3.1416;
GLdouble beta = -atan(a/v)*180./3.1416;

GLdouble g = far_1, h = g * tan(fovy_1*(width/winHeight_1)/2* 3.1416/180.);
GLdouble e = near_1, f = e * tan(fovy_1/2. * 3.1416/180.);

glTranslatef( xcam_1, ycam_1, zcam_1);
glRotatef( -alpha, 1., 0., 0.);
glRotatef( -beta, 0., 1., 0.);
There are some problems with that code, IMO, but basically (I think) it's equivalent to:
gluLookAt(xcam_1, ycam_1, z_cam1, xfoc_1, yfoc_1, zfoc_1, 0.0f, 1.0f, 0.0f);
g, h, e and f don't appear to be used in the example; as for the rest, it performs a spherical coordinate conversion using the camera position, and uses the resulting angles to orient the camera so that it's directed at the focal point.
magneeto
magneeto
you are correct about the gluLookAt(). the g,e,f,h are used to draw a frustum of the camera which i did not include in the post. my main problem was understanding the spherical coordinate conversion. Ok now i don't know anything about this type of conversion. any links to tutorials is going to be helpful.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.