PDA

View Full Version : Moving objects in 3D



wrapper
11-24-2000, 10:32 AM
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[3] - (GLint)y - 1.)

gluProject(controlPoints[dividend][remainder][0],controlPoints[dividend][remainder][1],controlPoints[dividend][remainder][2],mvmatrix,projmatrix,viewport,&transx,&transy,&transz);
gluUnProject((GLdouble) transx, (GLdouble) transy,(GLdouble) realy, mvmatrix, projmatrix, viewport, &wx, &wy, &wz);

Can anyone help me out?

agusn
11-24-2000, 11:47 PM
you should use gltranslate(x,y,z) function instead of moving the object by manipulating projection matrix.

Gus