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

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

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

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

触发回调:

  1. void ATD_MobilePlayerController::MoveToTouchLocation(const ETouchIndex::Type FingerIndex, const FVector Location)
  2. {
  3. FVector2D ScreenSpaceLocation(Location);
  4.  
  5. // Trace to see what is under the touch location
  6. FHitResult HitResult;
  7. GetHitResultAtScreenPosition(ScreenSpaceLocation, CurrentClickTraceChannel, true, HitResult);
  8. if (HitResult.bBlockingHit)
  9. {
  10. // We hit something, move there
  11. SetNewMoveDestination(HitResult.ImpactPoint);
  12. }
  13. }

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

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

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

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

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

  1. void AStrategyPlayerController::ProcessPlayerInput(const float DeltaTime, const bool bGamePaused)
  2. {
  3. if (!bGamePaused && PlayerInput && InputHandler && !bIgnoreInput)
  4. {
  5. InputHandler->UpdateDetection(DeltaTime);
  6. }
  7.  
  8. Super::ProcessPlayerInput(DeltaTime, bGamePaused);
  9.  
  10. if (!bIgnoreInput )
  11. {
  12. const ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
  13. AStrategySpectatorPawn* StrategyPawn = GetStrategySpectatorPawn();
  14. if(( StrategyPawn != NULL ) && ( LocalPlayer != NULL ))
  15. {
  16. // Create the bounds for the minimap so we can add it as a 'no scroll' zone.
  17. AStrategyHUD* const HUD = Cast<AStrategyHUD>(GetHUD());
  18. AStrategyGameState const* const MyGameState = GetWorld()->GetGameState<AStrategyGameState>();
  19. if( (MyGameState != NULL ) && ( MyGameState->MiniMapCamera.IsValid() == true ) )
  20. {
  21. if( LocalPlayer->ViewportClient != NULL )
  22. {
  23. const FIntPoint ViewportSize = LocalPlayer->ViewportClient->Viewport->GetSizeXY();
  24. const uint32 ViewTop = FMath::TruncToInt(LocalPlayer->Origin.Y * ViewportSize.Y);
  25. const uint32 ViewBottom = ViewTop + FMath::TruncToInt(LocalPlayer->Size.Y * ViewportSize.Y);
  26.  
  27. FVector TopLeft( HUD->MiniMapMargin, ViewBottom - HUD->MiniMapMargin - MyGameState->MiniMapCamera->MiniMapHeight, );
  28. FVector BottomRight( (int32)MyGameState->MiniMapCamera->MiniMapWidth, MyGameState->MiniMapCamera->MiniMapHeight, );
  29. FBox MiniMapBounds( TopLeft, TopLeft + BottomRight );
  30. StrategyPawn->GetStrategyCameraComponent()->AddNoScrollZone( MiniMapBounds );
  31. StrategyPawn->GetStrategyCameraComponent()->UpdateCameraMovement( this );
  32. }
  33. }
  34. }
  35. }
  36. }

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. JVM --- OutOfMemoryError异常

    在Java虚拟机规范的描述中,除了程序计数器外,虚拟机内存的其他几个运行时区域都有可能发生OutOfMemoryError(OOM)异常. 1.Java堆溢出 Java堆用于存储对象实例,只要不断地创 ...

  2. SWIFT中的repeat...while

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

  3. I.MX6 Linux Serial Baud Rate hacking

    /******************************************************************************** * I.MX6 Linux Seri ...

  4. test20190320 全连(fc)

    题意 全连(fc) [题目背景] 还记得若干年前那段互相比较<克罗地亚狂想曲>的分数的日子吗? [题目描述] E.Space 喜欢打音游. 但是他技术不好,总是拿不到全连(Full Com ...

  5. mac OS 安装 scikit-learn

    最近用来做实验,使用python时发现scikit-learn提供的库非常好用.因此,在电脑上果断下载安装: step1: sudo easy_install pip step2: sudo pip ...

  6. GStreamer插件分类

    gst-plugins-base一套小而固定的插件,涵盖各种可能类型的elements; 这些在开发系列期间随着核心变化而不断更新.我们相信分销商可以安全地发行这些插件.人们编写插件应该将他们的代码基 ...

  7. day27 python学习 logging

    logging模块 函数式简单配置 import logging logging.debug('debug message') logging.info('info message') logging ...

  8. 【转】每天一个linux命令(8):cp 命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/10/29/2744185.html cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一 ...

  9. MySQL中character set与collation的理解(转)

    character set和collation的是什么? character set即字符集 我们常看到的UTF-8.GB2312.GB18030都是相互独立的character set.即对Unic ...

  10. golang cannot assign to

    问题: # command-line-arguments .\example.go:22: cannot assign to m.V.(BasicMessage).Length 想在函数中修改inte ...