Environment: windows 7 64 bit, c++ visual studio 2012, no clr, opengl driver.
This is perhaps a stupid question but It's not so clear to me.
here is an explanation with all the calculation for how to implement perspective projection in opengl:
http://www.songho.ca/opengl/gl_projectionmatrix.html
As part of my work I implemented the projection matrix
as songho suggested (I need to do so cause I use irrlicht inside another framework).
I set my camera node to my new projection matrix and... surprise.... all my models are gone.
A quick look at irrlicht implementation revealed my problem:
Code: Select all
// Builds a right-handed perspective projection matrix based on a field of view
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovRH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar)
{
const f64 h = reciprocal(tan(fieldOfViewRadians*0.5));
_IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
const T w = static_cast<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/(zNear-zFar)); // DirectX version
// M[10] = (T)(zFar+zNear/(zNear-zFar)); // OpenGL version
M[11] = -1;
M[12] = 0;
M[13] = 0;
M[14] = (T)(zNear*zFar/(zNear-zFar)); // DirectX version
// M[14] = (T)(2.0f*zNear*zFar/(zNear-zFar)); // OpenGL version
M[15] = 0;
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
}
I'm using the opengl driver so I assumed the settings suppose to be in opengl....
So the link above explains to me why opengl projection works, what I don't understand is why this projection works?
(is there a directX equivelent to songho explenation?)
Thanks