My program moves an object with the mouse
After I rotate the camera the object moves but no longer in the direction of the mouse movement
I have this to rotate camera:
if(rotatingCamera){
if(mouseButton==1){
//change radius and zoom in/out with respect to the origin as mouse is moved vertically
rad += (mouseY-y)*.5;
//rotate the camera about the y-axis as the mouse is moved horizontally
thetaCam[0] += (mouseX-x)4PI/180;
}
I do this to move object
if(moveObject){
//move object around the x-z plane of the scene
obj.x -= (mouseX-x).4cos(thetaCam[0]) + (mouseY-y).4sin(thetaCam[0]);
obj.z += -1*(mouseX-x).4sin(thetaCam[0]) + (mouseY-y).4cos(thetaCam[0]);
}
when I display I do this:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0,0,-rad);
glRotatef(thetaCam[1],1,0,0);
glRotatef(thetaCam[0],0,1,0);
//display the object
...
glTranslatef(obj.x,obj.y,obj.z);
//draw object
After camera rotation, the object moves incorrectly with mouse.
Do I need to keep track of the camera x,y z coordinates?