public void Form1_MouseWheel(object sender, MouseEventArgs e) { if (!IsMouseEventNeeded(e.X, e.Y)) { return; } if (helperDevice == null) { return; } using (Teigha.GraphicsSystem.View pView = helperDevice.ActiveView) { // camera position in world coordinates Point3d pos = pView.Position; // TransformBy() returns a transformed copy pos = pos.TransformBy(pView.WorldToDeviceMatrix); int vx = (int)pos.X; int vy = (int)pos.Y; vx = e.X - vx; vy = e.Y - vy; // we move point of view to the mouse location, to create an illusion of scrolling in/out there dolly(pView, -vx, -vy); // note that we essentially ignore delta value (sign is enough for illustrative purposes) pView.Zoom(e.Delta > 0 ? 1.0 / 0.9 : 0.9); dolly(pView, vx, vy); // Invalidate(); } }
public static void ZoomMap(Teigha.GraphicsSystem.View pView, Point2d centerPoint, double zoomFactor) { // camera position in world coordinates Point3d pos = pView.Position; // TransformBy() returns a transformed copy pos = pos.TransformBy(pView.WorldToDeviceMatrix); double vx = (int)pos.X; double vy = (int)pos.Y; vx = centerPoint.X - vx; vy = centerPoint.Y - vy; // we move point of view to the mouse location, to create an illusion of scrolling in/out there Transform(pView, -vx, -vy); // note that we essentially ignore delta value (sign is enough for illustrative purposes) pView.Zoom(zoomFactor); Transform(pView, vx, vy); }
private void ZoomWindow(Point3d pt1, Point3d pt2) { using (Teigha.GraphicsSystem.View pView = helperDevice.ActiveView) { using (AbstractViewPE pVpPE = new AbstractViewPE(pView)) { pt1 = pt1.TransformBy(pVpPE.WorldToEye); pt2 = pt2.TransformBy(pVpPE.WorldToEye); Vector3d eyeVec = pt2 - pt1; if (((eyeVec.X < -1E-10) || (eyeVec.X > 1E-10)) && ((eyeVec.Y < -1E-10) || (eyeVec.Y > 1E-10))) { Point3d newPos = pt1 + eyeVec / 2.0; pView.Dolly(newPos.GetAsVector()); double wf = pView.FieldWidth / Math.Abs(eyeVec.X); double hf = pView.FieldHeight / Math.Abs(eyeVec.Y); pView.Zoom(wf < hf ? wf : hf); Invalidate(); } } } }