KlayGE-004-InputCaps 例子分析
InputCaps处理外部输入的事件
该例子主要由两部分内容:
- 外部输入事件获取
可以处理keyboard、mouse、joystick、touch、sensor的输入事件
- 显示一个ui图标按钮
Input
定义监听事件类型:
KlayGE::InputActionDefine actions[] ={InputActionDefine(KeyboardMsg, KS_AnyKey),InputActionDefine(MouseMsg, MS_X),InputActionDefine(MouseMsg, MS_Y),InputActionDefine(MouseMsg, MS_Z),InputActionDefine(MouseMsg, MS_AnyButton),InputActionDefine(JoystickMsg, JS_LeftThumbX),InputActionDefine(JoystickMsg, JS_LeftThumbY),InputActionDefine(JoystickMsg, JS_LeftThumbZ),InputActionDefine(JoystickMsg, JS_RightThumbX),InputActionDefine(JoystickMsg, JS_RightThumbY),InputActionDefine(JoystickMsg, JS_RightThumbZ),InputActionDefine(JoystickMsg, JS_LeftTrigger),InputActionDefine(JoystickMsg, JS_RightTrigger),InputActionDefine(JoystickMsg, JS_AnyButton),InputActionDefine(TouchMsg, TS_Pan),InputActionDefine(TouchMsg, TS_Tap),InputActionDefine(TouchMsg, TS_Press),InputActionDefine(TouchMsg, TS_PressAndTap),InputActionDefine(TouchMsg, TS_Zoom),InputActionDefine(TouchMsg, TS_Rotate),InputActionDefine(TouchMsg, TS_Flick),InputActionDefine(TouchMsg, TS_Wheel),InputActionDefine(TouchMsg, TS_AnyTouch),InputActionDefine(SensorMsg, SS_AnySensing),InputActionDefine(Exit, KS_Escape)};
}
在OnCreate中绑定事件监听
KlayGE::InputEngine& inputEngine = KlayGE::Context::Instance().InputFactoryInstance().InputEngineInstance();KlayGE::InputActionMap actionMap;actionMap.AddActions(actions, actions + std::size(actions));action_handler_t input_handler = MakeSharedPtr<input_signal>();input_handler->Connect([this](InputEngine const& sender, InputAction const& action){this->InputHandler(sender, action);});inputEngine.ActionMap(actionMap, input_handler); // 获取joystic_设备for (size_t i = 0; i < inputEngine.NumDevices(); ++i){auto const& device = inputEngine.Device(i);if (device->Type() == InputEngine::IDT_Joystick){joystick_ = checked_pointer_cast<InputJoystick>(device);}}
主要的消息处理函数InputHandler实现:
void InputCaps::InputHandler(KlayGE::InputEngine const& sender, KlayGE::InputAction const& action)
{switch (action.first){case KeyboardMsg:{key_str_.clear();InputKeyboardActionParamPtr param = checked_pointer_cast<InputKeyboardActionParam>(action.second);for (uint32_t i = 0; i < 0xEF; ++i){if (param->buttons_state[i]){key_str_ += key_name[i] + L' ';}}}break;case MouseMsg:{InputMouseActionParamPtr param = checked_pointer_cast<InputMouseActionParam>(action.second);std::wostringstream stream;stream << param->abs_coord.x() << ' ' << param->abs_coord.y() << ' ';stream << param->move_vec.x() << ' ' << param->move_vec.y() << ' ' << param->wheel_delta << ' ';for (uint32_t i = 0; i < 8; ++i){if (param->buttons_state & (1UL << i)){stream << "button" << i << L' ';}}mouse_str_ = stream.str();}break;case JoystickMsg:{InputJoystickActionParamPtr param = checked_pointer_cast<InputJoystickActionParam>(action.second);std::wostringstream stream;stream << param->thumbs[0].x() << ' ' << param->thumbs[0].y() << ' ' << param->thumbs[0].z() << ' ';stream << param->thumbs[1].x() << ' ' << param->thumbs[1].y() << ' ' << param->thumbs[1].z() << ' ';stream << param->triggers[0] << ' ' << param->triggers[1] << ' ';for (uint32_t i = 0; i < 16; ++i){if (param->buttons_state & (1UL << i)){stream << "button" << i << L' ';}}joystick_str_ = stream.str();if (joystick_){for (uint32_t i = 0; (i < joystick_->NumVibrationMotors()) && (i < 2); ++i){joystick_->VibrationMotorSpeed(i, param->triggers[i]);}}}break;case TouchMsg:{InputTouchActionParamPtr param = checked_pointer_cast<InputTouchActionParam>(action.second);std::wostringstream stream;stream << touch_name[param->gesture - 0x300] << ' ';if (param->gesture != TS_None){stream << "center " << param->center.x() << ' ' << param->center.y() << ' ';switch (param->gesture){case TS_Pan:case TS_Tap:case TS_Flick:stream << "move " << param->move_vec.x() << ' ' << param->move_vec.y() << ' ';break;case TS_Zoom:stream << "factor " << param->zoom << ' ';break;case TS_Rotate:stream << "angle " << param->rotate_angle << ' ';break;default:break;}}if (param->wheel_delta != 0){stream << "Wheel " << param->wheel_delta << ' ';}for (uint32_t i = 0; i < 16; ++i){if (param->touches_down & (1UL << i)){stream << "Touch" << i << L" Down ";}if (param->touches_up & (1UL << i)){stream << "Touch" << i << L" Up ";}}touch_str_ = stream.str();}break;case SensorMsg:{InputSensorActionParamPtr param = checked_pointer_cast<InputSensorActionParam>(action.second);std::wostringstream stream;stream << "Lat: " << param->latitude << " Lng: " << param->longitude;stream << " Orientation: " << param->orientation_quat.x() << ' ' << param->orientation_quat.y()<< ' ' << param->orientation_quat.z() << ' ' << param->orientation_quat.w();sensor_str_ = stream.str();}break;case Exit:this->Quit();break;}
}
UI
ui使用内置的ui解析脚本:uiml格式文件,从外部获取一个特定尺寸的图片作为按钮显示在指定位置
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<ui><dialog id="Logo" caption="Logo" x="-128" y="0" align_x="right" align_y="top" width="128" height="128" show_caption="false" opacity="true" bg_color_a="0"><control type="tex_button" id="LogoButton" texture="powered_by_klayge.dds" x="0" y="0" width="128" height="128" is_default="0"/></dialog>
</ui>
在OnCreate函数中加载ui资源
KlayGE::UIManager::Instance().Load(*KlayGE::ResLoader::Instance().Open("InputCaps.uiml"));
在DoUpdateOverlay函数中渲染
KlayGE::UIManager::Instance().Render();
在Onsize时,更新:
KlayGE::UIManager::Instance().SettleCtrls();
编写本例子遇到的坑
以下类无法找到,link失败:
1>InputCaps.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) class std::unique_ptr<class KlayGE::Signal::Detail::Mutex,struct std::default_delete<class KlayGE::Signal::Detail::Mutex> > __cdecl KlayGE::Signal::Detail::CreateMutexA(void)" (__imp_?CreateMutexA@Detail@Signal@KlayGE@@YA?AV?$unique_ptr@VMutex@Detail@Signal@KlayGE@@U?$default_delete@VMutex@Detail@Signal@KlayGE@@@std@@@std@@XZ),函数 "public: __cdecl KlayGE::Signal::Detail::SignalTemplateBase<void __cdecl(class KlayGE::InputEngine const &,struct std::pair<unsigned short,class std::shared_ptr<struct KlayGE::InputActionParam> > const &),struct KlayGE::Signal::CombinerDefault<void> >::SignalTemplateBase<void __cdecl(class KlayGE::InputEngine const &,struct std::pair<unsigned short,class std::shared_ptr<struct KlayGE::InputActionParam> > const &),struct KlayGE::Signal::CombinerDefault<void> >(void)" (??0?$SignalTemplateBase@$$A6AXAEBVInputEngine@KlayGE@@AEBU?$pair@GV?$shared_ptr@UInputActionParam@KlayGE@@@std@@@std@@@ZU?$CombinerDefault@X@Signal@2@@Detail@Signal@KlayGE@@QEAA@XZ) 中引用了该符号
1>F:\code\project\test\Learning.test\GFX\KlayGE\KlayGELearning\bin\Debug\InputCaps.exe : fatal error LNK1120: 1 个无法解析的外部命令
意思就是找不到这个函数:
__declspec(dllimport) class std::unique_ptr<class KlayGE::Signal::Detail::Mutex,struct std::default_delete<class KlayGE::Signal::Detail::Mutex> > __cdecl KlayGE::Signal::Detail::CreateMutexA(void)
在KlayGE_Core_vc142.dll中,只找到了这个
class std::unique_ptr<class KlayGE::Signal::Detail::Mutex,struct std::default_delete<class KlayGE::Signal::Detail::Mutex> > __cdecl KlayGE::Signal::Detail::CreateMutexW(void)
很明显,CreateMutex是windows kernel32中的api函数,但KlayGE却导出了一个同名的函数,导致函数签名错误。KlayGE默认使用unicode字符集,我的项目未设置,使用了多字节,结果就成了CreateMutexA。
最终的解决办法
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
但是,最好不要让自己的函数名称和常用库的API同名,这里出现冲突也和window的unicode使用宏定义有很大原因,如下:
#ifdef UNICODE
#define CreateMutex CreateMutexW
#else
#define CreateMutex CreateMutexA
#endif // !UNICODE
最终效果
源码
KlayGE学习主目录
相关文章:

