2 #include <OpenGl_transform_persistence.hxx>
4 #include <OpenGl_tgl_all.hxx>
9 #include <math.h> /* pour M_PI */
14 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
16 #include <OpenGl_cmn_varargs.hxx>
17 #include <OpenGl_telem_attri.hxx>
18 #include <OpenGl_tsm.hxx>
19 #include <OpenGl_telem.hxx>
20 #include <OpenGl_telem_inquire.hxx>
21 #include <OpenGl_tsm_ws.hxx> /* pour TsmGetWSAttri */
22 #include <OpenGl_telem_view.hxx> /* pour tel_view_data */
25 #include <OpenGl_tgl_funcs.hxx>
27 #include <OpenGl_Memory.hxx>
30 /*----------------------------------------------------------------------*/
39 Tmatrix3 inverse_matrix;/* accelerates UVN2XYZ conversion */
41 } TEL_VIEW_DATA, *tel_view_data; /* Internal data stored for every view rep */
45 static TStatus TransformPersistenceDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
46 static TStatus TransformPersistenceAdd( TSM_ELEM_DATA, Tint, cmn_key* );
47 static TStatus TransformPersistenceDelete( TSM_ELEM_DATA, Tint, cmn_key* );
48 static TStatus TransformPersistencePrint( TSM_ELEM_DATA, Tint, cmn_key* );
50 static TStatus (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
52 TransformPersistenceDisplay, /* PickTraverse */
53 TransformPersistenceDisplay,
54 TransformPersistenceAdd,
55 0, /*TransformPersistenceDelete,*/
56 TransformPersistencePrint,
62 TelTransformPersistentInitClass( TelType *el )
64 *el = TelTransformPersistence;
69 TransformPersistenceAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
71 tel_transform_persistence data = new TEL_TRANSFORM_PERSISTENCE();
76 *data = *(tel_transform_persistence)(k[0]->data.pdata);
78 ((tsm_elem_data)(d.pdata))->pdata = data;
85 TransformPersistenceDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
89 key.id = TelTransformPersistence;
90 key.data.pdata = data.pdata;
91 TsmSetAttri( 1, &key );
96 TransformPersistenceDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
98 /* transform_persistence_end();*/
104 TransformPersistencePrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
110 /***********************************/
111 static int isGenerated = 0;
113 void transform_persistence_end(void)
115 if( isGenerated == 1 )
118 glMatrixMode (GL_PROJECTION);
120 glMatrixMode (GL_MODELVIEW);
125 /*printf( "Transform Persistence End: %i \n", isGenerated );*/
129 void transform_persistence_begin( int theFlag,
137 GLdouble modelMatrix[4][4];
138 GLdouble projMatrix[4][4];
139 GLdouble idenMatrix[4][4] = { {1.,0.,0.,0.}, {0.,1.,0.,0.}, {0.,0.,1.,0.},{0.,0.,0.,1.} };
143 double W, H, W1, W2, H1, H2;
144 double winx, winy, winz;
145 double scaleX, scaleY, scaleZ;
148 printf( "Transform Persistence Mode: %i\n", theFlag );
149 printf( "Transform Persistence PointX: %f\n", theX );
150 printf( "Transform Persistence PointY: %f\n", theY );
151 printf( "Transform Persistence PointZ: %f\n", theZ );
156 transform_persistence_end();
160 glGetIntegerv (GL_VIEWPORT, viewport);
161 glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix );
162 glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
167 if( isGenerated == 0 )
172 glMatrixMode (GL_PROJECTION);
174 glMatrixMode (GL_MODELVIEW);
178 glMatrixMode( GL_MODELVIEW );
182 glMatrixMode( GL_PROJECTION );
186 /*pre loading matrix*/
187 if( theFlag & TPF_PAN )
188 /* Annulate translate matrix */
190 modelMatrix[3][0] = 0.;
191 modelMatrix[3][1] = 0.;
192 modelMatrix[3][2] = 0.;
193 projMatrix[3][0] = 0.;
194 projMatrix[3][1] = 0.;
195 projMatrix[3][2] = 0.;
198 if( theFlag & TPF_ZOOM )
199 /* Annulate zoom matrix */
202 det2 = 0.002 / projMatrix[1][1];
204 det2 = 0.002 / projMatrix[0][0];
206 TsmGetWSAttri( TglActiveWs, WSViews, &key );
207 vptr = (tel_view_data)key.pdata ; /* Obtain defined view data*/
208 scaleX = vptr->vrep.extra.scaleFactors[0];
209 scaleY = vptr->vrep.extra.scaleFactors[1];
210 scaleZ = vptr->vrep.extra.scaleFactors[2];
212 for( i = 0; i < 3; i++ )
214 for( j = 0; j < 3; j++ )
217 modelMatrix[i][j] /= scaleX;
219 modelMatrix[i][j] /= scaleY;
221 modelMatrix[i][j] /= scaleZ;
224 for( i = 0 ; i < 2; i++ )
225 projMatrix[i][i] *= det2;
228 if( theFlag & TPF_ROTATE )
229 /* Annulate rotate matrix */
231 modelMatrix[0][0] = 1.;
232 modelMatrix[1][1] = 1.;
233 modelMatrix[2][2] = 1.;
235 modelMatrix[1][0] = 0.;
236 modelMatrix[2][0] = 0.;
237 modelMatrix[0][1] = 0.;
238 modelMatrix[2][1] = 0.;
239 modelMatrix[0][2] = 0.;
240 modelMatrix[1][2] = 0.;
242 else if( theFlag & TPF_RELATIVE_ROTATE )
243 /* Initialize relative rotate matrix*/
245 modelMatrix[3][0] = 0.;
246 modelMatrix[3][1] = 0.;
247 modelMatrix[3][2] = 0.;
249 glMatrixMode( GL_MODELVIEW );
251 glTranslated( theX, theY, theZ );
254 if( theFlag == TPF_TRIEDRON )
256 /* Annulate translation matrix */
257 modelMatrix[3][0] = 0.;
258 modelMatrix[3][1] = 0.;
259 modelMatrix[3][2] = 0.;
261 projMatrix[3][0] = 0.;
262 projMatrix[3][1] = 0.;
263 projMatrix[3][2] = 0.;
266 det2 = 0.002 / projMatrix[1][1];
268 det2 = 0.002 / projMatrix[0][0];
270 for( i = 0 ; i < 2; i++ )
271 projMatrix[i][i] *= det2;
275 glMatrixMode (GL_MODELVIEW);
276 glMultMatrixd( (GLdouble *) modelMatrix);
278 glMatrixMode ( GL_PROJECTION );
279 glMultMatrixd( (GLdouble *) projMatrix);
282 /*post loading matrix*/
283 if( theFlag == TPF_TRIEDRON )
285 glMatrixMode( GL_PROJECTION );
287 gluUnProject( W/2, H/2., 0, (GLdouble*)idenMatrix, (GLdouble*)projMatrix, (GLint*)viewport, &winx, &winy, &winz);
290 gluUnProject( -W/2, -H/2., 0, (GLdouble*)idenMatrix, (GLdouble*)projMatrix, (GLint*)viewport, &winx, &winy, &winz);
294 if( theX == 0. && theY == 0. )
298 else if( theX > 0. && theY > 0. )
301 glTranslated( (W1 - W2)/2. - theZ/2., (H1-H2)/2. - theZ/2., 0. );
303 else if( theX > 0. && theY < 0. )
306 glTranslated( (W1 - W2)/2. - theZ/2., -(H1-H2)/2. + theZ/2., 0. );
308 else if( theX < 0. && theY > 0. )
311 glTranslated( -(W1 - W2)/2. + theZ/2., (H1-H2)/2. - theZ/2., 0. );
313 else if( theX < 0 && theY < 0 )
316 glTranslated( -(W1 - W2)/2. + theZ/2., -(H1-H2)/2. + theZ/2., 0. );