转自:http://aigo.iteye.com/blog/2272698

代码还是参考自Epic官方的塔防项目:StrategyGame

看了下C++的API,现成的API中貌似只支持单点触碰检测,用法如下:
注册:

// support touch devices
InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &ATD_MobilePlayerController::MoveToTouchLocation);
InputComponent->BindTouch(EInputEvent::IE_Repeat, this, &ATD_MobilePlayerController::MoveToTouchLocation);

触发回调:

void ATD_MobilePlayerController::MoveToTouchLocation(const ETouchIndex::Type FingerIndex, const FVector Location)
{
FVector2D ScreenSpaceLocation(Location); // Trace to see what is under the touch location
FHitResult HitResult;
GetHitResultAtScreenPosition(ScreenSpaceLocation, CurrentClickTraceChannel, true, HitResult);
if (HitResult.bBlockingHit)
{
// We hit something, move there
SetNewMoveDestination(HitResult.ImpactPoint);
}
}

如果要实现多点触碰检测,比如实现两个手指捏动来缩放屏幕,StrategyGame项目自己实现了一套算法来实现多点屏幕检测,具体做法如下:
StrategyPlayerController.h

1,先重写StrategyPlayerController的ProcessPlayerInput()和SetupInputComponent()函数

protected:
/** update input detection */
virtual void ProcessPlayerInput(const float DeltaTime, const bool bGamePaused) override;
virtual void SetupInputComponent() override;

在SetupInputComponent()函数中绑定事件(这个事件机制也是自己写的),其中BIND_1P_ACTION和BIND_2P_ACTION是自己定义的宏:

ProcessPlayerInput()来检测触碰点变化,这是一个连续执行的函数,大概逻辑是:每次执行时都会把当前的屏幕触碰信息和上次的触碰信息做对比,检测是单点触碰,还是按住不放,还是多点触碰或多点按住不放等等,具体逻辑在InputHandler->UpdateDetection(DeltaTime);中。

void AStrategyPlayerController::ProcessPlayerInput(const float DeltaTime, const bool bGamePaused)
{
if (!bGamePaused && PlayerInput && InputHandler && !bIgnoreInput)
{
InputHandler->UpdateDetection(DeltaTime);
} Super::ProcessPlayerInput(DeltaTime, bGamePaused); if (!bIgnoreInput )
{
const ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
AStrategySpectatorPawn* StrategyPawn = GetStrategySpectatorPawn();
if(( StrategyPawn != NULL ) && ( LocalPlayer != NULL ))
{
// Create the bounds for the minimap so we can add it as a 'no scroll' zone.
AStrategyHUD* const HUD = Cast<AStrategyHUD>(GetHUD());
AStrategyGameState const* const MyGameState = GetWorld()->GetGameState<AStrategyGameState>();
if( (MyGameState != NULL ) && ( MyGameState->MiniMapCamera.IsValid() == true ) )
{
if( LocalPlayer->ViewportClient != NULL )
{
const FIntPoint ViewportSize = LocalPlayer->ViewportClient->Viewport->GetSizeXY();
const uint32 ViewTop = FMath::TruncToInt(LocalPlayer->Origin.Y * ViewportSize.Y);
const uint32 ViewBottom = ViewTop + FMath::TruncToInt(LocalPlayer->Size.Y * ViewportSize.Y); FVector TopLeft( HUD->MiniMapMargin, ViewBottom - HUD->MiniMapMargin - MyGameState->MiniMapCamera->MiniMapHeight, );
FVector BottomRight( (int32)MyGameState->MiniMapCamera->MiniMapWidth, MyGameState->MiniMapCamera->MiniMapHeight, );
FBox MiniMapBounds( TopLeft, TopLeft + BottomRight );
StrategyPawn->GetStrategyCameraComponent()->AddNoScrollZone( MiniMapBounds );
StrategyPawn->GetStrategyCameraComponent()->UpdateCameraMovement( this );
}
}
}
}
}

StrategyInput.cpp

