Help with rotation and gluLookAt()
Hello. I'm messing around with the oculus in c++ with opengl 1.x or 2.x (whatevs win7 ships with). I've been able to muscle through the rendering items, and I can view my test scene just fine. However, I'm pretty lost with the rotation stuffs. Euler angles and quaternions are a new concept for me.
So the surrounding code for my camera is roughly this:
My first assumption was that the Pitch, Yaw, and Roll independently range from -Pi (pitch down, yaw left, roll left) to Pi (pitch up, yaw right, roll right). It works well until Yaw reaches Pi/2 or -Pi/2...when the pitch begins to go crazy... It seems like at that point, the oculus treats the orientation as if it's upside down or something.
My second approach was to try using the Orientation.x/y/z values. They seemed to range from roughly -1 to 1, and I saw somewhere that this could be the angle calculation sin( theta / 2 ). So i tried the following:
I've tried both approaches above using eye angles-only, head angles-only, and eye angles + head angles. There always seems to be a weird issue at yaw == +- 90 degrees.
Can someone help me to understand where I'm derailing?
Thanks very much!!
So the surrounding code for my camera is roughly this:
void Camera( int i ) //i is the eye :)
{
ovrTrackingState TrackingState = ovrHmd_GetTrackingState( Hmd, ovr_GetTimeInSeconds() );
if( TrackingState.StatusFlags & ovrStatus_OrientationTracked )
{
ovrPosef pos = ovrHmd_GetEyePose( Hmd, ovrEyeType(i) );
float headPitch = 0.0f, headYaw = 0.0f, headRoll = 0.0f, pitch = 0.0f, yaw = 0.0f, roll = 0.0f;
OVR::Quatf headOrientation = TrackingState.HeadPose.ThePose.Orientation;
headOrientation.GetEulerAngles <OVR::Axis_X, OVR::Axis_Y, OVR::Axis_Z> ( &headPitch, &headYaw, &headRoll );
OVR::Quatf orientation = pos.Orientation;
orientation.GetEulerAngles< OVR::Axis_X, OVR::Axis_Y, OVR::Axis_Z >( &pitch, &yaw, &roll );
pitch += headPitch;
yaw += headYaw;
roll += headRoll;
GLfloat lx = sin( -yaw ) * cos( pitch ),
ly = cos( yaw ) * sin( pitch ),
lz = -1 * cos( pitch ) * cos( yaw ),
ux = cos( pitch ) * sin( -roll ),
uy = cos( pitch ) * cos( roll ),
uz = sin( pitch ) * cos( roll );
static GLfloat x = 0, y = 0, z = 0;
if( TrackingState.StatusFlags & ovrStatus_PositionTracked )
{
x = pos.Position.x;
y = pos.Position.y;
z = pos.Position.z;
}
gluLookAt( x, y, z,
x+lx, y+ly, z+lz,
ux, uy, uz );
}
}
My first assumption was that the Pitch, Yaw, and Roll independently range from -Pi (pitch down, yaw left, roll left) to Pi (pitch up, yaw right, roll right). It works well until Yaw reaches Pi/2 or -Pi/2...when the pitch begins to go crazy... It seems like at that point, the oculus treats the orientation as if it's upside down or something.
My second approach was to try using the Orientation.x/y/z values. They seemed to range from roughly -1 to 1, and I saw somewhere that this could be the angle calculation sin( theta / 2 ). So i tried the following:
void Camera( int i )
{
ovrTrackingState TrackingState = ovrHmd_GetTrackingState( Hmd, ovr_GetTimeInSeconds() );
if( TrackingState.StatusFlags & ovrStatus_OrientationTracked )
{
ovrPosef pos = ovrHmd_GetEyePose( Hmd, ovrEyeType(i) );
float headPitch = TrackingState.HeadPose.ThePose.Orientation.x,
headYaw = TrackingState.HeadPose.ThePose.Orientation.y,
headRoll = TrackingState.HeadPose.ThePose.Orientation.z;
float pitch = pos.Orientation.x,
yaw = pos.Orientation.y,
roll = pos.Orientation.z;
pitch += headPitch;
yaw += headYaw;
roll += headRoll;
GLfloat lx = -yaw * cos(asin(pitch)),
ly = cos(asin(yaw)) * pitch,
lz = -1 * cos(asin(pitch)) * cos(asin(yaw)),
ux = cos(asin(pitch)) * -roll,
uy = cos(asin(pitch)) * cos(asin(roll)),
uz = pitch * cos(asin(roll));
static GLfloat x = 0,
y = 0,
z = 0;
if( TrackingState.StatusFlags & ovrStatus_PositionTracked )
{
x = pos.Position.x;
y = pos.Position.y;
z = pos.Position.z;
}
gluLookAt( x, y, z,
x+lx, y+ly, z+lz,
ux, uy, uz );
}
}
I've tried both approaches above using eye angles-only, head angles-only, and eye angles + head angles. There always seems to be a weird issue at yaw == +- 90 degrees.
Can someone help me to understand where I'm derailing?
Thanks very much!!
