0

I`m trying to use a GetPerspevtive function to check if the Perspective function returns the expected answer.

My Perspective is that:

Mat4<Real> Perspective(Real fovy, Real aspect, Real zNear, Real zFar)
{
        Real Cotan_fovy = (Real)1.0/Tan(fovy * (Real)0.5);

        Mat4<Real> r;
        r.SetRow(0, Cotan_fovy/aspect,  (Real)0.0,                         (Real)0.0,                                 (Real)0.0);
        r.SetRow(1,         (Real)0.0, Cotan_fovy,                         (Real)0.0,                                 (Real)0.0);
        r.SetRow(2,         (Real)0.0,  (Real)0.0,  -(zFar + zNear) / (zFar - zNear), ((Real)2.0* zFar * zNear )/ (zNear - zFar));
        r.SetRow(3,         (Real)0.0,  (Real)0.0,                        (Real)-1.0,                                 (Real)0.0);
        return r;
}

And that is my GetPerspective:

void GetPerspective(const Mat4<Real>& m, Real& fovy, Real& aspect, Real& zNear, Real& zFar)
{
    Real right = (Real)0.0;
    Real left = (Real)0.0;
    Real top = (Real)0.0;
    Real bottom = (Real)0.0;
    GetFrustum(m, left, right, bottom, top, zNear, zFar);

    fovy = Atan(top / zNear) - Atan(bottom / zNear);
    aspect = (right - left) / (top - bottom);
}

The problem is: don`t matter what is my input matrix, my GetPerspective always set -1 in the position (2,3)

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
absentia
  • 142
  • 2
  • 13

0 Answers0