I'm writing a CAD drawing application and I've got most of the drawing system figured out apart from a bug in th zoom in/out code. I think is a bug in my maths or a floating point error.
I'm using the mousewheel to alter the zoom factor... Point mouse is the x,y coordinate of the mouse when the wheel was rolled. ClientSize is the size of the picture box tha i'm drawingon an that captures the mouse events.
This returned point is supposed to be the mouse coordinate recalculated into WORLD coordinates.PHP Code:public PointF MouseToWorld( Point mouse, Size clientSize )
{
PointF fp = _viewSettings.FocalPoint;
float zf = _viewSettings.ZoomFactor;
float w = (float)(clientSize.Width);
float h = (float)(clientSize.Height);
float propX = (float)mouse.X / (w - 1f);
float propY = (float)mouse.Y / (h - 1f);
propX -= 0.5f;
propY -= 0.5f;
propX *= (w / zf);
propY *= (h / zf);
return new PointF( fp.X + propX, fp.Y + propY );
}
THE PROBLEM:
During debugging I put the mouse in the dead-centre of the screen and zoom in a couple of times. But the drawing slides off to the right the more I zoom in. If the zoom factor is 256x then the drawing will be 256 pixels to the right of where it should be.
I get the feeling that simply subtractinf the zoom factor from the x,y coordinates of th translation would be a dirty fix and I don't want to do that without some justification.
Has anyone else done anything like this before and had similar results?
*perplexed*




Reply With Quote