Xenko基础API笔记2-手势

交互:

Drag Gesture

Type : Continuous

Configuration class: GestureConfigDrag

Event class: GestureEventDrag

Action description:The user touched the screen, performed a translation and withdraw its finger(s).

Comments: The number of finger on the screen cannot vary during the gesture. The programmer can modify the MinimumDragDistance field if he need the gesture to be triggered for smaller drags.

配置类:GestureConfigDrag
事件类:GestureEventDrag
动作描述:用户触摸屏幕时,进行了翻译和撤回手指(s)。
评论:手指在屏幕上的数量不能改变姿态。程序员可以修改MinimumDragDistance字段如果他需要被触发的动作小拖。

Flick Gesture

Type : Discrete

Configuration class: GestureConfigFlick

Event class: GestureEventFlick

Action description:The user touched the screen, performed a quick straight translation and withdraw its finger(s).

Comments: The number of finger on the screen cannot vary during the gesture. The programmer can modify the MinimumFlickLength field to constrain the flick to have a minimum length.

类型:离散
配置类:GestureConfigFlick
事件类:GestureEventFlick
动作描述:用户触摸屏幕时,执行一个快速直接翻译和撤回手指(s)。
评论:手指在屏幕上的数量不能改变姿态。程序员可以修改MinimumFlickLength字段来限制有一个最小长度的电影。

Long Press Gesture

Type : Discrete

Configuration class: GestureConfigLongPress

Event class: GestureEventLongPress

Action description:The user touched the screen, and maintained the pressure without moving during a given time (default about 1 second).

Comments: The number of finger on the screen cannot vary during the gesture. The programmer can modify the RequiredPressTime field to change the press time.

长按手势
类型:离散
配置类:GestureConfigLongPress
事件类:GestureEventLongPress
动作描述:用户触摸屏幕,保持不动的压力在一个给定的时间(默认约1秒)。
评论:手指在屏幕上的数量不能改变姿态。程序员可以修改RequiredPressTime字段改变新闻时间。

Composite Gesture

Type : Continuous

Configuration class: GestureConfigComposite

Event class: GestureEventComposite

Action description:The user touched the screen with two fingers, and moved them independently.

Comments: This gesture is a composition the 3 basic transformations translation, scale, rotation. It requires exactly 2 fingers on the screen. The gesture is triggered when the system detect a small translation, scale or rotation. To perform a translation, the user translates uniformly the two fingers together. To perform a scale, the user moves closer or further the two fingers from each other. To perform a rotation, the user turns the two fingers around there their middle.

复合动作
类型:连续
配置类:GestureConfigComposite
事件类:GestureEventComposite
动作描述:用户用两个手指触摸屏幕,并独立地移动。
评论:这个手势是三个基本成分转换翻译,规模、旋转。它需要2根手指在屏幕上。触发手势当系统检测到一个小翻译,规模或旋转。进行翻译时,用户将统一在一起的两根手指。执行规模、用户移动接近或进一步的两根手指。执行一个旋转,用户就那里的两个手指在他们的中间。

Tap Gesture

Type : Discrete

Configuration class: GestureConfigTap

Event class: GestureEventTap

Action description:The user touched the screen, and removed its fingers quickly without moving.

Comments: The number of finger on the screen cannot vary during the gesture.The programmer can modify the RequiredNumberOfTaps field to decide the number tap that he wants to detect. Note that to be able to distinguish single taps from multi-tap taps, the system has to wait a given time and thus introduces latency in tap events. If the programmer is interested only in single taps, he can put the MaximumTimeBetweenTaps field to 0 to avoid this latency.

点击手势
类型:离散
配置类:GestureConfigTap
事件类:GestureEventTap
动作描述:用户触摸屏幕,并删除其手指快速不动。
评论:手指在屏幕上的数量不能改变姿态。程序员可以修改RequiredNumberOfTaps字段决定利用他想检测数量。注意,能够区分单从转接插座水龙头水龙头,系统必须等待一个给定的时间,因此介绍了延时水龙头事件。如果程序员只对单一的水龙头感兴趣,他可以把MaximumTimeBetweenTaps字段为0来避免这种延迟。

