I think perspective projection matrix used in irr is strange. A standard projection matrix may like :
void matrix4::buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar)
{
(*this)(0,0) = (cos(fieldOfViewRadians/2) * aspectRatio)/ sin(fieldOfViewRadians/2);
(*this)(1,0) = 0;
(*this)(2,0) = 0;
(*this)(3,0) = 0;
(*this)(0,1) = 0;
(*this)(1,1) = cos(fieldOfViewRadians/2) / sin(fieldOfViewRadians/2);
(*this)(2,1) = 0;
(*this)(3,1) = 0;
(*this)(0,2) = 0;
(*this)(1,2) = 0;
(*this)(2,2) = (zFar + zNear)/(zFar-zNear);
(*this)(3,2) = 1;
(*this)(0,3) = 0;
(*this)(1,3) = 0;
(*this)(2,3) = -2*zNear*zFar/(zFar-zNear);
(*this)(3,3) = 0;
}
but in irr that is:
void matrix4::buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar)
{
f32 h = (f32)(cos(fieldOfViewRadians/2) / sin(fieldOfViewRadians/2));
f32 w = h / aspectRatio;
(*this)(0,0) = 2*zNear/w;
(*this)(1,0) = 0;
(*this)(2,0) = 0;
(*this)(3,0) = 0;
(*this)(0,1) = 0;
(*this)(1,1) = 2*zNear/h;
(*this)(2,1) = 0;
(*this)(3,1) = 0;
(*this)(0,2) = 0;
(*this)(1,2) = 0;
(*this)(2,2) = zFar/(zFar-zNear);
(*this)(3,2) = 1;
(*this)(0,3) = 0;
(*this)(1,3) = 0;
(*this)(2,3) = zNear*zFar/(zNear-zFar);
(*this)(3,3) = 0;
}
but it seem work with matrix above. Is there any one can tell me the background acknowledge of the matrix of irr?
Strange projection matrix
While the other thread does suggest improvements, it's still not great. The original poster had the right idea, using the correct formula. If you want an Irrlicht friendly implementation of this, try here:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=72425
Cheers
http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=72425
Cheers
Harvey Gilpin, code monkey