I am trying to move a sphere in 3D with the mouse, but I am having problems with my routine. I can move the sphere in the x and y directions, but not the z direction. For the x and the y movement, I use gluProject and gluUnProject, and I would like to do the same with the z movement. Basically, I want to translate y movement of the mouse into z movement of the sphere. I accomplish motion with the x and the y directions by using glProject to obtained the normalized z coordinate and putting this normalized coordinate into glUnProject along with my mouse movement. My code for my attempt to move the sphere in the z direction looks like the following. (This code is actually part of a spline surface program, so that’s why there is a 2d matrix. realy is viewport - (GLint)y - 1.)
gluUnProject((GLdouble) transx, (GLdouble) transy,(GLdouble) realy, mvmatrix, projmatrix, viewport, &wx, &wy, &wz);
Can anyone help me out?