HamsterofDeath

01-26-2003, 09:22 AM

here's my ultra-optimized frustum-culling algorithm :

the basic idea is that you assume that all visible objects are in a cone. you are at the top of it.

the calculation :

if an object has to be drawn depends on its distance to the cone's middle-line. to calculate this, you need the shortest vector from this object to the middle-line of the cone (the vector from top to bottom). lets name it : "D".

add this vector to the objects position. you'll get a point on the middle-line. the distance between this point and he viewer is "D2".

assuming the fov is 90 degrees, you need only to draw objects if their D is smaller or equal to their D2.

advantages : very simlple, very fast.

to get the distance , use this function :

p is the point, l[0] and l[1] are to points on the middle-line.

public static Verticle vektorPunktStrecke(Verticle p, Verticle[] l)

{

float u = ( (((p.getX()-l[0].getX() )*( l[1].getX()-l[0].getX()) )+

((p.getY()-l[0].getY())*(l[1].getY()-l[0].getY()))+

((p.getZ()-l[0].getZ())*(l[1].getZ()-l[0].getZ())))

/

(float)Math.pow(getLength(getVectorBetween(l)),2)) ;

Verticle newP = new Verticle(l[0].getX()-u*getVectorBetween(l).getX(),

l[0].getY()-u*getVectorBetween(l).getY(),

l[0].getZ()-u*getVectorBetween(l).getZ());

the function was not written for this problem so it can be optimizied...

what do you think of my idea ?

the basic idea is that you assume that all visible objects are in a cone. you are at the top of it.

the calculation :

if an object has to be drawn depends on its distance to the cone's middle-line. to calculate this, you need the shortest vector from this object to the middle-line of the cone (the vector from top to bottom). lets name it : "D".

add this vector to the objects position. you'll get a point on the middle-line. the distance between this point and he viewer is "D2".

assuming the fov is 90 degrees, you need only to draw objects if their D is smaller or equal to their D2.

advantages : very simlple, very fast.

to get the distance , use this function :

p is the point, l[0] and l[1] are to points on the middle-line.

public static Verticle vektorPunktStrecke(Verticle p, Verticle[] l)

{

float u = ( (((p.getX()-l[0].getX() )*( l[1].getX()-l[0].getX()) )+

((p.getY()-l[0].getY())*(l[1].getY()-l[0].getY()))+

((p.getZ()-l[0].getZ())*(l[1].getZ()-l[0].getZ())))

/

(float)Math.pow(getLength(getVectorBetween(l)),2)) ;

Verticle newP = new Verticle(l[0].getX()-u*getVectorBetween(l).getX(),

l[0].getY()-u*getVectorBetween(l).getY(),

l[0].getZ()-u*getVectorBetween(l).getZ());

the function was not written for this problem so it can be optimizied...

what do you think of my idea ?