Using of right-handed projection matrix in Irrlicht

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Egret
Posts: 2
Joined: Mon Nov 26, 2012 9:06 am

Using of right-handed projection matrix in Irrlicht

Post by Egret »

Hi,
Irrlicht by default uses left-handed projection matrix, while I need to switch to the right-handed one.

But if I try to create a RH projection matrix using the following code snippet:
// here goes creation and initialization of the camera

Code: Select all

irr::core::matrix4 projMatrix;
projMatrix.buildProjectionMatrixPerspectiveFovRH(camera->getFOV(), camera->getAspectRatio(), camera->getNearValue(), camera->getFarValue());
camera->setProjectionMatrix(projMatrix);
the engine doesn't render anything.
With buildProjectionMatrixPerspectiveFovLH() the code works fine.

Other people tried to solve similar issues, but with no success:
http://irrlicht.sourceforge.net/forum/v ... hp?t=35809
http://irrlicht.sourceforge.net/forum/v ... hp?t=42330
http://www.gamedev.net/topic/575142-rig ... projection
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Using of right-handed projection matrix in Irrlicht

Post by hybrid »

If you render LH meshes with RH projection matrix, the meshes are likewise inside-out and will be backface culled. So maybe as a first try, disable all culling and/or make sure you use RH mesh data as well.
Egret
Posts: 2
Joined: Mon Nov 26, 2012 9:06 am

Re: Using of right-handed projection matrix in Irrlicht

Post by Egret »

Thank you for the idea, hybrid.
Unfortunately disabling of backface culling doesn't change the situation. I've already checked math of buildProjectionMatrixPerspectiveFovRH() - the function produces right projection matrix.
EldritchCheese
Posts: 4
Joined: Mon Dec 08, 2014 9:04 pm

Re: Using of right-handed projection matrix in Irrlicht

Post by EldritchCheese »

I know that this is an old thread, but I ran into the same issue, and as this is the top google result for "irrlicht right handed", I wanted to give my solution to the problem.

buildProjectionMatrixPerspectiveFovRH changes the sign on the z-coordinate, so that positive z is behind the camera and negative z is in front. However, when constructing the view matrix with ICameraSceneNode::setLookAt, it is assumed that positive z will always be in front of the camera. Therefore, when using buildProjectionMatrixPerspectiveFovRH, I saw an empty window, as did the OP, because the camera was pointed in the wrong direction.

Instead of changing the sign on the z-coordinate, I change the sign on the x-coordinate. This converts to a right-handed coordinate system, without invalidating setLookAt.

Code: Select all

 
irr::core::matrix4 matproj = camera->getProjectionMatrix();
matproj(0,0) *= -1;
camera->setProjectionMatrix(matproj);
 
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Using of right-handed projection matrix in Irrlicht

Post by hendu »

I can't find a function called setLookAt anywhere in SVN nor in 1.7. Are you using some old or modified version?
EldritchCheese
Posts: 4
Joined: Mon Dec 08, 2014 9:04 pm

Re: Using of right-handed projection matrix in Irrlicht

Post by EldritchCheese »

Whoops, that was my bad. The function is ICameraSceneNode::setTarget, not ICameraSceneNode::setLookAt.
Post Reply