转自: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. java.c++.c#.c的区别

    C++则一般看作是对C语言的扩展. Java语言是一种完全的面向对象语言,虽然它的底层(运行时库)是用C语言开发的,可是并不依赖于C. C#是微软开发的一种编程语言,语法类似Java,几乎就是从Jav ...

  2. SWIFT中的repeat...while

    SWIFT中的repeat...while类似于JAVA\.NET中的 do while.大同小异只是把do换成了repeat var index = 10 repeat{ print(index) ...

  3. [编程题] N阶楼梯上楼问题

    import sys for line in sys.stdin: N=int(line.split()[0]) d1=1 d2=2 if(N==1): print 1 continue elif(N ...

  4. 温度传感器的AD值,电压和电阻的计算方法

    V是输入的电压,VCC是标准电压,R为固定电阻,NTC为热敏电阻.计算公式是V=(NTC/(NTC+R))*VCC电压或电阻转化AD的计算方式为AD=(V/VCC)*2^n=(NTC/(NTC+R)) ...

  5. CTF-练习平台-Misc之 Linux基础1

    十四.Linux基础1 下载打开文件,解压后发下是一个没有后缀名的文件,添加后缀名为txt,搜索关键词“KEY”,发现flag Linux???不存在的!

  6. 各种CTF的WP

    http://l-team.org/archives/43.html PlaidCTF-2014-twenty/mtpox/doge_stege-Writeup http://l-team.org/a ...

  7. 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.2 lock-on-active

    转载至:https://blog.csdn.net/wo541075754/article/details/75208955 lock-on-active 当在规则上使用ruleflow-group属 ...

  8. Ubuntu 16.04下指定Sublime Text 3 默认python编译版本

    安装PackageResourceViewer插件 输入 Ctrl+Shift+P 输入install,选择Package Control: Install Package 选择PackageReso ...

  9. LG1600 天天爱跑步

    题意 分析 对一个(s,t)查询,令f=lca(s,t),则操作可化为(s,f),(f,t). 考虑观察到的情况,若x在s到t的路径上,且x观察到,则 \[ \textrm{dep}_s-\textr ...

  10. mysql常用的聚合函数

    GROUP BY(聚合)函数本章论述了用于一组数值操作的 group (集合)函数.除非另作说明, group 函数会忽略 NULL 值. 假如你在一个不包含 ROUP BY子句的语句中使用一个 gr ...