openHMD-simple代码分析(2/2)

本文深入分析openHMD中的设备打开、数据更新和四元素获取过程。通过oculars DK1/DK2设备为例,阐述ohmd_list_open_device如何开启设备,ohmd_ctx_update如何更新数据,以及ohmd_device_setf和ohmd_device_getf如何操作四元素。文中提及的fusion算法和传感器数据解析对于理解openHMD的工作原理至关重要。
摘要由CSDN通过智能技术生成

openHMD-simple代码分析(2/2)

接上篇内容,这里主要以oculars在openHMD中的提交,来分析oculars的DK1/DK2在openHMD中是如何运行的。
simple代码的主流程看上篇文章”openHMD-simple代码分析(1/2)”。

打开设备:ohmd_list_open_device

    //打开设备列表中第一个设备
    ohmd_device* hmd = ohmd_list_open_device(ctx, 0);

    if(!hmd){
        printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
        return -1;
    }

ohmd_list_open_device函数:

ohmd_device* OHMD_APIENTRY ohmd_list_open_device(ohmd_context* ctx, int index)
{
    ohmd_device_settings settings;
    //设置设备数据的更新方式:
    //false:需要手动调用ohmd_ctx_update来更新数据
    //true:创建线程,调用设备的update方法来更新数据(如rift.c里的update_devices)
    settings.automatic_update = true;

    return ohmd_list_open_device_s(ctx, index, &settings);
}

ohmd_list_open_device_s函数:

ohmd_device* OHMD_APIENTRY ohmd_list_open_device_s(ohmd_context* ctx, int index, ohmd_device_settings* settings)
{
    ohmd_lock_mutex(ctx->update_mutex);
    //轮询所有设备
    if(index >= 0 && index < ctx->list.num_devices){

        ohmd_device_desc* desc = &ctx->list.devices[index];
        ohmd_driver* driver = (ohmd_driver*)desc->driver_ptr;
        ohmd_device* device = driver->open_device(driver, desc);

        if (device == NULL)
            return</
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值