View Full Version : how to change mouse position ,please help

11-28-2005, 08:14 PM
Now ,I meet with a problem about mouse position, the problem is as follows:
First ,I draw a plane in the scene, now I want to press mouse button down on the plane to draw a point at the right position on this plane, I think the points on the radial which is from the camera to the mouse position should be drawn at the same pixel on the screen .here is my main program:
gluPerspective(45.0, (GLfloat)cx/(GLfloat)cy, 8.0f,40.0); //projection matrix
gluLookAt(0.0,15.0,15.0,0.0,0.0,0.0,0.0,1.0,0.0); //view transformation
// glRotatef(-40.0, 1.0, 0.0, 0.0);

glGetDoublev(GL_MODELVIEW_MATRIX, dmatModelview);
glGetDoublev(GL_PROJECTION_MATRIX, dmatProjection);
glGetIntegerv(GL_VIEWPORT, viewport);
y = viewport[3] - point1.y;
glReadPixels(point1.x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fWindowZ);
gluUnProject((GLdouble) point1.x, (GLdouble) y, (GLdouble) fWindowZ,dmatModelview, dmatProjection, viewport,&dWorldX, &dWorldY, &dWorldZ)
first ,I comment the glRotate() command,
then I define a line which pass (0.0,0.0,0.0) and (dWorldX,dWorldY-15.0,dWorldZ-15.0);
a plane y=-15.01,and solve the equations ,and I get the point of intersectin(x,y,z);
then make (x,y+15.0,z+15.0) as the mouse button down position ,and I can draw a point on the plane at the button down position. but when I add the glRotate ,make the vector(0,15.0,15.0)as
1 0 0 0 0
0 cos40 -sin40 0 15.0
0 sin40 cos40 0 * 15.0
0 0 0 1 1
and similarly generate interpoint as above .But I canít draw a point at the right position. i am so confused ,would you please help me ?thank you very much!

11-28-2005, 08:22 PM
sorry,the new vector didn't write correctly,it is the result of the multiplication of a matrix [[1,0,0,0],[0,cos40,-sin40,0],[0,sin40,cos40,0],[0,0,0,1]]which represents the inverse rotate and [0,15.0,15.0,1].thank you very much!

11-28-2005, 09:10 PM
assuming the plane is defined in world space, i'd create a vector from the difference in un-projections (given z=1 and z=0), then i'd use elementary methods to intersect the line segment implicit in this vector with the plane.

i'd consider posting such question in the math or beginner's forum, henceforth.

happy holidays,

11-28-2005, 09:42 PM
i am sorry,
i will try,thank you so much! :)