Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
0.8.3:interaction [2022/04/20 15:41] – [In Viewport] admin | 0.8.3:interaction [2022/04/20 15:45] (current) – [Classic Camera Mouse Movement] admin | ||
---|---|---|---|
Line 102: | Line 102: | ||
<file pascal> | <file pascal> | ||
+ | var FMove : Boolean; | ||
+ | FLastPos : TPointF; | ||
+ | FSpeed : Single = 0.1; | ||
+ | |||
procedure TGameWin.GorillaViewport1MouseDown(Sender: | procedure TGameWin.GorillaViewport1MouseDown(Sender: | ||
Button: TMouseButton; | Button: TMouseButton; | ||
begin | begin | ||
+ | /// allow camera movement | ||
FMove := true; | FMove := true; | ||
+ | /// store the current mouse position to detect the pixel movement | ||
FLastPos := PointF(X, Y); | FLastPos := PointF(X, Y); | ||
end; | end; | ||
Line 112: | Line 118: | ||
Shift: TShiftState; | Shift: TShiftState; | ||
var LDiff : TPointF; | var LDiff : TPointF; | ||
- | LLeft, | ||
LDir : TPoint3D; | LDir : TPoint3D; | ||
begin | begin | ||
+ | /// if mouse was not down - skip camera movement here | ||
if not FMove then | if not FMove then | ||
begin | begin | ||
Line 121: | Line 127: | ||
end; | end; | ||
+ | /// compute the offset to the last pixel position | ||
LDiff := PointF(X, Y) - FLastPos; | LDiff := PointF(X, Y) - FLastPos; | ||
if ssRight in Shift then | if ssRight in Shift then | ||
begin | begin | ||
- | // rotate camera | + | |
Dummy1.RotationAngle.Y := Dummy1.RotationAngle.Y + LDiff.X; | Dummy1.RotationAngle.Y := Dummy1.RotationAngle.Y + LDiff.X; | ||
end | end | ||
- | else | + | else if ssLeft in Shift then |
begin | begin | ||
- | // move camera in camera | + | |
LDir := TPoint3D.Zero; | LDir := TPoint3D.Zero; | ||
- | LDir := LDir + TPoint3D(GorillaCamera1.AbsoluteLeft) * (LDiff.X * 0.1); | + | |
- | LDir := LDir + TPoint3D(GorillaCamera1.AbsoluteDirection) * (LDiff.Y * 0.1); | + | |
+ | /// 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(' | ||
FLastPos := PointF(X, Y); | FLastPos := PointF(X, Y); | ||
end; | end; |