使用 Kinect 和 OpenNI 在 Unity 中检测手势

发布于 2025-01-03 11:21:27 字数 477 浏览 1 评论 0原文

我的 Unity 项目中有一个 3D 模型,并且有一个 JavaScript,可以根据键盘箭头键(左/右)旋转相机。

现在,我需要一个脚本来检测水平滑动手势并返回一个用于旋转相机的矢量。

我将 ZigFu SDK 与 PrimeSense OpenNI/NITE 结合使用。 ZigFu SDK 附带示例脚本,其中之一是 SwipeDetector - 我想知道它是如何工作的?

我的设置: 我有 3 个 GameObjects:一个 3D 模型、一个 MainCamera 和一个定向光。

那么,如何在我的项目中使用 SwipeDetector 脚本?我现在的做法是 1) 创建一个空的游戏对象“SwipeDetection”,2) 从 ZigFu“拖放”SwipeDetector 脚本。我已将日志放入 SwipeDetector 脚本中,但我没有看到它们。

I have a 3D model in my Unity project and I have a JavaScript that rotates the camera based on keyboard arrow keys (left/right).

Now, I need to have a script that detects a horizontal swipe hand gesture and returns a vector that I would use to rotate the camera.

I am using the ZigFu SDK with PrimeSense OpenNI/NITE. The ZigFu SDK comes with sample scripts, one of which is SwipeDetector - I am wondering how does it work?

My setup:
I have 3 GameObjects: a 3D model, a MainCamera, and a Directional Light.

So, how do I use the SwipeDetector script in my project? The way I do it right now is 1)Create an empty game object "SwipeDetection", 2) "drag and drop" the SwipeDetector script from ZigFu. I've put in logs in the SwipeDetector script, but I don't see them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄意 2025-01-10 11:21:27

Zigfu 绑定(我假设您使用的是 1.4 版?)没有 SwipeDetector 示例,但它们确实包含 SwipeDetector MonoBehaviour。 SwipeDetector 检测垂直和水平滑动,但遗憾的是无法检测滑动的速度。

您有几个选项:

  1. 使用提供的滑动检测器,并在每次检测到水平滑动(SwipeDetector_Left 或 SwipeDetector_Right 事件)时将相机旋转固定量

  2. 使用提供的 Swipe检测器,在 Swipe 上开始旋转,在 SwipeDetector_Release 事件上停止旋转。这类似于按箭头键(假设您在 keydown/keyup 事件上有相同的行为)

  3. 跟踪手部速度,并在滑动发生时检查其值。使用该值来旋转相机。您可以通过创建新的 MonoBehaviour 并实现 Hand_Create、Hand_Update 和 Hand_Destroy(查看 HandpointControls 文件夹中的任何脚本)来跟踪速度。将最后 n 帧中的手点放入队列中。最新和最新版本之间的差异最旧的点将是这 n 帧的速度(我建议您从 15 帧或大约半秒开始)

(这将包含在未来的 Zigfu 版本中:))

您的游戏对象设置听起来正确 - 如果您没有看到任何记录您可能没有正确执行“焦点手势”。尝试向传感器挥手或轻敲 - 这应该会导致调用 Hand_Create 事件。一旦获得有效的手点,您应该从滑动检测器获得正确的事件。

另外值得一提的是,您的滑动检测游戏对象应该有一个 HandPointControl 组件(使用 RequireComponent 隐式添加),并且“ActiveOnStart”应该为 true。

The Zigfu bindings (I'm assuming you're using version 1.4?) dont have a SwipeDetector sample, but they do include a SwipeDetector MonoBehaviour. The SwipeDetector detects vertical and horizontal swipes, but unfortunately doesn't detect the velocity of the swipe.

You have a few options:

  1. Use the provided Swipe Detector, and rotate the camera by a fixed amount every time you detect a horizontal swipe (SwipeDetector_Left or SwipeDetector_Right events)

  2. Use the provided Swipe Detector, start rotating on Swipe, and stop rotating on the SwipeDetector_Release event. This would be similar to pressing on the arrow keys (assuming you have the same behaviour on keydown/keyup events)

  3. Keep track of the hand velocity, and check its value when the swipe occurs. Use this value to rotate the camera. You can keep track of velocity by creating a new MonoBehaviour, and implementing Hand_Create, Hand_Update, and Hand_Destroy (look at any of the scripts in the HandpointControls folder). Keep a queue with the hand points from the last n frames. The delta between the newest & oldest points will be your velocity for those n frames (I recommend you start with 15 frames, or about half a second)

(This will be included in a future Zigfu release :))

Your game object setup sounds right - if you dont see any logs you may not be performing the 'focus gesture' correctly. Try waving or performing a tap towards the sensor - this should cause the Hand_Create event to be called. Once you have a valid handpoint you should get the proper events from the Swipe Detector.

Also worth mentioning your swipe detection game object should have a HandPointControl component (added implicitly with RequireComponent) and that 'ActiveOnStart' should be true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文