Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
0.8.3:interaction [2022/04/20 15:40] – [In Viewport] admin0.8.3:interaction [2022/04/20 15:43] – [Classic Camera Mouse Movement] admin
Line 86: Line 86:
 Another solution is to include rotation behaviour in each object related mouse-move event, or to use TGorillaInputController with global mouse hooks ([[inputpolling|Input Polling]]). Another solution is to include rotation behaviour in each object related mouse-move event, or to use TGorillaInputController with global mouse hooks ([[inputpolling|Input Polling]]).
  
-=== Classic Camera Mouse Movement  ===+==== Classic Camera Mouse Movement  ====
  
 Very often users want to implement  simple camera movement controlled by mouse. Very often users want to implement  simple camera movement controlled by mouse.
Line 102: Line 102:
  
 <file pascal> <file pascal>
 +var FMove : Boolean;
 +    FLastPos : TPointF;
 +    FSpeed : Single = 0.1;
 +
 procedure TGameWin.GorillaViewport1MouseDown(Sender: TObject; procedure TGameWin.GorillaViewport1MouseDown(Sender: TObject;
   Button: TMouseButton; Shift: TShiftState; X, Y: Single);   Button: TMouseButton; Shift: TShiftState; X, Y: Single);
Line 112: Line 116:
   Shift: TShiftState; X, Y: Single);   Shift: TShiftState; X, Y: Single);
 var LDiff : TPointF; var LDiff : TPointF;
-    LLeft, 
     LDir  : TPoint3D;     LDir  : TPoint3D;
 begin begin
Line 130: Line 133:
   else   else
   begin   begin
-    // move camera in camera direction 
     LDir := TPoint3D.Zero;     LDir := TPoint3D.Zero;
  
-    LDir := LDir + TPoint3D(GorillaCamera1.AbsoluteLeft) * (LDiff.X * 0.1); +    /// at first we apply the left-side direction  
-    LDir := LDir + TPoint3D(GorillaCamera1.AbsoluteDirection) * (LDiff.Y * 0.1);+    LDir := LDir + TPoint3D(GorillaCamera1.AbsoluteLeft) * (LDiff.X * FSpeed); 
 +    /// then we apply the forward direction 
 +    LDir := LDir + TPoint3D(GorillaCamera1.AbsoluteDirection) * (LDiff.Y * FSpeed);
  
 +    /// we move the parent dummy, not the camera itself!
 +    /// simply by adding our direction vector to the current dummy position
     Dummy1.Position.Point := Dummy1.Position.Point + LDir;     Dummy1.Position.Point := Dummy1.Position.Point + LDir;
   end;   end;
  
-  LDir := TPoint3D(GorillaCamera1.AbsoluteDirection); 
-  Self.Caption := Format('Direction = (%n, %n, %n)', [LDir.X, LDir.Y, LDir.Z]); 
   FLastPos := PointF(X, Y);   FLastPos := PointF(X, Y);
 end; end;