new culling system

A forum to store posts deemed exceptionally wise and useful
Post Reply
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

new culling system

Post by omaremad »

i know this might not be good but i just thought it it out in 10 mins
it is based on some old code i had which was actually used for ai
pretty crazy :lol:

it works on this principle (they diagram is horrible but the code will explain

Image
all of it is in the update loop
any way it starts with this

Code: Select all

core::vector3df pos=camera->getAbsolutePosition();
               core::vector3df selfrot=camera->getRotation();
               core::vector3df targetpos=node->getAbsolutePosition();
               core::vector3df targetrot;
               targetrot=getTargetAngle(pos,targetpos);
               f32 rotadd=targetrot.Y-selfrot.Y;


then the fun part

the 60 value is 0 deg +60
the 300 valueis 360 -60 deg

there fore giving the camera 120 deg of fov if the node is out side that cull it :!:

Code: Select all

if(rotadd>60 & rotadd<300 ){
node->setVisible(true);
}
else
node->setVisible(false);

[code]

it is useful for animated things as the octree node doesnt allow animation


i know it is simple and not complete tell me what u think
bye
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

i only skimmed what u said, so correct me if I'm wrong, but this sounds to me pretty much just like frustum culling. Admittedly irrlicht does lousy frustum culling (uses aabb of frustum instead of culling against actual planes)
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

i dont know how frutsum culling works

but my way ensure that scene node only dissapear if they are not in the fov of the cam

my way probabaly is less resourve consuming

here is a func i missed

Code: Select all

core::vector3df getTargetAngle(core::vector3df v, core::vector3df r) 
{ 
        #define PI		3.14159265358979323846
       //v -position 
       //r -target 

       core::vector3df angle; 
       float x,y,z; 
       x = r.X - v.X; 
       y = r.Y - v.Y; 
       z = r.Z - v.Z; 

       //angle in X-Z plane 
       angle.Y = atan2 (x, z); 
       angle.Y *= (180 / PI); //converting from rad to degrees 
       
       //angle.Y-=90;
       //just making sure angle is somewhere between 0-360 degrees 
       if(angle.Y < 0) angle.Y += 360; 
       if(angle.Y >= 360) angle.Y -= 360; 

       //angle in Y-Z plane while Z and X axes are already rotated around Y 
       float z1 = sqrt(x*x + z*z); 

       angle.X = atan2 (z1, y); 
       angle.X *= (180 / PI); //converting from rad to degrees 
       
       //angle.X -= 90; 
       //just making sure angle is somewhere between 0-360 degrees 
       if(angle.X < 0) angle.X += 360; 
       if(angle.X >= 360) angle.X -= 360; 
       
       
       return angle; 

} 
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

You've got two trigonometric functions and a square root in a function to be executed for every node. Owww. Personally I'd rather take frustum culling (with tests first then more accurate involved tests). If you don't understand frustum culling I suggest you read about it, its pretty much the most basic and essentia lculling technique (IMHO)
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

From what I can see with your code and diagrams, you're only culling based on the horizontal FOV of the camera, what about the vertical FOV and what about near and far clipping?
Image
Post Reply