Find SceneNodes By Frustum

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
amin
Posts: 6
Joined: Tue Aug 30, 2011 11:31 am

Find SceneNodes By Frustum

Post by amin »

Hi

How can i get an array of sceneNodes witch are inside the Frustum of a camera ?

thanks
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Find SceneNodes By Frustum

Post by Mel »

create an array and traverse the scene from the root. call the method "isTrulyVisible()" for each scene node you find, and if it is visible, add it to your array. Just make sure that every node is linked to the root scene node somehow.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
amin
Posts: 6
Joined: Tue Aug 30, 2011 11:31 am

Re: Find SceneNodes By Frustum

Post by amin »

isTrulyVisible() doesnt work , i debug getPrimitiveCountDrawn() and it goes down to 0 when node is behind camera but isTrulyVisible() still returns True ...

i also have another question , it seems that frustum culling is dependent on camera's far clipping value and not the actual frustum, see this picture :
http://s3.picofile.com/file/7537488274/awegwg.png

is it possible to make frustum culling use the actual camera's frustum ?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Find SceneNodes By Frustum

Post by CuteAlien »

ISceneNode::setAutomaticCulling can set different culling types: http://irrlicht.sourceforge.net/docu/na ... dc77fd9cce

And frustum far-plane is camera far-plane, there is no difference.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
amin
Posts: 6
Joined: Tue Aug 30, 2011 11:31 am

Re: Find SceneNodes By Frustum

Post by amin »

thanks CuteAlien

"EAC_FRUSTUM_BOX" was what i looking for :D

but here is another not so important problem ( or mabye bug )
i added for example 10 meshSceneNode each has 20 triangle and set all of them to EAC_FRUSTUM_BOX ...
getPrimitiveCountDrawn() always show 20 primitive is rendering even if non of them are inside the frustum , i think the first meshSceneNode will never be culled ... however for the other 9 it works well.

i still have problem with my first question :(
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Find SceneNodes By Frustum

Post by CuteAlien »

It's checking the boundingbox of meshes against the frustum - not the triangles (that would be too expensive).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
amin
Posts: 6
Joined: Tue Aug 30, 2011 11:31 am

Re: Find SceneNodes By Frustum

Post by amin »

yes i mean bounding box and not triangles , all sceneNodes ( bounding boxes ) are completely outside the frustum ... but getPrimitiveCountDrawn() shows 20 primitive ( one of those meshSceneNodes ) is rendering ...
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Find SceneNodes By Frustum

Post by CuteAlien »

That shouldn't happen, can't really say much without a test-case.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
amin
Posts: 6
Joined: Tue Aug 30, 2011 11:31 am

Re: Find SceneNodes By Frustum

Post by amin »

I think sceneNodes with scale around 100 and above have problem with frustum culling

Code: Select all

#include <irrlicht.h>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
 
int main()
{
 
    IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<u32>(800,600),32,false,false,false);
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* scene = device->getSceneManager();
 
    ICameraSceneNode* camera = scene->addCameraSceneNodeFPS(0 , 100.0 , 20.0);
    camera->setFarValue(10000);
 
    for (int i = 0; i < 10 ; ++i)
    {
        IMeshSceneNode* node = scene->addCubeSceneNode(2.0);
        node->setPosition(vector3df(i * 500.0 , 0.0 , 500.0));
        node->setAutomaticCulling(EAC_FRUSTUM_BOX);
        
        node->setScale(vector3df(100 ,100 ,100));
    }
 
    while (device->run())
    {
 
        stringw primitiveCount(L"Primitive Count = ");
        primitiveCount += driver->getPrimitiveCountDrawn();
        device->setWindowCaption(primitiveCount.c_str());
 
        driver->beginScene(true,true,SColor(255,128,64,255));
        scene->drawAll();
        driver->endScene();
    }
 
    device->drop();
 
    return 0;
}
when i set scale around 50 and below everything is OK ...
jaworekplay
Posts: 36
Joined: Mon Jan 23, 2012 11:14 pm
Location: Lancs, UK

Re: Find SceneNodes By Frustum

Post by jaworekplay »

In my opinion if you decrease the placement from 500.0 to 5.0 would help,cause 1x500 = 500, 2x500 = 1000, 3 x 500 = 1500 etc... you get the picture
EDIT: sorry completely misunderstuded the question. ^_^
Last edited by jaworekplay on Wed Dec 19, 2012 4:10 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Find SceneNodes By Frustum

Post by CuteAlien »

Thanks for the testcase. It's definitely a bug - and at least for that case it would even be easy to fix.
In CMatrix4<T>::getInverse(CMatrix4<T>& out) in line 1329 the iszero check needs to be replaced by:

Code: Select all

 
if( d == 0 )
    return false;
 
From what I can see that looks correct and would make more sense - and it would fix the problem here.

There's just one problem now... before version 362 it looked exactly like that and then was changed. Unfortunately no commit message so I've got no idea why that was done. And the code used there is some asm code which I don't understand, so no idea if it maybe caused crashes with certain values or something *sigh*.

I would just revert that change, but moving it to bugforum now in case anyone else has some feedback before I mess something up. And I try if I can reach the author of that change (not certain if he's still around...).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Find SceneNodes By Frustum

Post by CuteAlien »

Ok, original patch writer is still reading the forum and gave me permission to change this stuff :-) Check-out newest irrlicht svn trunk version (r4343), it will work there.

Thanks for reporting.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply