Forum Discussion

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

One question regarding a piece of code in SDK Doc

Hi, guys, I found there is piece of code in the sdk is kind of confusing to me. here they are:
HMDInfo& hmd = ...;
Matrix4f viewCenter = ...;
// Compute Aspect Ratio. Stereo mode cuts width in half.
float aspectRatio = float(hmd.HResolution * 0.5f) / float(hmd.VResolution);
// Compute Vertical FOV based on distance.
float halfScreenDistance = (hmd.VScreenSize / 2);
float yfov = 2.0f * atan(halfScreenDistance/HMD.EyeToScreenDistance);
// Post-projection viewport coordinates range from (-1.0, 1.0), with the
// center of the left viewport falling at (1/4) of horizontal screen size.
// We need to shift this projection center to match with the lens center.
// We compute this shift in physical units (meters) to correct
// for different screen sizes and then rescale to viewport coordinates.
float viewCenter = hmd.HScreenSize * 0.25f;
float eyeProjectionShift = viewCenter - hmd.LensSeparationDistance*0.5f;
float projectionCenterOffset = 4.0f * eyeProjectionShift / hmd.HScreenSize;
// Projection matrix for the "center eye", which the left/right matrices are based on.
Matrix4f projCenter = Matrix4f::PerspectiveRH(yfov, aspect, 0.3f, 1000.0f);
Matrix4f projLeft = Matrix4f::Translation(projectionCenterOffset, 0, 0) * projCenter;
Matrix4f projRight = Matrix4f::Translation(-projectionCenterOffset, 0, 0) * projCenter;
// View transformation translation in world units.
float halfIPD = hmd.InterpupillaryDistance * 0.5f;
Matrix4f viewLeft = Matrix4f::Translation(halfIPD, 0, 0) * viewCenter;
Matrix4f viewRight= Matrix4f::Translation(-halfIPD, 0, 0) * viewCenter;


Notice the viewCenter is a matrix , but in the doc, one of the lines is doing this : float eyeProjectionShift = viewCenter - hmd.LensSeparationDistance*0.5f;
so, My question is, what should be in place of the viewCenter matrix to make this piece of code work.
Thanks for your help!

1 Reply

  • oh, sorry, NVM.. i was stupid, sorry. :lol: .
    The line right above that line was viewCenter, it just happened to be the same name as the viewCenterMatrix