[Plib-users] R: How to clip an area
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2007-10-18 07:32:54
|
Now the big picture is clearer. As far as one uses (heading,pitch,roll) Euler angles for camera orientation, summing a fixed heading offset for = the side, 45=B0 walls doesn't work as your experience confirms. On the other = side I discourage you to pursue the clipping approach. (up view) _______ / \ / \ / \ O (isometric view) _______ /| |\ / | | \ / |_______| \ | / \ | | / O \ | |/ /|\ \| _|_ Since here we deal with a rotated screen problem we must take into = account the screen rotation in the calcOffAxisView: sgMat4 mview_wtos_mat; // Rotate the viewing frustum to correspond with the actual // screen orientation (orientation by screen axes, which, in turn, just depend on corners). sgMakeIdentMat4( mview_wtos_mat ); sgSetVec3( mview_wtos_mat[0], xProj[SG_X], yProj[SG_X], zProj[SG_X] ); sgSetVec3( mview_wtos_mat[1], xProj[SG_Y], yProj[SG_Y], zProj[SG_Y] ); sgSetVec3( mview_wtos_mat[2], xProj[SG_Z], yProj[SG_Z], zProj[SG_Z] ); // invert it (the simple way, which is suitable for roto-translation matrices) // this is because we use it as a modelview matrix // so it actually means: counter-rotate the world accordingly sgTransposeNegateMat4( mview_wtos_mat ); Arrange for passing mview_wtos_mat as a further argument to = calcOffAxisView. Then we have to use the general frustum parameters and the rotation = matrix. I'd like to not enter into FG specifics - I can only suggest how I use = them both in my apps. Before ssgCullAndDraw the following function gets called:=20 void setFrustumAndCamera( sgCoord *camera, // app camera in terms of (x,y,z) position and = (h,p,r) Euler angles float left, float right, float bottom, float top, // general frustum params as calculated by calcOffAxisView float near_clip, float far_clip, sgMat4 mview_wtos_mat // screen orientation matrix as calculated by calcOffAxisView ) { sgMat4 mview_mat, cam_mat; ssgSetFrustum( left, right, bottom, top, near_clip, far_clip ); sgCopyMat4( mview_mat, mview_wtos_mat ); // load the screen = orientation matrix sgMakeCoordMat4( cam_mat, camera ); // put camera in its matrix equivalent sgPostMultMat4( mview_mat, cam_mat ); // apply the camera = transformation to the screen orientation=20 ssgSetCamera( mview_mat ); // use it as the actual camera matrix } Third: how to find screen corners for each screen. Again, put a coord reference system at observer point of view (eyepos), so it is (0,0,0). Assuming the observer is on-axis with all screens, for a 45=B0 front = screen its corners are: b (half screen baseline) ___ \ | \ | d (screen distance from obs) \| B =3D d*tg(22,5=B0) =3D> B/d =3D tg(22,5=B0) =3D 0,41421 So we can arbirtarily set b =3D 1, then, for a screen aspect ratio of = 4:3, the front screen lies at d =3D -2,41421 (z+ outside the screen), and hence = we get: UL=3D(-1,.75,-2.41421) UR=3D(1,.75,-2.41421)=20 +--------------------+ | | y | | | | | |____ x | | / | | / | | z | +--------------------+ LL=3D(-1,-.75,-2.41421) LR=3D(1,-.75,-2.41421) For corners of the two side walls just rotate the front screen corners = by -45=B0 and +45=B0 respectively, with no regard of the center of rotation = (since it's (0,0,0) in our case). In case of acceptance of this general model, FG could be extended with support for such general screen definition (i.e. in terms of screen corners), and/or by calculating those from the heading offset as by the simple calculation above. The general screen definition would, = generally, support other multi-screen schema such as tiled screens, even with = partial overlap for edge blending. Greetings - Paolo Leoncini ________________________________ >=20 > Da: pli...@li... > [mailto:pli...@li...] Per conto di swetha=20 > korada > Inviato: marted=EC 16 ottobre 2007 10.45 > A: PLIB Users > Oggetto: Re: [Plib-users] R: How to clip an area > =09 > =09 > Hi, >=20 > We are using flightgear-0.9.4 version. We are running this=20 > flightgear in three pcs and projecting this on big curved 135 deg=20 > screen using three projectors.FOV in three is 45 deg and viewoffset=20 > that is camera view in flightgear is > 45 in left, 0 in center,-45 in right so that it will cover full 135=20 > deg fov. > But problem is when pitch up, terrain is not coming straight( Bow=20 > like image is coming i.e, right and left terrain up and the center is=20 > down). >=20 >=20 > ________________________________ >=20 > Da: swetha korada [mailto:swe...@gm...]=20 > Inviato: mercoled=EC 17 ottobre 2007 6.57 > A: p.l...@ci... > Cc: PLIB Users > Oggetto: Re: [Plib-users] R: How to clip an area > =09 > =09 >=20 >=20 > Hi, >=20 > The concept you have sent is what we are expecting to implement. > =20 > 135=B0 > __________________ > \45=B0 \ 45=B0 /45=B0/ > \ \ / / > \ \ / / > \ \/ / > \/ >=20 > =20 >=20 > We r very new to plib, and we r using plib as a=20 > standerad lib for flightgear. >=20 > In my code glviewport is in reshape funtion of flightgear. i.e., >=20 > glutReshapeFunc( fgReshape ); >=20 > void fgReshape( int width, int height )=20 > { > int view_h; > if ( (!fgGetBool("/sim/virtual-cockpit"))&&=20 > fgPanelVisible() && idle_state =3D=3D 1000 ) > { > view_h =3D (int)(height *=20 > (globals->get_current_panel()->getViewHeight() -=20 > =20 > globals->get_current_panel()->getYOffset()) / 768.0); > }=20 > else=20 > { > view_h =3D height; > } > =20 > glViewport( 0, (GLint)(height - view_h),=20 > (GLint)(width), (GLint)(view_h) );=20 >=20 > fgSetInt("/sim/startup/xsize", width); > fgSetInt("/sim/startup/ysize", height); > guiInitMouse(width, height); >=20 > // for all views > FGViewMgr *viewmgr =3D globals->get_viewmgr(); > if (viewmgr) > { > for ( int i =3D 0; i < viewmgr->size(); ++i )=20 > { > =20 > viewmgr->get_view(i)->set_aspect_ratio((float)view_h / (float)width);=20 > } > ssgSetFOV(=20 > viewmgr->get_current_view()->get_h_fov(),viewmgr->get_current_ > view()->get_v_fov() ); > =20 > #ifdef FG_USE_CLOUDS_3D > sgClouds3d->Resize(=20 > viewmgr->get_current_view()->get_h_fov(),=20 > viewmgr->get_current_view()->get_v_fov() ); > #endif > } > fgHUDReshape(); > =20 > } >=20 > and ssgCullAndDraw(.....) is calling in fgrender=20 > function which is infinitely calling. Now we are > confused to where put the code which you have sent(=20 > below ). only in reshape function we are calling > glviewport. >=20 > glViewport( 0, 0, w/3, h ); > ssgSetFrustum( <leftmost frustum params> ); > ssgCullAndDraw(...); >=20 > glViewport( w/3, 0, w/3, h ); > ssgSetFrustum( <center frustum params> ); > ssgCullAndDraw(...); >=20 > glViewport( 2*w/3, 0, w/3, h ); > ssgSetFrustum( <rightmost frustum params> ); > ssgCullAndDraw(...); >=20 > And Calculation of=20 >=20 > void calcOffAxisView( > // input args > sgVec3 screen[4], // the four screen corner=20 > positions (x,y,z), > // fill entries SC_UL, SC_UR,=20 > SC_LL, and SC_LR > sgVec3 eyepos, // eye position (x,y,z)=20 > // screen and eyepos have to be=20 > in the same coordinate system > // (x+ right, y+ up, z+ out of=20 > the screen) > float near_clip, float far_clip, // near and=20 > far clipping planes=20 > // output args > float *left, float *right, float *bottom, float=20 > *top // first sixargs to ssgSetFrustum, > =20 > // the last twoare near_clip and far_clip=20 > ) >=20 > we are put in ssgContext.cxx. >=20 > Now the problem is where to call this function and what=20 > are the value of sgVec3 screen[4] and > sgVec3 eyepos how to find this. >=20 > we are expecting your reply. > Thankyou very much. >=20 > Regards, > swetha. >=20 >=20 > =20 > =20 > On 10/15/07, Paolo Leoncini <p.l...@ci...=20 > > wrote:=20 >=20 > Rather than reasoning in terms of=20 > clipping, it seems to me that you have to > setup an off-axis projection=20 > =09 > (http://www.opengl.org/resources/faq/technical/transformations > .htm#tran0080=20 > <http://www.opengl.org/resources/faq/technical/transformations > .htm#tran0080> ) > . > =09 > 135=B0 > __________________ > \45=B0 \ 45=B0 /45=B0 /=20 > \ \ / / > \ \ / / > \ \/ / > \/ > =09 > The left- and right-most are off-axis=20 > projections (to be set up through > OpenGL's glFrustum or Plib's=20 > ssgSetFrustum), the center one is on-axis ( i.e. > the classic one set up through OpenGL's=20 > gluProjection or Plib's ssgSetFOV). > =09 > So the sequence of operation would be=20 > the following: > =09 > glViewport( 0, 0, w/3, h ); > ssgSetFrustum( <leftmost frustum params> );=20 > ssgCullAndDraw(...); > =09 > glViewport( w/3, 0, w/3, h ); > ssgSetFrustum( <center frustum params> ); > ssgCullAndDraw(...); > =09 > glViewport( 2*w/3, 0, w/3, h ); > ssgSetFrustum( <rightmost frustum params> );=20 > ssgCullAndDraw(...); > =09 > In order to calculate proper arguments=20 > to ssgSetFrustum( left, right, > bottom, top, zNear, zFar) as the given=20 > FoV partitioning you could search for > keywords glfrustum and off-axis=20 > projection, or tiled projection.=20 > =09 > If you prefer, just use to code below.=20 > You nave to find how to split you > 135=B0 FoV screen into 3x45=B0 screens=20 > (i.e. the four corners of each projection > surface) in terms of (ul,ur,ll,lr)=20 > corner positions - and set eyepos as to=20 > comprise the 135=B0 screen. It's not=20 > important where the coordinate system > origin is wrt screen corner and eyepos,=20 > nor the units, but, for simplicity, > you could just put the coordinate=20 > system origin at the center of the center=20 > screen and find (ul,ur,ll,lr) and=20 > eyepos accordingly, or put it at eyepos > (eyepos (0,0,0)) and find (ul,ur,ll,lr)=20 > accordingly: > =09 > ul ur > +---+------+---+ > | | | | > +...+......+...+ > |\ |\ /| /|=20 > +--\+-\--/-+/--+ > ll lr\ \/ / > \/ > eyepos > =09 > enum {SC_UL, SC_UR, SC_LL, SC_LR}; //=20 > enum for specifying screen corner > //=20 > (Ux: upper, Lx: lower, xL: left, xR: > right) > =09 > void calcOffAxisView( > // input args > sgVec3 screen[4], // the four=20 > screen corner positions (x,y,z), > // fill entries=20 > SC_UL, SC_UR, SC_LL, and SC_LR > sgVec3 eyepos, // eye=20 > position (x,y,z)=20 > // screen and=20 > eyepos have to be in the same > coordinate system > // (x+ right,=20 > y+ up, z+ out of the screen) > float near_clip, float far_clip,=20 > // near and far clipping planes=20 > // output args > float *left, float *right, float=20 > *bottom, float *top // first six > args to ssgSetFrustum, > =20 > // the last two > are near_clip and far_clip=20 > ) > { > sgVec3 eyeToScreen, xProj, yProj, zProj; > float width, height, dist; > sgVec3 eyePos; > =09 > sgCopyVec3( eyePos, eyepos ); > // Calculate vector from eye to=20 > screen origin (lower left corner)=20 > sgSubVec3(eyeToScreen, eyePos,=20 > screen[SC_LL]); > // Calculate vectors from bottom=20 > left corner of screen that form > // the screen coordinate frame > sgSubVec3(xProj, screen[SC_LR],=20 > screen[SC_LL]);=20 > width =3D sgLengthVec3(xProj); > sgScaleVec3(xProj, SG_ONE / width); > sgSubVec3(yProj, screen[SC_UL],=20 > screen[SC_LL]); > height =3D sgLengthVec3(yProj); > sgScaleVec3(yProj, SG_ONE / height);=20 > sgVectorProductVec3(zProj, xProj, yProj); > =09 > // Now, specify an off-axis=20 > viewing frustum in order to define the > // viewing volume with respect=20 > to the user's eye position. > *left =3D=20 > sgScalarProductVec3(eyeToScreen, xProj);=20 > *right =3D width - *left; > bottom =3D=20 > sgScalarProductVec3(eyeToScreen, yProj); > *top =3D height - *bottom; > dist =3D=20 > sgScalarProductVec3(eyeToScreen, zProj); > float nc_over_d =3D near_clip / dist;=20 > *left *=3D -nc_over_d; > *right *=3D nc_over_d; > *bottom *=3D -nc_over_d; > *top *=3D nc_over_d; > } > =09 > Note that the code above is only valid=20 > for the tiling case (i.e. there's no=20 > screen rotation) - for arbitrary=20 > positioned screens there's an additional > matrix multiplication to take into=20 > account either in the projection or in > the modelview matrix (in this case, its=20 > inverse). > =09 > Greetings -=20 > =09 > Paolo Leoncini > =09 > =09 > ________________________________ > =09 > Da:=20 > pli...@li...=20 > [mailto:=20 > pli...@li...=20 > <mailto:pli...@li...> ] Per conto=20 > di swetha korada > Inviato: luned=EC 15 ottobre 2007 10.35 > A: pli...@li... > Oggetto: [Plib-users] How to=20 > clip an area=20 > =09 > =09 > Hi all, > =09 > I am using plib-1.8.2=20 > version.In that, I have set the horizonital > Field Of View(FOV) as 135 degrees.In=20 > that I have to render only first 45=20 > degrees area.So I need to clip next 90=20 > degrees.How to achieve this? > =09 > Hope any one will give reply as=20 > soon as possible. > =09 > Thanks And Regards, > swetha. > =09 > =09 > =09 > =09 > =09 > -------------------------------------------------------------- > -----------=20 > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to=20 > find problems? Stop. > Now Search log events and configuration=20 > files using AJAX and a browser. > Download your FREE copy of Splunk now=20 > >> http://get.splunk.com/ > _______________________________________________ > plib-users mailing list > pli...@li...=20 > =09 > https://lists.sourceforge.net/lists/listinfo/plib-users=20 > <https://lists.sourceforge.net/lists/listinfo/plib-users> |