Menu

Panning a scene

Help
2016-12-16
2019-01-28
  • shine world

    shine world - 2016-12-16

    Hi to all I'm trying to get a panning of a scene (left/right/up/bottom) using mouse movements (with righ button pressed).

    I'm using Delphi 2006 so related GLScene is version RC 1.0.0.0714.

    Actually I can well rotate my scene using this code

      // if left mouse changes camera angle (we're moving around the parent and target dummycube)
      if ssLeft in Shift then
        Camera.MoveAroundTarget(DY, DX);
    

    The camera use csPerspective mode.

     

    Last edit: shine world 2016-12-16
    • lnebel

      lnebel - 2016-12-16

      Hi, do something like this:

      if IsKeyDown(VK_UP) then DummyCube.Translate(-DummyCube.Position.X, 0,
      -DummyCube.Position.Z) else

      if IsKeyDown(VK_DOWN) then DummyCube.Translate( DummyCube.Position.X, 0,
      DummyCube.Position.Z) else

      if IsKeyDown(VK_LEFT) then DummyCube.Translate(-DummyCube.Position.Z, 0,
      DummyCube.Position.X) else

      if IsKeyDown(VK_RIGHT) then DummyCube.Translate( DummyCube.Position.Z, 0,
      -DummyCube.Position.X);

      \Lars

      From: Silverio Diquigiovanni [mailto:shineworld@users.sf.net]
      Sent: 16. december 2016 10:03
      To: [glscene:discussion] 93606@discussion.glscene.p.re.sf.net
      Subject: [glscene:discussion] Panning a scene

      Hi to all I'm trying to get a panning of a scene (left/right/up/bottom)
      using mouse movements (with righ button pressed).

      I'm using Delphi 2006 so related GLScene is version RC 1.0.0.0714.

      Actually I can well rotate my scene using this code

      // if left mouse changes camera angle (we're moving around the parent and
      target dummycube)
      if ssLeft in Shift then
      Camera.MoveAroundTarget(DY, DX);

      The camera sue csPerspective mode.

      http://pasteboard.co/aqR7rv5fe.png


      Panning a scene
      https://sourceforge.net/p/glscene/discussion/93606/thread/6dbf2dea/?limit=2 5#7817


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/glscene/discussion/93606/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • shine world

    shine world - 2016-12-16

    Unfortunately that don't seem to work for me.

    The solution seem to move either camera and camera target (the dummybox) left or right how in following code BUT, but, I'm in perspective mode so all 3 axes (X/Y/Z) sould be changed depending by plane inclination...

    I don't know how to calculate this ....

    Mouse Movement -> DeltaX/Y -> some calc -> Camera/Camera.Target.PositionX/Y/Z = Calculated values...

     

    Last edit: shine world 2017-08-01
  • shine world

    shine world - 2016-12-22

    I've solved and now I can rotate/zoom/pan a scene with mouse :)

     

    Last edit: shine world 2017-08-01
  • Mostafa

    Mostafa - 2018-01-28

    Hi Silverio,
    Can you tell me how you resolved the Panning problem?

     
  • shine world

    shine world - 2018-01-30

    Sure Mostafa:

    procedure TGLSceneFrame.GLSceneViewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      // stores mouse coordinates when a button went down
      FMDX := X;
      FMDY := Y;
    end;
    
    procedure TGLSceneFrame.GLSceneViewerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    var
      DX: Integer;
      DY: Integer;
      VT: TAffineVector;
      VTA: TAffineVector;
      VTS: TAffineVector;
      VTW: TAffineVector;
    begin
      // calculates delta since last move or last mousedown
      DX := FMDX - X;
      DY := FMDY - Y;
      FMDX := X;
      FMDY := Y;
    
      // if left mouse changes camera angle (we're moving around the parent and target dummycube)
      if ssLeft in Shift then
        Camera.MoveAroundTarget(DY, DX);
    
      // if pressed right mouse button moves camera and camera target to get panning in H&V
      if (ssRight in Shift)
      begin
        VT := CameraTarget.Position.AsAffineVector;
        VTA := GLScene.Objects.LocalToAbsolute(VT);
        VTS := GLSceneViewer.Buffer.WorldToScreen(VTA);
        VTS[0] := VTS[0] + DX;
        VTS[1] := VTS[1] - DY;
        VTW := GLSceneViewer.Buffer.ScreenToWorld(VTS);
        CameraTarget.Position.AsAffineVector := VTW;
        Camera.Position.AsAffineVector := VectorAdd(Camera.Position.AsAffineVector, VectorSubtract(VTW, VT));
      end;
    end;
    

    I'm using an old library so VTS[0] should be changed in new notation VTS.x or something similar
    I was not able to get a demo project so I've attached the used code.
    Objects name are close to classes name so you shouldn't have problems to guess what are.

    The idea is to move either camera and cameratarget of mouse DX/DY.

     
  • Mostafa

    Mostafa - 2018-01-30

    Thank you Silverio,

     
  • tambok

    tambok - 2019-01-21

    Hi every one,
    A bit late,
    my question is how can panning be used in csOrthogonal Camera mode?

    i would like to be able to use panning as in this picture.

    Thanks

     
  • shine world

    shine world - 2019-01-21

    To have the panning of scene a right way is to move the dummy block linked with camera and related camera in space. Moving the couple is very simple with code attached in my previous post.

    I'm amazed about your snapshot.
    What are you doing ? Seem a CAD for mech.

    I'm very interested on how you had obtained the axis reference XYZ in botton left place !

    I'm working on a CNC project: you can see my progress on https://www.youtube.com/user/thoth2487/

     
    • tambok

      tambok - 2019-01-23

      Hi SW,
      do you mean this codes?

      // if pressed right mouse button moves camera and camera target to get panning in H&V
      if (ssRight in Shift)
      begin
      VT := CameraTarget.Position.AsAffineVector;
      VTA := GLScene.Objects.LocalToAbsolute(VT);
      VTS := GLSceneViewer.Buffer.WorldToScreen(VTA);
      VTS[0] := VTS[0] + DX;
      VTS[1] := VTS[1] - DY;
      VTW := GLSceneViewer.Buffer.ScreenToWorld(VTS);
      CameraTarget.Position.AsAffineVector := VTW;
      Camera.Position.AsAffineVector := VectorAdd(Camera.Position.AsAffineVector, VectorSubtract(VTW, VT));
      end;

      the snapshot is not mine. It's just to take clear my question about panning in csOrthogonal.

      i have seen your project. Very, very interesting about your project.

      tbk

       
  • tambok

    tambok - 2019-01-28

    Hi SW,
    thank you for the info.
    while i am waiting your news, i played with the codes. Now the codes worked for viewers.
    i just have problem with one viewer, where only X and Y axes is used.
    i dont know where i can fix it.
    Any help for me?

    tbk

     

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.