触屏设备上的多点触碰检测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 ...
随机推荐
- Python中的import
模块(module):用来从逻辑(实现一个功能)上组织Python代码(变量.函数.类),本质就是*.py文件.文件是物理上组织方式"module_name.py",模块是逻辑上组 ...
- 批量解帧视频文件cpp
前言 将多个视频文件进行解帧. 实现过程 1.批量获取文件路径: 2.对某个视频文件进行解帧: 代码 /************************************************ ...
- virtualenv 设置虚拟环境来运行不同版本的python
转自: http://pythonguidecn.readthedocs.io/zh/latest/dev/virtualenvs.html virtualenv 是一个创建隔绝的Python环境的 ...
- Struts2访问ServletAPI的三种方式
web应用中需要访问的ServletAPI,通常只有HttpServletRequest,HttpSession,ServletContext三个,这三个接口分别代表jsp内置对象中的request, ...
- Visual Studio 2017 以前的旧格式的 csproj Import 进来的 targets 文件有时不能正确计算属性(PropertyGroup)和集合(ItemGroup)
我在之前的博客中有教大家如何编写 NuGet 工具包,其中就有编写 .targets 文件. 我在实际的使用中,发现 Visual Studio 2017 带来的含 Sdk 的新 csproj 格式基 ...
- File、Directory、Path
File.Directory.Path https://blog.csdn.net/xiaouncle/article/details/52050577 File.Directory.Path是实际开 ...
- (4)logging(日志模块)
日志分成几个常用的级别 debug 10 代表程序调试过程中的信息 info 20 代表普通日志信息,用户的访问等等 warning 30 警告日志,有可能出错,但是目前还没出错的 error 40 ...
- shell 命令学习
https://blog.csdn.net/mnmlist/article/details/55215158
- web 常用网址及资源
一.web教程 w3school在线教程 菜鸟教程 二.学习路线 2017前端学习路线图,内附完整前端自学视频教程+工具经验-黑马程序员技术交流社区 三.工具 盘搜 百度地图 查物流 金山词霸 必应词 ...
- 【vue】创建一个vue前端项目,编译,发布
npm: Nodejs下的包管理器. webpack: 它主要的用途是通过CommonJS的语法把所有浏览器端需要发布的静态资源做相应的准备,比如资源的合并和打包. vue-cli: 用户生成Vue工 ...