Original Post
Hello I'm having a problem with getting the correct cursor position is located when my camera zooms in the 2D scene.
I've spent days google searching and playing with the variables, but I can't get it too work right and zoom is going too be a very important feature in my 2D image program. I'm currently using OpenGL for the 2D. I'm wondering if it's the way I could have Ortho set up, but I'm not sure since I'm using two Ortho projections.
Example when I try too determine the mouse position with the zoom:
ViewPos is the camera position over the image, and RenderImageWidth and RenderImageHeight is the image being displayed in the center of the screen the user draws on. Lets say both those values are 512.
Here is how my 2D Ortho is set up:
Thanks for reading, I'll appreciate any feedback, thanks!
[Edited by - ajm113 on September 1, 2010 11:32:40 PM]
I've spent days google searching and playing with the variables, but I can't get it too work right and zoom is going too be a very important feature in my 2D image program. I'm currently using OpenGL for the 2D. I'm wondering if it's the way I could have Ortho set up, but I'm not sure since I'm using two Ortho projections.
Example when I try too determine the mouse position with the zoom:
int ImageHalfWidth = RenderImageWidth / 2; int ImageHalfHeight = RenderImageHeight / 2; int halfw = (windowWidth / 2) - ImageHalfWidth; int halfh = (windowHeight / 2) - ImageHalfHeight; Vector2D vec = Vector2D(PreviewZoom*(MouseCurPos.m_X-ViewPos.m_X-halfw), PreviewZoom*(MouseCurPos.m_Y-ViewPos.m_Y-halfh)); Vector2D vec2 = Vector2D(PreviewZoom*(MouseLastPos.m_X-ViewPos.m_X-halfw), PreviewZoom*(MouseLastPos.m_Y-ViewPos.m_Y-halfh));ViewPos is the camera position over the image, and RenderImageWidth and RenderImageHeight is the image being displayed in the center of the screen the user draws on. Lets say both those values are 512.
Here is how my 2D Ortho is set up:
Set2DDrawImage(windowWidth*PreviewZoom, windowHeight*PreviewZoom, RenderImageWidth, RenderImageHeight);//Draw workspace here! Layers, the image, etc..Set2DDraw(windowWidth, windowHeight, 0);//Normal 2D drawing of tool bars, buttons, etc with OpenGL.void Set2DDrawImage(int w, int h, int ImageWidth, int ImageHeight){// switch to projection mode glMatrixMode(GL_PROJECTION); // save previous matrix which contains the //settings for the perspective projection glPushMatrix(); // reset matrix glLoadIdentity(); // set a 2D orthographic projection gluOrtho2D(0, w, 0, h); // invert the y axis, down is positive glScalef(1, -1, 1); // mover the origin from the bottom left corner // to the upper left corner int ImageHalfWidth = ImageWidth / 2; int ImageHalfHeight = ImageHeight / 2; int halfw = (w / 2) - ImageHalfWidth; int halfh = (h / 2) + ImageHalfHeight; glTranslatef(halfw, -halfh, 0); glMatrixMode(GL_MODELVIEW);}void Set2DDraw(int w, int h, float zoom){// switch to projection mode glMatrixMode(GL_PROJECTION); // save previous matrix which contains the //settings for the perspective projection glPushMatrix(); // reset matrix glLoadIdentity(); // set a 2D orthographic projection gluOrtho2D(50.0*zoom, w, 50.0*zoom, h); // invert the y axis, down is positive glScalef(1, -1, 1); // mover the origin from the bottom left corner // to the upper left corner glTranslatef(0, -h, 0); glMatrixMode(GL_MODELVIEW);}Thanks for reading, I'll appreciate any feedback, thanks!
[Edited by - ajm113 on September 1, 2010 11:32:40 PM]