PDA

View Full Version : wobble problem



sguTiger
06-05-2009, 11:58 AM
I have a MFC program using wgl. I want to change the eye position by moving the mouse, and then I plot the eye position as a point but it is wobbling.
OnMoveMove() like this:
void CGLWndL::OnMouseMove(UINT nFlags, CPoint point){
static CPoint dP,prePoint;
dP=point-prePoint;
if(dP.x>0)eyex+=0.01;
else if(dP.x<0) eyex-=0.01;
if(dP.y<0)eyey+=0.01;
else if(dP.y>0) eyey-=0.01;
if(nFlags==MK_CONTROL){
centerx=eyex;centery=eyey;
}
prePoint=point;
Invalidate();
}
The OnPaint() will call the render like this:
void render(){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyex,eyey,eyez,centerx,centery,centerz,0 ,1,0);
glPointSize(5);
glBegin(GL_POINTS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(centerx,centery,centerz);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(eyex,eyey,eyez);
glEnd();
}
Both points should locate in the center of the screen. But
I find that the blue point(eye point) is wobbling(sometimes it is not in the center). But the red point(center point) is stable. What causes this problem? thank you.

marek-knows.com
06-07-2009, 06:44 AM
Does the blue point wobble in one direction (horizontal only or vertical only)?

One thing that comes to mind is this. Are you transforming the mouse from the screen space to the window space? You may be off by a few pixels if you don't.