触屏设备上的多点触碰检测C++代码实现
转自: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++代码实现的更多相关文章
- 在触屏设备上面利用html5裁剪图片
前言 如今触屏设备越来越流行,并且大多数已经支持html5了.针对此.对触屏设备开发图片裁剪功能, 让其能够直接处理图片.减轻服务端压力. 技术点 浏览器必须支持html5,包含fileReader. ...
- 在触屏设备上面利用html5裁剪图片(转)
前言 现在触屏设备越来越流行,而且大多数已经支持html5了.针对此,对触屏设备开发图片裁剪功能, 让其可以直接处理图片,减轻服务端压力. 技术点 浏览器必须支持html5,包括fileReader, ...
- jquery -- 触屏设备touch事件
几种普及得比较好的触摸事件,你可以在绝大多数现代浏览器中来测试这一事件(必须是触屏设备哦): touchstart:触摸开始的时候触发 touchmove:手指在屏幕上滑动的时候触发 touchend ...
- 在触屏设备中拖动 overflow 元素
在 Android 和 iOS 等触屏设备中,如果网页中某元素设置 overflow: auto 或者 overflow:scroll,那么问题就来了.在 Android 3.0 之前以及 iPhon ...
- [Winform]关于cefsharp触屏设备长按文本内容,崩溃问题的修复
摘要 在之前遇到cefsharp,在触屏电脑上,长按文本内容,会崩溃的问题. 相关文章 当时遇到这样的问题,在cefsharp项目下提交了bug.已经修复,可以参考当时我提的bug,以及解决过程,可参 ...
- 移动端touch触屏滑动事件、滑动触屏事件监听!
一.触摸事件 ontouchstart.ontouchmove.ontouchend.ontouchcancel 目前移动端浏览器均支持这4个触摸事件,包括IE.由于触屏也支持MouseEvent,因 ...
- 朋友圈常见单页面触屏滑动上下翻屏功能jQuery实现
翻页插件:实现原理,用margin-top来控制页面容器位置来实现上下翻页.margin这属性很好用,可以用来制作侧栏动画滑出菜单(左菜单,右内容,控制两者的margin实现):或者head下滑菜单 ...
- 在 Mac 上使用多点触控手势
使用多点触控触控板或妙控鼠标,可以通过轻点.轻扫.捏合或开合一根或多根手指进行有用的操作. 触控板手势 有关这些手势的更多信息,请选取苹果菜单 () >“系统偏好设置”,然后点按“触控板”.您 ...
- 让BOOTSTRAP默认SLIDER支持触屏设备
var isTouch=('ontouchstart' in window); if(isTouch){ $(".carousel").on('touchstart', funct ...
随机推荐
- ZooKeeper客户端原生API的使用以及ZkClient第三方API的使用
这两部分内容的介绍主要讲的是节点及节点内容和子节点的操作,并且讲解的节点的事件监听以及ACL授权 ZooKeeper客户端原生API的使用 百度网盘地址: http://pan.baidu.com/s ...
- 12个有趣的 XSS Vector
XSS Vector #1 <script src=/〱20.rs></script> URL中第二个斜杠在Internet Explorer下(测试于IE11)可被U+303 ...
- Redis学习第四课:Redis List类型及操作
list是一个链表结构,主要功能是push.pop.获取一个范围的所有值等,操作中key理解为链表的名字. Redis的list类型其实就是一个每个子元素都是string类型的双向链表.我们可以通过p ...
- WebGL编程指南高级技术篇(常见需求的处理)
一.鼠标控制模型旋转 实质的根据鼠标移动前后的位置比较得出x,y轴的旋转角度: 图中是一个屏幕,有一个模型(恩,他是一个模型),鼠标由P点移动到P1点,我们假定移动单位步长旋转β角度: P(x1,y1 ...
- NSJSONSerialization的简单用法
NSJSONSerialization 苹果官方给出的解析方式是性能最优越的,虽然用起来稍显复杂. 首先我们在上面已经有了我希望得到的信息的网站的API给我们的URL,在OC中,我要加载一个NSURL ...
- NBUT 1217 Dinner 2010辽宁省赛
Time limit 1000 ms Memory limit 32768 kB Little A is one member of ACM team. He had just won the g ...
- C语言基础:枚举.宏 分类: iOS学习 c语言基础 2015-06-10 22:01 20人阅读 评论(0) 收藏
枚举:一组有符号的整型常量,一 一列举所有的状态 枚举常和switch连用 enum week{ monday=1, tuesday, wednesday, thursday, friday, sat ...
- 微信小程序实现多选分享
微信小程序拉取好友列表后,默认只能选一个分享,现在在分享回调onShareAppMessage里加上这段代码,拉取好友列表时,右上角会出现多选按钮,这样就解决了微信小程序安卓下只能单选分享的问题. / ...
- 《DSP using MATLAB》Problem 3.4
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- LG2044 [NOI2012]随机数生成器
题意 栋栋最近迷上了随机算法,而随机数是生成随机算法的基础.栋栋准备使用线性同余法(Linear Congruential Method)来生成一个随机数列,这种方法需要设置四个非负整数参数m,a,c ...