KlayGE-004-InputCaps 例子分析
InputCaps处理外部输入的事件 该例子主要由两部分内容: 外部输入事件获取 可以处理keyboard、mouse、joystick、touch、sensor的输入事件 显示一个ui图标按钮 Input 定义监听事件类型: KlayGE::InputActionDefine actions[] {InputActionDefin…...
组装机经验、软硬件故障排除、网络问题
目录 主板 CPU 内存 显卡 判断显卡好坏的步骤 新买的显卡安装后显示器不亮 电源 其他 网络问题 主板 1.不同主板对于不同数量的内存条安装的位置有要求,要按照主板规定的位置安装不同数量的内存条,特别是服务器主板,否则系统可能起…...

【行为型模式】责任链模式
文章目录1、简介2、结构3、实现方式3.1、案例引入3.2、结构分析3.3、具体实现4、责任链优缺点5、应用场景1、简介 责任链模式(Chain of Responsibility)是一种行为型设计模式,它允许对象在链上依次处理请求,用户只需要将请求发送到责任链上即可…...
C++命令模式 指挥家:掌控命令模式之美
C指挥家:掌控命令模式之美 (C Conductor: Master the Beauty of Command Pattern一、引言 (Introduction)1.1 命令模式概述 (Overview of Command Pattern)1.2 命令模式的应用场景 (Application Scenarios of Command Pattern)二、命令模式的基本概念 (Basic Concep…...

学会 制作极简搜索浏览器 —— 并将 ChatGPT 接入浏览器
前期回顾 Vue3 Ts Vite pnpm 项目中集成 —— eslint 、prettier、stylelint、husky、commitizen_0.活在风浪里的博客-CSDN博客搭建VIte Ts Vue3项目并集成eslint 、prettier、stylelint、huskyhttps://blog.csdn.net/m0_57904695/article/details/129950163?spm1001.2…...

NumPy 秘籍中文第二版:六、特殊数组和通用函数
原文:NumPy Cookbook - Second Edition 协议:CC BY-NC-SA 4.0 译者:飞龙 在本章中,我们将介绍以下秘籍: 创建通用函数查找勾股三元组用chararray执行字符串操作创建一个遮罩数组忽略负值和极值使用recarray函数创建一…...
各种交叉编译工具链的区别
目录 1 命名规则 2 实例 2.1 arm-none-eabi-gcc 2.2 arm-none-linux-gnueabi-gcc 2.3 arm-eabi-gcc 2.4 armcc 2.5 arm-none-uclinuxeabi-gcc 和 arm-none-symbianelf-gcc 3 gnueabi和gnueabihf的区别(硬浮点、软浮点) 4 Linaro公司出品的交叉编译工具链 5 ARM公司出…...

密度聚类算法(DBSCAN)实验案例
密度聚类算法(DBSCAN)实验案例 描述 DBSCAN是一种强大的基于密度的聚类算法,从直观效果上看,DBSCAN算法可以找到样本点的全部密集区域,并把这些密集区域当做一个一个的聚类簇。DBSCAN的一个巨大优势是可以对任意形状…...

第07章_面向对象编程(进阶)
第07章_面向对象编程(进阶) 讲师:尚硅谷-宋红康(江湖人称:康师傅) 官网:http://www.atguigu.com 本章专题与脉络 1. 关键字:this 1.1 this是什么? 在Java中,this关键字不算难理解…...
异常的讲解(2)
目录 throws异常处理 基本介绍 throws异常处理注意事项和使用细节 自定义异常 基本概念 自定义异常的步骤 throw 和throws的区别 本章作业 第一题 第二题 第三题 第四题 throws异常处理 基本介绍 1)如果一个方法(中的语句执行时)可能生成某种异常,但是…...

jvm内存结构
1. 栈 程序计数器 2. 虚拟机栈 3. 本地方法栈 4. 堆 5. 方法区 1.2栈内存溢出 栈帧过多导致栈内存溢出 /*** 演示栈内存溢出 java.lang.StackOverflowError* -Xss256k*/ public class Demo1_2 {private static int count;public static void main(String[] args) {try {meth…...

要刹车?生成式AI迎新规、行业连发ChatGPT“警报”、多国考虑严监管
4月13日消息,据中国移动通信联合会元宇宙产业工作委员会网站,中国移动通信联合会元宇宙产业工作委员会、中国通信工业协会区块链专业委员会等,共同发布“关于元宇宙生成式人工智能(类 ChatGPT)应用的行业提示”。提示内…...
轻松掌握Qt FTP 机制:实现高效文件传输
轻松掌握Qt FTP:实现高效文件传输一、简介(Introduction)1.1 文件传输协议(FTP)Qt及其网络模块(Qt and its Network Module)QNetwork:二、QNetworkAccessManager上传实例(Qt FTP Upl…...

用AI帮我写一篇关于FPGA的文章,并推荐最热门的FPGA开源项目
FPGA定义 FPGA(Field Programmable Gate Array)是一种可编程逻辑器件,可以在硬件电路中实现各种不同的逻辑功能。与ASIC(Application Specific Integrated Circuit,特定应用集成电路)相比,FPGA…...
从兴趣或问题出发
当我们还沉寂在移动互联网给生活带来众多便利中,以 ChartGPT 为代表的 AI 时代已彻底到来。科技的发展,时刻在改变着我们的生活,我们需要不断地学习新知识和掌握新技能才能享受变化带来的便利,以及自身不被社会淘汰。 因此&#…...

C++ | 探究拷贝对象时的一些编译器优化
👑作者主页:烽起黎明 🏠学习社区:烈火神盾 🔗专栏链接:C 文章目录前言一、传值传参二、传引用传参三、传值返回拷贝构造和赋值重载的辨析四、传引用返回【❌】五、传匿名对象返回六、总计与提炼前言 在传参…...

linux工具gcc/g++/gdb/git的使用
目录 gcc/g 基本概念 指令集 函数库 (重要) gdb使用 基本概念 指令集 项目自动化构建工具make/makefile 进度条小程序 编辑 git三板斧 创建仓库 git add git commit git push git status git log gcc/g 基本概念 gcc/g称为编译器…...

Direct3D 12——纹理——纹理
纹理不同于缓冲区资源,因为缓冲区资源仅存储数据数组,而纹理却可以具有多个mipmap层级(后 文有介绍),GPU会基于这个层级进行相应的特殊操作,例如运用过滤器以及多重采样。支持这些特殊 的操作纹理资源都被限定为一些特定的数据格式…...

产品经理必读 | 俞军产品经理十二条军规
最近在学习《俞军产品方法论》,觉得俞军总结的十二条产品经理原则非常受用,分享给大家。 01. 产品经理首先是产品的深度用户 自己设计的产品都没使用过的产品经理,如何明白用户使用的问题,如何解决问题,所以产品经理肯…...

【机器视觉1】光源介绍与选择
文章目录一、常见照明光源类型二、照明光源对比三、照明技术3.1 亮视野与暗视野3.2 低角度照明3.3 前向光直射照明3.4 前向光漫射照明3.5 背光照明-测量系统的最佳选择3.6 颜色与补色示例3.7 偏光技术应用四、镜头4.1 镜头的几个概念4.2 影响图像质量的关键因素4.3 成像尺寸4.4…...
【根据当天日期输出明天的日期(需对闰年做判定)。】2022-5-15
缘由根据当天日期输出明天的日期(需对闰年做判定)。日期类型结构体如下: struct data{ int year; int month; int day;};-编程语言-CSDN问答 struct mdata{ int year; int month; int day; }mdata; int 天数(int year, int month) {switch (month){case 1: case 3:…...
java调用dll出现unsatisfiedLinkError以及JNA和JNI的区别
UnsatisfiedLinkError 在对接硬件设备中,我们会遇到使用 java 调用 dll文件 的情况,此时大概率出现UnsatisfiedLinkError链接错误,原因可能有如下几种 类名错误包名错误方法名参数错误使用 JNI 协议调用,结果 dll 未实现 JNI 协…...

【SQL学习笔记1】增删改查+多表连接全解析(内附SQL免费在线练习工具)
可以使用Sqliteviz这个网站免费编写sql语句,它能够让用户直接在浏览器内练习SQL的语法,不需要安装任何软件。 链接如下: sqliteviz 注意: 在转写SQL语法时,关键字之间有一个特定的顺序,这个顺序会影响到…...

华为OD机试-食堂供餐-二分法
import java.util.Arrays; import java.util.Scanner;public class DemoTest3 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint a in.nextIn…...

Redis数据倾斜问题解决
Redis 数据倾斜问题解析与解决方案 什么是 Redis 数据倾斜 Redis 数据倾斜指的是在 Redis 集群中,部分节点存储的数据量或访问量远高于其他节点,导致这些节点负载过高,影响整体性能。 数据倾斜的主要表现 部分节点内存使用率远高于其他节…...

Reasoning over Uncertain Text by Generative Large Language Models
https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829 1. 概述 文本中的不确定性在许多语境中传达,从日常对话到特定领域的文档(例如医学文档)(Heritage 2013;Landmark、Gulbrandsen 和 Svenevei…...

JVM 内存结构 详解
内存结构 运行时数据区: Java虚拟机在运行Java程序过程中管理的内存区域。 程序计数器: 线程私有,程序控制流的指示器,分支、循环、跳转、异常处理、线程恢复等基础功能都依赖这个计数器完成。 每个线程都有一个程序计数…...
【Android】Android 开发 ADB 常用指令
查看当前连接的设备 adb devices 连接设备 adb connect 设备IP 断开已连接的设备 adb disconnect 设备IP 安装应用 adb install 安装包的路径 卸载应用 adb uninstall 应用包名 查看已安装的应用包名 adb shell pm list packages 查看已安装的第三方应用包名 adb shell pm list…...
C语言中提供的第三方库之哈希表实现
一. 简介 前面一篇文章简单学习了C语言中第三方库(uthash库)提供对哈希表的操作,文章如下: C语言中提供的第三方库uthash常用接口-CSDN博客 本文简单学习一下第三方库 uthash库对哈希表的操作。 二. uthash库哈希表操作示例 u…...
c# 局部函数 定义、功能与示例
C# 局部函数:定义、功能与示例 1. 定义与功能 局部函数(Local Function)是嵌套在另一个方法内部的私有方法,仅在包含它的方法内可见。 • 作用:封装仅用于当前方法的逻辑,避免污染类作用域,提升…...