Menu

Zoom to mouse position

Help
Mostafa
2018-02-09
2018-02-12
  • Mostafa

    Mostafa - 2018-02-09

    Hi,
    How can we zoom on scene to the mouse position by mousewheel event?

     
  • Jerome.D (BeanzMaster)

    Convert you mouse 2D screen position to 3D and assign it to camera taget positon or move the camera according to the 3D position and in the plane you are (xy, yz, zx)

     

    Last edit: Jerome.D (BeanzMaster) 2018-02-09
  • Mostafa

    Mostafa - 2018-02-09

    Hi Jerome,
    Thanks for your answer,
    I tried to do this conversion using the following code but not work truly:

    procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
    WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    begin

    GLDummyCube1.Position.AsAffineVector:=GLSceneViewer1.Buffer.ScreenToWorld(MousePos.X , MousePos.Y);

    // Note that 1 wheel-step induces a WheelDelta of 120,
    // this code adjusts the distance to target with a 10% per wheel-step ratio
    GLCamera1.AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));

    end;

     
  • shine world

    shine world - 2018-02-12

    Perhaps camera e camera target have to be moved in accordance

     

    Last edit: shine world 2018-02-12
  • Jerome.D (BeanzMaster)

    Yes exactly Silverio. But i'm not sure i' need make some verification because don't remember if by using 'Position.AsAffineVector' position notify the changes
    You can also try PixelRayToWorld(x,y):TAffineVector instead of screenToWorld

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.