Usage

By default, the input system does not recognize any Gesture. To start (resp. stop) some gesture recognition the programmer has to add (resp. remove) gesture configurations to the @‘SiliconStudio.Xenko.Input.ActivatedGestures‘ collection. Once a gesture is activated for recognition, its associated configuration is frozen and the user cannot modify it any more. If the user wants to stop all gesture recognition he can directly clear the collection.

Code: Activate/Desactivate Gestures Recognitions

var singleTapConfig = new GestureConfigTap(); // create the configuration of the gesture we want to recognize
Input.ActivatedGestures.Add(singleTapConfig); // start the tap gesture recognition

var doubleTapConfig = new GestureConfigTap(2, 1); // create the configuration of the gesture we want to recognize
Input.ActivatedGestures.Add(doubleTapConfig ); // start the double tap gesture recognition

 // ...

Input.ActivatedGestures.Remove(singleTapConfig); // stop the tap gesture recognition

// ...
Input.ActivatedGestures.Clear(); // stop all remaining gesture recognitions

Each configuration class has a parameterless constructor corresponding to the default gesture configuration. Special constructors have also been implemented for parameters that the programmer may modify frequently. Other parameters correspond to fields that are not recommended to modify to keep a good coherency of the system. Those fields can be modified by accessing the corresponding properties.

Code: Set gesture configuration

var singleTapConfig = new GestureConfigTap(); // default config for the gesture.
var doubleTapConfig = new GestureConfigTap(2, 2); // personalize the gesture config by using the dedicated constructor
var noLatencyTap = new GestureConfigTap() { MaximumTimeBetweenTaps= TimeSpan.Zero }; // personalize the gesture config by directly accessing the desired property (user must be aware of was he does, this may break the input system coherency in some cases)

The programmer can access the recognized gestures via the @‘SiliconStudio.Xenko.Input.IInputManager.GestureEvents‘ collections. The collection is automatically cleared every frame.

Code: Access Gesture events

var currentFrameGestureEvents = Input.GestureEvents;

One can use the Type field to identity the gesture type and then cast it to the appropriate event type to have extra info about the event.

Code: Identifying the gesture type

foreach( var gestureEvent in Input.GestureEvents)
{
       if (gestureEvent.Type != GestureType.Tap) // determine if the event is from a tap gesture
        continue;

    GestureEventTap  tapEvent = (GestureEventTap) gestureEvent; // cast the event the specific tap event class
    log.Info("Tap position: {0}.", tapEvent.TapPosition); // access tap event specific field
}

One can know the gesture state by analyzing the @‘ SiliconStudio.Xenko.Input.GestureEvent.State‘ field.

Code: Identifying the event state

switch(compositeGestureEvent.State)
{
case GestureState.Began:
    image.ComputePreview();
    break;
case GestureState.Changed:
    image.TransformPreview(compositeGestureEvent.TotalScale, compositionGestureEvent.TotalRotation);
    break;
case GestureState.Ended:
    image.TransformRealImage(compositeGestureEvent.TotalScale, compositionGestureEvent.TotalRotation);
    break;
default:
    break;
}
时间: 2024-11-01 21:36:05

Xenko基础API笔记2-手势的相关文章

Xenko基础API笔记3- Pointers指针设备屏幕上点对应的手指触摸。

