0
votes

I was trying to get a tiled renderer working (the idea is to render one large view frustum by breaking it down into chunks and rendering individually).

I had code that transforms a standard perspective projection with a viewing angle into left, right, top, and bottom clipping planes that can then be passed into glFrustum.

I was stuck on properly breaking this down.

1
Did libtr not work?genpfault
That was the only reference on the topic I could find, but I was looking for something more general.imallett

1 Answers

0
votes

After several missteps, I produced the following:

//"int  rect[4]" is the pixel rectangle of the original view
//"int rect2[4]" is the pixel subrectangle within rect corresponding to the new view
//"left", "right", "bottom", and "top" are the left, right, bottom, and top clipping
//    planes of the old view, respectively.

float diff_x = right -   left;
float diff_y =   top - bottom;

result_left   = (float)(rect2[0]         ) / (float)(rect[2]) * diff_x  +    left;
result_right  = (float)(rect2[0]+rect2[2]) / (float)(rect[2]) * diff_x  +    left;
result_bottom = (float)(rect2[1]         ) / (float)(rect[3]) * diff_y  +  bottom;
result_top    = (float)(rect2[1]+rect2[3]) / (float)(rect[3]) * diff_y  +  bottom;