Finally got some demo code working! No display yet but at least I got the basic head pose position vector and Eular angles of the orientation dumping to a console…
Visual Studio really makes development a pain in the ass. I tried a few of the Oculus boiler plates and they didn’t really do anything but slow me down while I tried to get them to compile.
But I learned a lot about Visual Studio and CMake in the process so it wasn’t a complete waste of time. As well, at least I’ve got a few code examples to use as I move on to the rendering portion of this.
So, since no one else seems to have built up a good, minimalist Oculus boiler plate example (at least, I haven’t found one yet), I guess I’ll share what I’ve got:
bc(language-cpp).. #include <stdio.h> #include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h> #include <glm/glm.hpp>
// If you don’t include these in the Visual Studio project configs. These need to go before OVR_CAPI.h: #pragma comment(lib, “winmm.lib”) #pragma comment(lib, “Ws2_32.lib”) //#include “OVR_CAPI.h” #include “OVR_CAPI_GL.h” #include “Kernel\OVR_Math.h”
using namespace OVR;
int main(void) { printf(“hello world\n”);
ovr_Initialize(); ovrHmd hmd = ovrHmd_Create(0); if (hmd) { // Get more details about the HMD. ovrSizei resolution = hmd->Resolution; printf(“Resolution: i, i\n”, resolution.h, resolution.w); } // Do something with the HMD. ….
int i = 0; float yaw; float eyePitch; float eyeRoll; while (1) { // Start the sensor which provides the Rift’s pose and motion. ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0); // Query the HMD for the current tracking state. ovrTrackingState ts = ovrHmd_GetTrackingState(hmd, ovr_GetTimeInSeconds()); if (ts.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)) { ovrPosef pose = ts.HeadPose.ThePose; printf(“Pos: f, f, f\t”, pose.Position.x, pose.Position.y, pose.Position.z);
ovrQuatf ori = pose.Orientation;
Quatf OculusRiftOrientation = ori;
OculusRiftOrientation.GetEulerAngles\<OVR::Axis\_X, OVR::Axis\_Y, OVR::Axis\_Z\>(&yaw, &eyePitch, &eyeRoll);
printf("Ori: f, f, f\\n”, yaw, eyePitch, eyeRoll);} else { printf(“No device yet…”); } i += 1; }
ovrHmd_Destroy(hmd); ovr_Shutdown();
system(“pause”);
}
Not really the best example, but it works! I’ll have to do a fair amount of rework to get it to be cross platform but it should be portable… I hope…
