Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Krux02's avatar
Krux02
Honored Guest
11 years ago

Minimum sensor polling demo for linux with sdl2 and c-api

Hi I am using the C api 3.2 on linux and would like to have a minimum loop the polls the sensors each frame. This is what I have so far:


#include <iostream>
#include <SDL2/SDL.h>
#include <memory>
#include <OVR_CAPI.h>
#include <OVR_CAPI_GL.h>
#include <chrono>
#include <thread>

using namespace std;

ostream& operator<<(ostream& os, const ovrQuatf& quat) {
return os << "q(" << quat.x << quat.y << quat.z << quat.w << ")";
}

ostream& operator<<(ostream& os, const ovrVector3f& pos) {
return os << "vec3(" << pos.x << pos.y << pos.z << ")";
}

ostream& operator<<(ostream& os, ovrPosef pose) {
return os << "pose(" << pose.Orientation << pose.Position << ")";
}

int main(int argc, char* argv[]){
for(int i = 0; i < argc; i++) {
cout << argv << endl;
}



if ( !ovr_Initialize() ){
cout << "can't init ovr" << endl;
} else {
cout << "ovr ok" << endl;
}

auto hmd = ovrHmd_Create(0);
if ( hmd == nullptr ) {
cout << "create debug" << endl;
hmd = ovrHmd_CreateDebug(ovrHmd_DK1);
}

ovrHmdDesc desc;
ovrHmd_GetDesc(hmd, &desc);

int ok = SDL_Init(SDL_INIT_EVERYTHING);
cout << "Hello World! " << ok << endl;

auto window = SDL_CreateWindow("bla",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,320,240,0);

SDL_Event event;

cout << "pseudo render loop" << endl;
ok = true;
while (ok) {
ovrHmd_BeginFrame(hmd,0);
for (int j = 0; j < ovrEye_Count; j++){
auto eye = desc.EyeRenderOrder[j];
ovrPosef pose = ovrHmd_BeginEyeRender(hmd, eye);
cout << pose;
ovrHmd_EndEyeRender(hmd, eye, pose, nullptr);
this_thread::sleep_for(chrono::milliseconds(16));
}
ovrHmd_EndFrame(hmd);
cout << endl;

SDL_PumpEvents();
SDL_PollEvent(&event);

switch(event.type) {
case SDL_KEYDOWN:
if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
ok = false;
}
break;
case SDL_WINDOWEVENT_CLOSE:
ok = false;
break;
}
}

SDL_DestroyWindow(window);

ovrHmd_Destroy(hmd);

ovr_Shutdown();
SDL_Quit();
return 0;
}



this is the output:
0x7fffed2f4b98
OVR::DeviceManagerThread - running (ThreadId=0x7f53f352b700).
OVR::DeviceManager - initialized.
ovr ok
*** SensorFusion Startup: TimeSeconds = 1406735779.733282
OVR::Linux::HIDDevice - Opened '/dev/hidraw1'
Manufacturer:'Oculus VR, Inc.' Product:'Tracker DK' Serial#:'8D82318D4855'
OVR::SensorDevice - Closed '/dev/hidraw1'
OVR::Linux::HIDDevice - HID Device Closed '/dev/hidraw1'
OVR::Linux::HIDDevice - HIDShutdown '/dev/hidraw1'
Hello World! 0
pseudo render loop
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
pose(q(0001)vec3(000))pose(q(0001)vec3(000))
[...]


the sensors are not able to be moved at all.
No RepliesBe the first to reply