i am having trouble with an aspect of my code
i need to reposition my clipping rectangle so that where i click my mouse that becomes the new center for my clipping rectangle
it is a 1000 x 1000 window and 100 x 100 clip here is my code see if you can see what is wrong
cw-clipwidth
ww-windowwidth
void myMouse( int btn, int st, int mousex, int mousey)
{
a=mousex;
b=mousey;
mx=(cw/ww)*mousex + a - (cw/2);
my=(-ch/wh)*mousey - b + (ch/2);
if ( btn==GLUT_LEFT_BUTTON && st == GLUT_DOWN )
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(mx-cw/2,mx+cw/2,my-ch/2,my+ch/2); //reset center of clip
glutPostRedisplay();
}
if ( btn==GLUT_RIGHT_BUTTON && st == GLUT_DOWN )
exit(1);
}
What is the problem you are having?
Do you call ortho2d any place else in the code?
Originally posted by weedus:
[b]i am having trouble with an aspect of my code
i need to reposition my clipping rectangle so that where i click my mouse that becomes the new center for my clipping rectangle
it is a 1000 x 1000 window and 100 x 100 clip here is my code see if you can see what is wrong
cw-clipwidth
ww-windowwidth
void myMouse( int btn, int st, int mousex, int mousey)
{
a=mousex;
b=mousey;
mx=(cw/ww)*mousex + a - (cw/2);
my=(-ch/wh)*mousey - b + (ch/2);
if ( btn==GLUT_LEFT_BUTTON && st == GLUT_DOWN )
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(mx-cw/2,mx+cw/2,my-ch/2,my+ch/2); //reset center of clip
glutPostRedisplay();
}
if ( btn==GLUT_RIGHT_BUTTON && st == GLUT_DOWN )
exit(1);
}