Forum Discussion
ckoeber
12 years agoHonored Guest
Reading Sensor data with GLM and OpenGL ...
Hello, So I have my application ported to the rift using the SDK and I can read sensor data fine. It's calculating the sensor data and converting it over to GLM that is giving me problems. I...
DoZo1971
12 years agoExplorer
Well, I fill the yaw, pitch, roll directly from the sensor:
Inside l_CurrentCamera, whenever the yaw, pitch, and/or roll is changed (or the position for that matter) I update the ModelView matrix (note I don't use GLM, but my own matrix class):
Then, since the ModelView matrix is always correct I can move forward (for instance) in the direction of what you call the direction vector and just update the position:
Note the hierarchy of camera classes. I've made a clear fundamental distinction between a camera that orbits a fixed viewing point outside of the camera or a camera that orbits itself, like in a FPS game. Both have its uses. The Oculus camera I have implemented is of the latter type (c_CameraOculusRift is a c_CameraQuake is a c_CameraCartesian (is a c_Camera)).
Thanks,
Daniel
void
c_OculusRift::GetYawPitchRoll(float* p_Yaw, float* p_Pitch, float* p_Roll)
{
if (m_Hmd)
{
OVR::Quatf l_Orientation = OVR::Quatf(m_EyePose.Orientation);
l_Orientation.GetEulerAngles<OVR::Axis_Y, OVR::Axis_X, OVR::Axis_Z>(p_Yaw, p_Pitch, p_Roll);
}
else
{
*p_Yaw = 0.0f;
*p_Pitch = 0.0f;
*p_Roll = 0.0f;
}
}
l_CurrentCamera->SetYawPitchRoll(l_Yaw*MY_RADTODEG, l_Pitch*MY_RADTODEG, -l_Roll*MY_RADTODEG);
Inside l_CurrentCamera, whenever the yaw, pitch, and/or roll is changed (or the position for that matter) I update the ModelView matrix (note I don't use GLM, but my own matrix class):
void
c_CameraQuake::CalculateModelView(void)
{
c_Matrix4f l_Matrix; // Auto fill with Identity...
l_Matrix.Rotate(+m_Roll.GetValue(), 0.0f, 0.0f, 1.0f);
l_Matrix.Rotate(-m_Pitch.GetValue(), 1.0f, 0.0f, 0.0f);
l_Matrix.Rotate(-m_Yaw.GetValue(), 0.0f, 1.0f, 0.0f);
if (GetOrientationModeModel()->GetChoice()==e_Zup) l_Matrix.Rotate(-90.0f, 1.0f, 0.0f, 0.0f);
l_Matrix.Translate(-GetPositionModel()->GetX(), -GetPositionModel()->GetY(), -GetPositionModel()->GetZ());
GetModelViewModel()->SetData(l_Matrix);
}
Then, since the ModelView matrix is always correct I can move forward (for instance) in the direction of what you call the direction vector and just update the position:
void
c_CameraCartesian::MoveFront(float p_Distance)
{
c_Matrix3f l_Inverse = GetModelViewModel()->Transpose().ToMatrix3f();
m_Position.AddValue(l_Inverse*c_Vector3f(0.0f, 0.0f, -p_Distance));
}
Note the hierarchy of camera classes. I've made a clear fundamental distinction between a camera that orbits a fixed viewing point outside of the camera or a camera that orbits itself, like in a FPS game. Both have its uses. The Oculus camera I have implemented is of the latter type (c_CameraOculusRift is a c_CameraQuake is a c_CameraCartesian (is a c_Camera)).
Thanks,
Daniel
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device