virtual void onKey(int key, int scancode, int action, int mods) {
    if (GLFW_PRESS != action) {
      return;
    }

    switch (key) {
    case GLFW_KEY_R:
      ovrSensorFusion.Reset();
      return;
    case GLFW_KEY_UP:
      ovrSensorFusion.SetPrediction(ovrSensorFusion.GetPredictionDelta() * 1.5f, true);
      return;
    case GLFW_KEY_DOWN:
      ovrSensorFusion.SetPrediction(ovrSensorFusion.GetPredictionDelta() / 1.5f, true);
      return;
    }
    GlfwApp::onKey(key, scancode, action, mods);
  }
Esempio n. 2
0
void initRift() {
  OVR::System::Init(OVR::Log::ConfigureDefaultLog(OVR::LogMask_All));

  pManager = *OVR::DeviceManager::Create();

  //pManager->SetMessageHandler(this);

  pHMD = *pManager->EnumerateDevices<OVR::HMDDevice>().CreateDevice();

  if (pHMD)
    {
      pSensor = *pHMD->GetSensor();

      InfoLoaded = pHMD->GetDeviceInfo(&Info);

      strncpy(Info.DisplayDeviceName, RiftMonitorName, 32);

      RiftDisplayId = Info.DisplayId;

      EyeDistance = Info.InterpupillaryDistance;
      DistortionK[0] = Info.DistortionK[0];
      DistortionK[1] = Info.DistortionK[1];
      DistortionK[2] = Info.DistortionK[2];
      DistortionK[3] = Info.DistortionK[3];
    }
  else
    {
      pSensor = *pManager->EnumerateDevices<OVR::SensorDevice>().CreateDevice();
    }

  if (pSensor)
    {
      FusionResult.AttachToSensor(pSensor);
      FusionResult.SetPredictionEnabled(true);
      float motionPred = FusionResult.GetPredictionDelta(); // adjust in 0.01 increments
      if(motionPred < 0) motionPred = 0;
      FusionResult.SetPrediction(motionPred);

      if(InfoLoaded) {
	riftConnected = true;

	riftX = Info.DesktopX;
	riftY = Info.DesktopY;

	riftResolutionX = Info.HResolution;
	riftResolutionY = Info.VResolution;
      }
    }

#ifdef WIN32
  getRiftDisplay();
#endif
}
  void draw() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    std::string message = Platform::format(
      "Prediction Delta: %0.2f ms\n",
      sensorFusion.GetPredictionDelta() * 1000.0f);
    renderStringAt(message, -0.9f, 0.9f);

    gl::MatrixStack & mv = gl::Stacks::modelview();
    gl::MatrixStack & pr = gl::Stacks::projection();

    mv.push().rotate(predictedOrientation);
    GlUtils::renderArtificialHorizon();
    mv.pop();

    mv.push().rotate(currentOrientation);
    mv.scale(1.25f);
    GlUtils::renderArtificialHorizon(0.3f);
    mv.pop();
  }
  void draw() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    std::string message = Platform::format(
        "Prediction Delta: %0.2f ms\n",
        ovrSensorFusion.GetPredictionDelta() * 1000.0f);
    renderStringAt(message, -0.9f, 0.9f);

    gl::MatrixStack & mv = gl::Stacks::modelview();
    glm::mat4 glm_mat;

    glm_mat = glm::make_mat4((float*) predicted.M);
    mv.push().transform(glm_mat);
    GlUtils::renderArtificialHorizon();
    mv.pop();

    glm_mat = glm::make_mat4((float*) actual.M);
    mv.push().transform(glm_mat);
    mv.scale(1.25f);
    GlUtils::renderArtificialHorizon(0.3f);
    mv.pop();
  }
void OculusVRSensorData::setData(const OVR::SensorFusion& data, const F32& maxAxisRadius)
{
   // Sensor rotation
   OVR::Quatf orientation;
   if(data.GetPredictionDelta() > 0)
   {
      orientation = data.GetPredictedOrientation();
   }
   else
   {
      orientation = data.GetOrientation();
   }
   OVR::Matrix4f orientMat(orientation);
   OculusVRUtil::convertRotation(orientMat.M, mRot);
   mRotQuat.set(mRot);

   // Sensor rotation in Euler format
   OculusVRUtil::convertRotation(orientation, mRotEuler);

   // Sensor rotation as axis
   OculusVRUtil::calculateAxisRotation(mRot, maxAxisRadius, mRotAxis);

   mDataSet = true;
}