样本这里是一个简单的示例程序,跟踪目前在屏幕上的指针和打印他们的位置.访问输入字段,类继承自@ SiliconStudio.Xenko.脚本的类. public override async Task Execute() { var pointerPositions = new Dictionary<int, Vector2>(); while (true) { await Scheduler.NextFrame(); foreach (var pointerEvent in Input.Po

Xenko基础API笔记2-Enum Keys按键

Name   Description A The 'a' key. Add The 'add' key. Apps The 'apps' key. Attn The 'attn' key. B The 'b' key. Back The 'back' key. BrowserBack The 'browserback' key. BrowserFavorites The 'browserfavorites' key. BrowserForward The 'browserforward' key

java基础巩固笔记(6)-注解

java基础巩固笔记(6)-注解 java基础巩固笔记6-注解 注解的应用结构图 元注解 自定义注解 示例代码 参考资料 注解(Annotation),也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举是在同一个层次.它可以声明在包.类.字段.方法.局部变量.方法参数等的前面,用来对这些元素进行说明,注释. API Package java.lang.annotation 注解的应用结构图 调用/结构关系:A<–B<–C A,B,C解释如下: A:注解类

Android 网络编程 API笔记 - java.net 包 权限 地址 套接字 相关类 简介

Android 网络编程相关的包 : 9 包, 20 接口, 103 类, 6 枚举, 14异常; -- Java包 : java.net 包 (6接口, 34类, 2枚举, 12异常); -- Android包 : android.net 包 (1接口, 19类, 3枚举, 1异常), android.net.http 包 (6类), android.net.nsd 包 (3接口, 2类), android.net.rtp (4类), android.net.sip 包 (1接口, 9类, 1

jQuery官方基础教程笔记(转载)

本文转载于阮一峰的博文,内容基础,结构清晰,是jquery入门不可多得的资料,非常好,赞一个. 阮一峰:jQuery官方基础教程笔记 jQuery是目前使用最广泛的javascript函数库. 据统计,全世界排名前100万的网站,有46%使用jQuery,远远超过其他库.微软公司甚至把jQuery作为他们的官方库. 对于网页开发者来说,学会jQuery是必要的.因为它让你了解业界最通用的技术,为将来学习更高级的库打下基础,并且确实可以很轻松地做出许多复杂的效果. 虽然jQuery上手简单,比其他

QT基础学习笔记

Qt简介:1991, 挪威奇趣科技Trolltech开发的跨平台c++图形用户界面(GUI)应用程序开发.2008,被诺基亚收购2012,转让给芬兰的Digia公司. 商业版:专业版,企业版: // 开源版(GNU) 优势:1.跨平台 2.面向对象 3.丰富API 类库  4.可视化编程 5,时间驱动机制 JAVA--compile once, run anywhere    一次编译,到处运行Qt-- wrire once ,comile anywhere     一次编写,到处编译 桌面操作

linux系统驱动基础学习笔记

Linux驱动: 角色:应用程序 API      操作系统      驱动       实际硬件 功能:1.对设备进行初始化和释放2.把数据从内核传送到硬件和从硬件读取数据3.检测和处理设备出现的错误 Linux驱动程序类型:字符设备:由文件系统管理    (通过设备文件访问)块设备:由文件系统管理网络设备:由协议栈管理      (通过socket访问) 查看系统设备文件ls -l /devcat /proc/devicescat /sys/power/state 属性:文件类型   主设备

linux应用编程基础学习笔记

********************************************************            --文件I/O-- 文件:文本文件:存储量大,速度慢,便于字符操作二进制文件:存储量小,速度快,便于存放中间结果 普通文件:设备文件: ---C标准函数---:Buffered I/O,高级文件系统,在用户空间开辟缓冲区,流操作(stream)#include<stdio.h> typedef struct{ int _fd;      //文件号 int _

Android 网络编程 API笔记 - java.net 包相关 接口 api

Android 网络编程相关的包 : 9 包, 20 接口, 103 类, 6 枚举, 14异常; -- Java包 : java.net 包 (6接口, 34类, 2枚举, 12异常); -- Android包 : android.net 包 (1接口, 19类, 3枚举, 1异常), android.net.http 包 (6类), android.net.nsd 包 (3接口, 2类), android.net.rtp (4类), android.net.sip 包 (1接口, 9类, 1