Hello,
I am working on development of a graphical application where in one can draw lines, circles, points, load images, scale them and rotate, zooom in and out…
Well, I’m new to this world, but by hook or crook i am able to draw lines, polygons and load image. I’m also able to Zoom upto some extent. I am using wxWidgets for the GUI implementation Using C++.
Here’s my initialization of code for graphics.
int w,h;
GetClientSize(&w,&h); // function which returns the canvas’s height and width
glViewport( 0, 0, (GLint)w, (GLint)h);
if(h==0) h=1;
left=0;
right=(double)w;
top=(double)h;
bottom=0;
near=0;
far=1;
double aspect_ratio = (double)w/(double)h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if ( w > h)
glOrtho( leftaspect_ratio, rightaspect_ratio, bottom, top, near, far);
else
glOrtho( left, right, bottomaspect_ratio, topaspect_ratio, near, far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Then later i catch the mouse scrolling event and write the following code:
if( event.GetWheelRotation() < 0 )
{
left *= 0.75f;
right *= 0.75f;
bottom *= 0.75f;
top *= 0.75f;
near *= 0.75f;
far *= 0.75f;
}
else
{
left *= 1.33f;
right *= 1.33f;
bottom *= 1.33f;
top *= 1.33f;
near *= 1.33f;
far *= 1.33f;
}
int cw,ch;
GetClientSize(&w, &h);
double aspect_ratio = (double)w/(double)h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if ( w > h)
glOrtho( leftaspect_ratio, rightaspect_ratio, bottom, top, near, far);
else
glOrtho( left, right, bottomaspect_ratio, topaspect_ratio, near, far);
glMatrixMode(GL_MODELVIEW);
this->Refresh(false);
this event catching code is written for mouse scroll of canvas. It works absolutely fine… But it zooms with reference to the origin only… how do i do it with reference to the point where mouse is pointing to.??
Secondly, when i load a high resolution image, it takes lot of time to zoom in / out… in other applications it zooms very fast… if i load low resolution image then it works file… what can be done to improve this drawback…?? is there any way to reduce the resolution of the image before loading.??
Thanks in advance