Starting with the important bit:
Is it a bug that the projection matrix built by buildProjectionMatrixPerspectiveFovLH in matrix4.h is very close, but doesn't match the matrix used by directX?
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
It is only different in 1 element, so wouldn't this cause irrlicht's projection matrix to not produce the correct aspect ratio?
More info:
I need to create a camera that matches specific FOV parameters. The ICameraSceneNode documentation for setFOV doesn't state what dimension's FOV is set (horizontal, vertical, diagonal) with the function, though the parameter is called fovy which led me to believe that it is the vertical field of view. However, setting up a scene with objects laid out didn't render as expected given my camera's aspect ratio & fov. It looks like this is just a typo due to pulling the aspectRatio mult out of the trig function when setting up the matrix. Changing the projection matrix to directx's creates the view I expect. If this is not a typo, what is setting the camera FOV setting?
[no bug] Perspective Projection Field of View
[no bug] Perspective Projection Field of View
Last edited by drewbacca on Thu Jul 21, 2011 12:00 pm, edited 1 time in total.
Re: Perspective Projection Field of View
To make things easier to review: here is the irrlicht code:
and changing the w calc to the code below fixed the field of view for me
Code: Select all
const f64 h = reciprocal(tan(fieldOfViewRadians*0.5));
_IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
const T w = (T)(h / aspectRatio);
_IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
M[0] = w;
M[1] = 0;
M[2] = 0;
M[3] = 0;
M[4] = 0;
M[5] = (T)h;
M[6] = 0;
M[7] = 0;
M[8] = 0;
M[9] = 0;
M[10] = (T)(zFar/(zFar-zNear));
M[11] = 1;
M[12] = 0;
M[13] = 0;
M[14] = (T)(-zNear*zFar/(zFar-zNear));
M[15] = 0;
Code: Select all
const f64 w = reciprocal(tan((fieldOfViewRadians*aspectRatio)*0.5));
Re: Perspective Projection Field of View
It depends what you mean by "aspect ratio". You think it is the ratio of the horizontal angle to the vertical angle. The code you quote thinks it is the ratio of the width to the height of the viewport. The latter is normal for the consumer, but you seem to have deeper knowledge.
Re: Perspective Projection Field of View
Ahh... you are right, except for the part about me having a deeper knowledge. I was incorrectly applying the aspect ratio to the field of view. With further looking, the matrix follows exactly what is in msdn after all:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Re: [no bug] Perspective Projection Field of View
Wow! It *is* confusing to change your units in the middle of a parameter block! The engineer who designed that should be ashamed but I don't think MS engineers feel shame!