problem with Culling and Orthogonal camera

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

problem with Culling and Orthogonal camera

Post by Alucard344 »

I have an orthogonal camera and i have some culling problem. if the camera is not orthogonal everything is fine.
So what is happening is, with the orthogonal camera, my object sometime disappear. it seems to happen on orthogonal angle as you can see in the screenshot.

here is how my camera and my scene node are created:

Code: Select all

irr::core::matrix4 matrix;
	matrix.buildProjectionMatrixOrthoLH(width, height, 1.0f, 1000000); 

	m_smgr->getActiveCamera()->setProjectionMatrix(matrix,true);
	m_smgr->getActiveCamera()->setFarValue(1000000);
	m_smgr->getActiveCamera()->setAspectRatio(width/height);

Code: Select all

scene::ISceneNode* cube = m_smgr->addCubeSceneNode(20,m_smgr->getRootSceneNode(),-1,cubePos);
here you see the cube
Image

and here it disappear
Image

this happens for all object, i just did a real simple test.

Does anyone have an idea of what the problem could be ?

Thanks
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

Post by Alucard344 »

i have changed the default culling to this
cube->setAutomaticCulling(scene::EAC_FRUSTUM_BOX);
and now its working perfectly

but i still dont know why this is working but the default is not..
will i get good culling with this method ?
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

At first, I thought maybe you were rotating your camera in the two different screen shots just enough to move the cube out of view. But looking closer, I notice that in the API, ICameraSceneNode::setProjectionMatrix () mentions
Note that the matrix will only stay as set by this method until one of the following Methods are called: setNearValue, setFarValue, setAspectRatio, setFOV.
Those, in turn call "recalculateProjectionMatrix()" which makes a projection matrix out of your Ortho matrix. A frustum box is generally larger than the EAC_BOX (well, actually always for a projection matrix) so I'm guessing your numbers are just barely enough that switching to EAC_FRUSTUM_BOX makes the culling area just large enough to include the node that was being culled before, without distorting the image enough to make it obvious that you've actually got a perspective matrix.

Since orthocams require that you manually build the projection matrix first (before setting them), you shouldn't need to setFarValue() or setAspectRation() anyway. See if striking out the last two lines in your original code works to do what you want.

If not then,...idk :roll:
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

Post by Alucard344 »

unfortunately i only used setFarValue and setAspectRatio at the initialization
i understand i just dont need to use them so i have removed these lines
but it did not fix the problem.

but at least its working good with EAC_FRUSTUM_BOX

thanks anyway for your answer.
Post Reply