[Plib-users] R: How to clip an area
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2007-10-15 11:55:02
|
Rather than reasoning in terms of clipping, it seems to me that you have = to setup an off-axis projection (http://www.opengl.org/resources/faq/technical/transformations.htm#tran00= 80) . 135=B0 __________________ \45=B0 \ 45=B0 /45=B0 / \ \ / / \ \ / / \ \/ / \/ The left- and right-most are off-axis projections (to be set up through OpenGL's glFrustum or Plib's ssgSetFrustum), the center one is on-axis = (i.e. the classic one set up through OpenGL's gluProjection or Plib's = ssgSetFOV). So the sequence of operation would be the following: glViewport( 0, 0, w/3, h ); ssgSetFrustum( <leftmost frustum params> ); ssgCullAndDraw(...); glViewport( w/3, 0, w/3, h ); ssgSetFrustum( <center frustum params> ); ssgCullAndDraw(...); glViewport( 2*w/3, 0, w/3, h ); ssgSetFrustum( <rightmost frustum params> ); ssgCullAndDraw(...); In order to calculate proper arguments to ssgSetFrustum( left, right, bottom, top, zNear, zFar) as the given FoV partitioning you could search = for keywords glfrustum and off-axis projection, or tiled projection. If you prefer, just use to code below. You nave to find how to split you 135=B0 FoV screen into 3x45=B0 screens (i.e. the four corners of each = projection surface) in terms of (ul,ur,ll,lr) corner positions - and set eyepos as = to comprise the 135=B0 screen. It's not important where the coordinate = system origin is wrt screen corner and eyepos, nor the units, but, for = simplicity, you could just put the coordinate system origin at the center of the = center screen and find (ul,ur,ll,lr) and eyepos accordingly, or put it at = eyepos (eyepos (0,0,0)) and find (ul,ur,ll,lr) accordingly: ul ur +---+------+---+ | | | | +...+......+...+ |\ |\ /| /| +--\+-\--/-+/--+ ll lr\ \/ / \/ eyepos enum {SC_UL, SC_UR, SC_LL, SC_LR}; // enum for specifying screen corner // (Ux: upper, Lx: lower, xL: left, = xR: right) void calcOffAxisView( // input args sgVec3 screen[4], // the four screen corner positions (x,y,z), // fill entries SC_UL, SC_UR, SC_LL, and SC_LR sgVec3 eyepos, // eye position (x,y,z) // screen and eyepos have to be in the same coordinate system // (x+ right, y+ up, z+ out of the screen) float near_clip, float far_clip, // near and far clipping planes // output args float *left, float *right, float *bottom, float *top // first six args to ssgSetFrustum, // the last = two are near_clip and far_clip ) { sgVec3 eyeToScreen, xProj, yProj, zProj; float width, height, dist; sgVec3 eyePos; sgCopyVec3( eyePos, eyepos ); // Calculate vector from eye to screen origin (lower left corner) sgSubVec3(eyeToScreen, eyePos, screen[SC_LL]); // Calculate vectors from bottom left corner of screen that form // the screen coordinate frame sgSubVec3(xProj, screen[SC_LR], screen[SC_LL]); width =3D sgLengthVec3(xProj); sgScaleVec3(xProj, SG_ONE / width); sgSubVec3(yProj, screen[SC_UL], screen[SC_LL]); height =3D sgLengthVec3(yProj); sgScaleVec3(yProj, SG_ONE / height); sgVectorProductVec3(zProj, xProj, yProj); // Now, specify an off-axis viewing frustum in order to define the // viewing volume with respect to the user's eye position. *left =3D sgScalarProductVec3(eyeToScreen, xProj); *right =3D width - *left; bottom =3D sgScalarProductVec3(eyeToScreen, yProj); *top =3D height - *bottom; dist =3D sgScalarProductVec3(eyeToScreen, zProj); float nc_over_d =3D near_clip / dist; *left *=3D -nc_over_d; *right *=3D nc_over_d; *bottom *=3D -nc_over_d; *top *=3D nc_over_d; } Note that the code above is only valid for the tiling case (i.e. there's = no screen rotation) - for arbitrary positioned screens there's an = additional matrix multiplication to take into account either in the projection or = in the modelview matrix (in this case, its inverse). Greetings - Paolo Leoncini ________________________________ Da: pli...@li... [mailto:pli...@li...] Per conto di swetha = korada Inviato: luned=EC 15 ottobre 2007 10.35 A: pli...@li... Oggetto: [Plib-users] How to clip an area =09 =09 Hi all, =20 I am using plib-1.8.2 version.In that, I have set the horizonital Field Of View(FOV) as 135 degrees.In that I have to render only first 45 degrees area.So I need to clip next 90 degrees.How to achieve this? =20 Hope any one will give reply as soon as possible. =20 Thanks And Regards, swetha. =20 |