buildProjectionMatrixOrthoRH() is correct?

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Kadota Mamoru
Posts: 1
Joined: Tue Nov 03, 2009 6:16 pm

buildProjectionMatrixOrthoRH() is correct?

Post by Kadota Mamoru »

Hi.

I'm using irr::core::CMatrix4<T>::buildProjectionMatrixOrtho().

Code: Select all

	void restoreCameraOrtho(f32 width, f32 height)
	{
		// cameraOrtho - Restore orthogonal matrix
		core::matrix4 matprj;
		matprj.buildProjectionMatrixOrthoRH(
			width, height,
			1.0f, 3000.0f);
		cameraOrtho->setProjectionMatrix(matprj, true);
	}
But it did not work well. All objects(Mesh, line etc) are not drawn at all.
I tried to see Irrlicht implementation, then I found some suspicious codes.
(Irrlicht : version 1.6)

Code: Select all

	// Builds a right-handed orthogonal projection matrix.
	template <class T>
	inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixOrthoRH(
			f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar)
	{
		_IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero
		_IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero
		_IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
		M[0] = (T)(2/widthOfViewVolume);
		M[1] = 0;
		M[2] = 0;
		M[3] = 0;

		M[4] = 0;
		M[5] = (T)(2/heightOfViewVolume);
		M[6] = 0;
		M[7] = 0;

		M[8] = 0;
		M[9] = 0;
		M[10] = (T)(1/(zNear-zFar));
		M[11] = 0;

		M[12] = 0;
		M[13] = 0;
		M[14] = (T)(zNear/(zNear-zFar));
		M[15] = -1;

#if defined ( USE_MATRIX_TEST )
		definitelyIdentityMatrix=false;
#endif
		return *this;
	}
In this code, matrix's final element that is M[15], is set "-1" value.
If this generated matrix multiply vertex, resulted vertex's "x", "y", "z" values mean always negative. because resulted vertex's "w" is negative (if input vertex's "w" is positive).

And I think it is the problem's cause.
but I don't have conviction...
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I think you should use the Left Hand version.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
zucka
Posts: 1
Joined: Tue May 09, 2006 6:02 am
Location: Japan

Post by zucka »

I met same trouble by buildProjectionMatrixOrthoRH().
You should change W[15].

Code: Select all

   void restoreCameraOrtho(f32 width, f32 height)
   {
      // cameraOrtho - Restore orthogonal matrix
      core::matrix4 matprj;
      matprj.buildProjectionMatrixOrthoRH(
         width, height, 1.0f, 3000.0f);

      //M[15] change .
      matprj(3,3) = 1;

      cameraOrtho->setProjectionMatrix(matprj, true);
   } 
Post Reply