Hi Everyone,
I posted a thread earlier about rotating too fast around an object, but I fixed that problem. Now I have one last problem. I cannot seem to completely rotate around my object. I’ll rotate to a point, and then the object will appear to ‘jump’ to a new location. Also, the eye of my camera appears to move farther away and then closer away in an oscillating manner. I can record this behavior if requested.
The way this is set up is initially I am looking towards the negative Z axis from the positive Z axis. I am looking at the origin.
I’ve been working on this camera movement and I’m just frustrated. Any help would be appreciated. I know I’m close. My code for this is listed below.
void sceneTransformation(){
glLoadIdentity( );
GLdouble radx = (GLdouble)(anglex*PI/180.);
GLdouble rady = (GLdouble)(angley*PI/180.);
GLdouble l = sqrt( pow(distX, 2) + pow(distY, 2) + pow(distZ, 2) );
GLdouble phi = atan(distZ/distX) + radx;
GLdouble theta = acos(distY/l) + rady;
// limit what angles theta and phi can take.
if(theta >= 2*PI)
theta = fmod((GLdouble)theta, 2*PI);
if(phi >= 2*PI)
phi = fmod((GLdouble)phi, 2*PI);
GLdouble deltaX = l*sin(theta)*cos(phi);
GLdouble deltaY = l*cos(theta);
GLdouble deltaZ = l*sin(theta)*sin(phi);
GLdouble up_x = deltaX - l*sin(theta-1.0)*cos(phi);
GLdouble up_y = deltaY - l*cos(theta-1.0);
GLdouble up_z = deltaZ - l*sin(theta-1.0)*sin(phi);
gluLookAt((distanceX + deltaX), (distanceY + deltaY), (distanceZ + deltaZ), 0, 0, 0, up_x,up_y,up_z);
}