Math::Transform Camera::PerspectiveTransform(double aFov, double n, double f, uint32_t xDim, uint32_t yDim){ double x = xDim; double y = yDim; // Normalized screen dimensions double aspectRatio = y / x; Math::Transform s = Math::Transform::Scaling(2./x, -2./y, 1.); s *= Math::Transform::Scaling(1., aspectRatio, 1.); s *= Math::Transform::Translation(-x/2., -y/2., 0); // Perspective transform double scale = 1. / tan(M_PI*aFov/180./2.); Math::Transform pers = Math::Transform::Scaling(scale, scale, 1.); double m = f / (f - n); Eigen::Matrix4d t; t << 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, m,-n*m, 0, 0, 1, 0; pers *= Math::Transform(t); return pers.Inverse() * s; }