only draw visible triangles (or models)

Started by xixi, November 09, 2010, 15:45:56

Previous topic - Next topic



i was asking myself if lwjgl has something to calculate if my triangles that i draw are on screen or not

do anyone know this and if not, how would i calculate that, because my math is not so good.

Thanks in advance


This is something tough to code. It s part of shadow mapping. isn't it? I read about that in the red book, and NeHe tutorial could help.


For this, all you would need to do is see if all 3 corners of the triangle are off the screen.  But it gets complicated trying to figure out what the location of the corners are after rotation, scaling, etc.  Luckily, there is a method for this:  gluProject.  But this can be slow with a lot of triangles, so we're back to math to figure out the points of the 3 vertexes after rotation and scaling.

Personally, I'd just check a bounding box (or circle), as you don't need perfect collision because you're just testing if off screen.

//all >= 0
int x1 = centerTriangleX;
int y1 = centerTriangleY;
int x2 = farthestTriangleXLength;
int y2 = farthestTriangleYLength;

if((x1 + x2) < 0 || (x1 - x2) > width ||
  (y1 + y2) < 0 || (y1 - y2) > height) {
 //off screen
cool story, bro


Ur calculations are generally not correct for ordinary projectional displays. Triangles from within the range depth will Show even at higher x,y coords.


All he said was triangles, so that's all I based my calculation on.  But yes, it would need to be adjusted for depth, but I'm not quite sure if he is even using depth (or rotation for that matter) based on his post...

Of course, the gluProject way would adjust for rotation, scaling, depth, etc.
cool story, bro