触屏设备上的多点触碰检测C++代码实现的更多相关文章

  1. 在触屏设备上面利用html5裁剪图片

    前言 如今触屏设备越来越流行,并且大多数已经支持html5了.针对此.对触屏设备开发图片裁剪功能, 让其能够直接处理图片.减轻服务端压力. 技术点 浏览器必须支持html5,包含fileReader. ...

  2. 在触屏设备上面利用html5裁剪图片(转)

    前言 现在触屏设备越来越流行,而且大多数已经支持html5了.针对此,对触屏设备开发图片裁剪功能, 让其可以直接处理图片,减轻服务端压力. 技术点 浏览器必须支持html5,包括fileReader, ...

  3. jquery -- 触屏设备touch事件

    几种普及得比较好的触摸事件,你可以在绝大多数现代浏览器中来测试这一事件(必须是触屏设备哦): touchstart:触摸开始的时候触发 touchmove:手指在屏幕上滑动的时候触发 touchend ...

  4. 在触屏设备中拖动 overflow 元素

    在 Android 和 iOS 等触屏设备中,如果网页中某元素设置 overflow: auto 或者 overflow:scroll,那么问题就来了.在 Android 3.0 之前以及 iPhon ...

  5. [Winform]关于cefsharp触屏设备长按文本内容,崩溃问题的修复

    摘要 在之前遇到cefsharp,在触屏电脑上,长按文本内容,会崩溃的问题. 相关文章 当时遇到这样的问题,在cefsharp项目下提交了bug.已经修复,可以参考当时我提的bug,以及解决过程,可参 ...

  6. 移动端touch触屏滑动事件、滑动触屏事件监听!

    一.触摸事件 ontouchstart.ontouchmove.ontouchend.ontouchcancel 目前移动端浏览器均支持这4个触摸事件,包括IE.由于触屏也支持MouseEvent,因 ...

  7. 朋友圈常见单页面触屏滑动上下翻屏功能jQuery实现

    翻页插件:实现原理,用margin-top来控制页面容器位置来实现上下翻页.margin这属性很好用,可以用来制作侧栏动画滑出菜单(左菜单,右内容,控制两者的margin实现):或者head下滑菜单 ...

  8. 在 Mac 上使用多点触控手势

    使用多点触控触控板或妙控鼠标,可以通过轻点.轻扫.捏合或开合一根或多根手指进行有用的操作. 触控板手势 有关这些手势的更多信息,请选取苹果菜单 () >“系统偏好设置”,然后点按“触控板”.您 ...

  9. 让BOOTSTRAP默认SLIDER支持触屏设备

    var isTouch=('ontouchstart' in window); if(isTouch){ $(".carousel").on('touchstart', funct ...

随机推荐

  1. zabbix监控系统的配置

    一.zabbix介绍 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系 ...

  2. axios 拦截 , 页面跳转, token 验证

    第一步: 路由 多添加一个自定义字段 requireAuth path: '/repository', name: 'repository', meta: { requireAuth: true, / ...

  3. 玩转树莓派:OpenHAB的入门(二)

    通过第一篇的介绍,我们现在已经安装了OpenHAB和Demo House,那么接下来我们来看一下OpenHAB是如何工作的. OpenHAB如何工作? 接下来你会在openHAB配置的共享文件夹看到s ...

  4. Python 文件复制_bytes

    f1 = open("c:/huyifei.jpg", mode="rb") f2 = open("d:/huerfei.jpg", mod ...

  5. 修改类不重启tomcat 自动加载项目

    可以修改类不用重启Tomcat加载整个项目(手工启动)     配置reloadable=true(自动重载)     使用Debug模式,前提是仅限于局部修改.(修改类不用重启--热加载) Tomc ...

  6. springboot整合jedisCluster

    maven依赖 springboot整合jedisCluster相当简单,maven依赖如下: <dependency> <groupId>org.springframewor ...

  7. CentOS使用安装光盘建立本地软件源

    本实验的目的是使用CentOS的两张DVD安装光盘作为本地软件源,避免执行yum安装命令时每次都要从网络重新下载. 安装createrepo软件包 createrepo是制作软件源所需要的一个工具,默 ...

  8. Unity 3D开发-C#脚本语言的一些基础用法

    Unity 中C#语言的一些基础用法 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 Lerp -- 线 ...

  9. 51Nod 1009:1009 数字1的数量 (思维)

    1009 数字1的数量  基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的 ...

  10. Assert随笔

    ☆ Assert.notNull(haha, "未找到需要导入的计划1");//haha必须不能为null,if为null则抛出message的异常: Assert.hasText ...