Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
interaction [2020/05/26 12:41] – [Interaction] admin | interaction [2020/05/26 12:53] – [Gesture Interaction] admin | ||
---|---|---|---|
Line 210: | Line 210: | ||
===== Gesture Interaction ===== | ===== Gesture Interaction ===== | ||
+ | Gesture handling is supported for Gorilla3D viewport. To allow gesture management you will need a TGestureManager component on your form and you have to link it to the TGorillaViewport component. | ||
+ | |||
+ | In the example below it is described, how to rotate and zoom a model. Therefor we use the interactive gestures: ZOOM and PAN. | ||
+ | In the // | ||
+ | |||
+ | <file pascal> | ||
+ | type | ||
+ | TForm1 = class(TForm) | ||
+ | GorillaViewport1: | ||
+ | GestureManager1: | ||
+ | GorillaModel1: | ||
+ | | ||
+ | procedure GorillaViewport1Gesture(Sender: | ||
+ | const EventInfo: TGestureEventInfo; | ||
+ | | ||
+ | protected | ||
+ | FLastPos : TPointF; | ||
+ | | ||
+ | [...] | ||
+ | end; | ||
+ | | ||
+ | procedure TForm1.FormCreate(Sender : TObject); | ||
+ | begin | ||
+ | GorillaViewport1.Touch.GestureManager := GestureManager1; | ||
+ | GorillaViewport1.Touch.InteractiveGestures := [Zoom, Pan]; | ||
+ | GorillaViewport1.OnGesture := GorillaViewport1Gesture; | ||
+ | [...] | ||
+ | end; | ||
+ | |||
+ | procedure TForm1.GorillaViewport1Gesture(Sender: | ||
+ | const EventInfo: TGestureEventInfo; | ||
+ | |||
+ | procedure DoZoom(); | ||
+ | var LScale : Single; | ||
+ | begin | ||
+ | if not (TInteractiveGestureFlag.gfBegin in EventInfo.Flags) | ||
+ | and not (TInteractiveGestureFlag.gfEnd in EventInfo.Flags) then | ||
+ | begin | ||
+ | LScale := EventInfo.Distance / 100; | ||
+ | GorillaModel1.Scale.Point := Point3D(LScale, | ||
+ | end; | ||
+ | end; | ||
+ | |||
+ | procedure DoRotate(); | ||
+ | var LDist : Single; | ||
+ | LDiff, | ||
+ | LNew, | ||
+ | LPos : TPointF; | ||
+ | begin | ||
+ | LNew := EventInfo.Location; | ||
+ | |||
+ | if not Assigned(GorillaModel1) then | ||
+ | begin | ||
+ | FLastPos := LNew; | ||
+ | Exit; | ||
+ | end; | ||
+ | |||
+ | if not (TInteractiveGestureFlag.gfBegin in EventInfo.Flags) | ||
+ | and not (TInteractiveGestureFlag.gfEnd in EventInfo.Flags) then | ||
+ | begin | ||
+ | LPos := EventInfo.Location; | ||
+ | LDiff := FLastPos - LPos; | ||
+ | |||
+ | LDist := LDiff.X / 5; | ||
+ | |||
+ | GorillaModel1.RotationAngle.Y := GorillaModel1.RotationAngle.Y + LDist; | ||
+ | end; | ||
+ | |||
+ | FLastPos := LNew; | ||
+ | end; | ||
+ | |||
+ | begin | ||
+ | // just a dirty and quick solution for gesture handling | ||
+ | case EventInfo.GestureID of | ||
+ | igiZoom : | ||
+ | begin | ||
+ | // zoom | ||
+ | DoZoom(); | ||
+ | Handled := true; | ||
+ | end; | ||
+ | |||
+ | igiPan : | ||
+ | begin | ||
+ | // rotate model | ||
+ | DoRotate(); | ||
+ | Handled := true; | ||
+ | end; | ||
+ | |||
+ | else | ||
+ | begin | ||
+ | Handled := false; | ||
+ | end; | ||
+ | end; | ||
+ | end; | ||
+ | </ | ||
===== GamePad Interaction ===== | ===== GamePad Interaction ===== | ||