Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualL. Spiro

Posted 11 June 2013 - 06:20 PM

I don’t know the Irrlicht API but there is no way to accomplish what you want with that method; it automatically centers the projection.
Most API’s would give you an “offset” version of the same method, but apparently Irrlicht does not.
 
So you have to make one yourself.
Here is the code that would be plug-and-play for their matrix library:
     // Builds a customized, right-handed orthographic projection matrix.
     template <class T>
     inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixOrthoOffCenterRH(
             f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar)
     {
         T width = (T)(right-left);
         T height = (T)(top-bottom);
         _IRR_DEBUG_BREAK_IF(width==0.f); //divide by zero
         _IRR_DEBUG_BREAK_IF(height==0.f); //divide by zero
         _IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero

         M[0] = (T)(2/width);
         M[1] = 0;
         M[2] = 0;
         M[3] = 0;
 
         M[4] = 0;
         M[5] = (T)(2/height);
         M[6] = 0;
         M[7] = 0;
 
         M[8] = 0;
         M[9] = 0;
         M[10] = (T)(1/(zNear-zFar));
         M[11] = 0;
 
         M[12] = (T)((left+right)/(left-right));
         M[13] = (T)((top+bottom)/(bottom-top));
         M[14] = (T)(zNear/(zNear-zFar));
         M[15] = 1;
 
 #if defined ( USE_MATRIX_TEST )
         definitelyIdentityMatrix=false;
 #endif
         return *this;
     }
Their original code can be found here:
http://irrlicht.sourceforge.net/docu/matrix4_8h_source.html
buildProjectionMatrixOrthoRH() is defined on line 01639, and I based my version off that. Both are right-handed and row-major.



L. Spiro

#2L. Spiro

Posted 11 June 2013 - 06:17 PM

I don’t know the Irrlicht API but there is no way to accomplish what you want with that method; it automatically centers the projection.
Most API’s would give you an “offset” version of the same method, but apparently Irrlicht does not.
 
So you have to make one yourself.
Here is the code that would be plug-and-play for their matrix library:
     // Builds a customized, right-handed orthographic projection matrix.
     template <class T>
     inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixOrthoOffCenterRH(
             f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar)
     {
         f32 width = right-left;
         f32 height = top-bottom;
         _IRR_DEBUG_BREAK_IF(width==0.f); //divide by zero
         _IRR_DEBUG_BREAK_IF(height==0.f); //divide by zero
         _IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero

         M[0] = (T)(2/width);
         M[1] = 0;
         M[2] = 0;
         M[3] = 0;
 
         M[4] = 0;
         M[5] = (T)(2/height);
         M[6] = 0;
         M[7] = 0;
 
         M[8] = 0;
         M[9] = 0;
         M[10] = (T)(1/(zNear-zFar));
         M[11] = 0;
 
         M[12] = (left+right)/(left-right);
         M[13] = (top+bottom)/(bottom-top);
         M[14] = (T)(zNear/(zNear-zFar));
         M[15] = 1;
 
 #if defined ( USE_MATRIX_TEST )
         definitelyIdentityMatrix=false;
 #endif
         return *this;
     }
L. Spiro

#1L. Spiro

Posted 11 June 2013 - 06:16 PM

I don’t know the Irrlicht API but there is no way to accomplish what you want with that method; it automatically centers the projection.
Most API’s would give you an “offset” version of the same method, but apparently Irrlicht does not.
 
So you have to make one yourself.
Here is the code that would be plug-and-play for their matrix library:
     // Builds a customized, right-handed orthographic projection matrix.
     template <class T>
     inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixOrthoOffCenterRH(
             f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar)
     {
         f32 width = right-left;
         f32 height = top-bottom;
         _IRR_DEBUG_BREAK_IF(width==0.f); //divide by zero
         _IRR_DEBUG_BREAK_IF(top-bottom==0.f); //divide by zero
         _IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero

         M[0] = (T)(2/width);
         M[1] = 0;
         M[2] = 0;
         M[3] = 0;
 
         M[4] = 0;
         M[5] = (T)(2/height);
         M[6] = 0;
         M[7] = 0;
 
         M[8] = 0;
         M[9] = 0;
         M[10] = (T)(1/(zNear-zFar));
         M[11] = 0;
 
         M[12] = (left+right)/(left-right);
         M[13] = (top+bottom)/(bottom-top);
         M[14] = (T)(zNear/(zNear-zFar));
         M[15] = 1;
 
 #if defined ( USE_MATRIX_TEST )
         definitelyIdentityMatrix=false;
 #endif
         return *this;
     }
L. Spiro

PARTNERS