Is this the right perspective FOV matrix?

I have a promising FOV, but during rotation it does not look โ€œrightโ€ - all objects intersect faster than closer objects, transferring them in the middle of the screen.

So: Is that right? Using the right coordinates, if that matters?

public static Matrix4x4 PerspectiveFOV(float fov, float aspect, float near, float far) { float yScale = 1.0F / (float)Math.Tan(fov / 2); float xScale = yScale / aspect; float farmnear = far - near; return new Matrix4x4( xScale, 0, 0, 0, 0, yScale, 0, 0, 0, 0, far / (farmnear), 1, 0, 0, -near * (far / (farmnear)), 1 ); } 

Thanks.

+4
source share
2 answers

I see a couple of problems. First, the argument tan () must be converted from degrees to radians.

Secondly, the formula for perspective projection in OpenGL is slightly different from yours. As stated here , it uses the โ€œnearโ€ in the denominator instead of your โ€œfarโ€. Numerators are also different. Changing your function a bit and translating it from Java to C, I created a projection matrix identical to the one specified by gluPerspective (), with the following:

  static void my_PerspectiveFOV (double fov, double aspect, double near, double far, double * mret) {
     double D2R = M_PI / 180.0;
     double yScale = 1.0 / tan (D2R * fov / 2);
     double xScale = yScale / aspect;
     double nearmfar = near - far;
     double m [] = {
         xScale, 0, 0, 0,
         0, yScale, 0, 0,
         0, 0, (far + near) / nearmfar, -1,
         0, 0, 2 * far * near / nearmfar, 0 
     };
     geom_matrix4_copy (m, mret);
 }
+6
source

For issues like this, I would suggest excellent resources: https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix This really goes into the details of the projection matrix. These are more tutorials on the subject of camera, designing camera beams, etc. You will need to dig a little.

+3
source

All Articles