1 /***********************************************************************
12 HISTORIQUE DES MODIFICATIONS :
13 --------------------------------
14 xx-xx-xx : xxx ; Creation.
15 20-02-96 : FMN ; Suppression code inutile:
16 11-03-96 : FMN ; Correction warning compilation
17 01-04-96 : CAL ; Integration MINSK portage WNT
18 13-06-96 : CAL ; Gestion de la transparence dans redraw_all_structs
19 09-07-97 : FMN ; Verification calcul matrice orientation et projection.
20 Je n'ai verifie que le mode parallele pas le mode perspective.
21 18-07-97 : FMN ; Desactivation des lights au demarrage
22 05-08-97 : PCT ; Support texture mapping
23 19-08-97 : PCT ; ajout reflexion
24 23-12-97 : FMN ; Suppression TelBackInteriorStyle, TelBackInteriorStyleIndex
25 et TelBackInteriorShadingMethod
26 13-01-98 : FMN ; Oublie printf
27 03-03-98 : FMN ; Suppression variable externe TglWhetherPerspective
28 13-03-98 : FMN ; Suppression variable externe TglUpdateView0
29 17-03-98 : FMN ; Ajout mode animation
30 - deplacement TelSetViewIndex de OpenGl_execstruct.c ici.
31 - gestion du mode animation.
32 29-04-98 : FMN ; Mode animation
33 - ajout TsmPushAttri et TsmPopAttri necessaire pour
34 sauvegarder la point de vue.
35 - ajout init de la var TglActiveWs
36 08-07-98 : FMN ; Mode animation: ajout print debug
37 27-11-98 : CAL ; S4062. AJout des layers.
38 30-11-98 : FMN ; S3819 : Textes toujours visibles
39 14-12-98 : BGN ; (S3989, Phase "triedre") ajout du reaffichage
41 05-01-99 : CAL ; Warning WNT
42 22-03-04 : SAN ; OCC4895 High-level interface for controlling polygon offsets
44 ************************************************************************/
46 #define G003 /* EUG 20-09-99 ; Animation management
50 /*----------------------------------------------------------------------*/
58 #include <OpenGl_tgl_all.hxx>
59 #include <OpenGl_cmn_varargs.hxx>
60 #include <OpenGl_tsm.hxx>
61 #include <OpenGl_tsm_ws.hxx>
62 #include <OpenGl_telem.hxx>
63 #include <OpenGl_telem_view.hxx>
64 #include <OpenGl_telem_util.hxx>
65 #include <OpenGl_telem_attri.hxx>
66 #include <OpenGl_tgl_funcs.hxx>
67 #include <OpenGl_telem_util.hxx>
68 #include <OpenGl_LightBox.hxx>
69 #include <OpenGl_TextureBox.hxx>
70 #include <OpenGl_animation.hxx>
72 #include <InterfaceGraphic_Graphic3d.hxx>
73 #include <OpenGl_telem.hxx>
74 #include <InterfaceGraphic_Visual3d.hxx>
75 #include <OpenGl_trsf_stack.hxx>
76 #include <OpenGl_triedron.hxx>
77 #include <OpenGl_graduatedtrihedron.hxx>
80 # include <OpenGl_degeneration.hxx>
87 #include <OSD_FontAspect.hxx>
88 /*----------------------------------------------------------------------*/
95 #define NO_DEBUG_ANIMATION
99 /*----------------------------------------------------------------------*/
104 tsm_trsf_stack trsf_stack = NULL;
105 tsm_trsf_stack cur_trsf_stack = NULL;
107 Tint ForbidSetTextureMapping; /* valid only during traversal */
108 Tint SecondPassNeeded; /* valid only during traversal */
109 Tint SecondPassDo; /* valid only during traversal */
112 extern GLboolean g_fUpdateAM;
113 extern GLboolean g_fList;
118 /*----------------------------------------------------------------------*/
123 static void call_util_apply_trans2( float ix, float iy, float iz, matrix3 mat,
124 float *ox, float *oy, float *oz );
125 static void call_util_mat_mul( matrix3 mat_a, matrix3 mat_b, matrix3 mat_c);
128 static void pr_matrix( matrix3 mat );
131 /*----------------------------------------------------------------------*/
137 call_func_set_text_style(int lid)
141 key.data.ldata = lid;
142 TsmAddToStructure( TelTextStyle, 1, &key );
146 /*----------------------------------------------------------------------*/
149 call_func_set_text_display_type(int lid)
153 key.data.ldata = lid;
154 TsmAddToStructure( TelTextDisplayType, 1, &key );
158 /*----------------------------------------------------------------------*/
161 /*----------------------------------------------------------------------*/
164 call_func_label(Tint lid)
168 key.data.ldata = lid;
169 TsmAddToStructure( TelLabel, 1, &key );
173 /*----------------------------------------------------------------------*/
176 call_func_appl_data(void *ptr)
180 key.data.pdata = ptr;
181 TsmAddToStructure( TelApplicationData, 1, &key );
185 /*----------------------------------------------------------------------*/
188 call_func_set_view_ind(Tint vid)
192 key.data.ldata = vid;
193 TsmAddToStructure( TelViewIndex, 1, &key );
197 /*----------------------------------------------------------------------*/
200 call_func_set_local_tran3( Tmatrix3 mat, TComposeType mode )
205 key.data.pdata = mat;
206 TsmAddToStructure( TelLocalTran3, 1, &key );
210 /*----------------------------------------------------------------------*/
213 call_func_set_linewidth( Tfloat lw )
218 TsmAddToStructure( TelPolylineWidth, 1, &key );
222 /*----------------------------------------------------------------------*/
225 call_func_set_linetype( Tint lt )
230 TsmAddToStructure( TelPolylineType, 1, &key );
234 /*----------------------------------------------------------------------*/
237 call_func_set_edge_type( Tint lt )
242 TsmAddToStructure( TelEdgeType, 1, &key );
246 /*----------------------------------------------------------------------*/
249 call_func_set_int_style( Tint is )
254 TsmAddToStructure( TelInteriorStyle, 1, &key );
258 /*----------------------------------------------------------------------*/
261 call_func_set_edge_flag( Tint st )
266 TsmAddToStructure( TelEdgeFlag, 1, &key );
271 /*----------------------------------------------------------------------*/
274 call_func_set_edgewidth( Tfloat ew )
279 TsmAddToStructure( TelEdgeWidth, 1, &key );
283 /*----------------------------------------------------------------------*/
286 call_func_set_int_style_ind( Tint ind )
290 key.data.ldata = ind;
291 TsmAddToStructure( TelInteriorStyleIndex, 1, &key );
295 /*----------------------------------------------------------------------*/
298 call_func_set_face_disting_mode( Tint mode )
302 key.data.ldata = mode;
303 TsmAddToStructure( TelFaceDistinguishingMode, 1, &key );
307 /*----------------------------------------------------------------------*/
310 call_func_set_face_cull_mode( Tint mode )
314 key.data.ldata = mode;
315 TsmAddToStructure( TelFaceCullingMode, 1, &key );
319 /*----------------------------------------------------------------------*/
322 call_func_set_marker_type( Tint type )
326 key.data.ldata = type;
327 TsmAddToStructure( TelPolymarkerType, 1, &key );
332 /*----------------------------------------------------------------------*/
335 call_func_set_marker_size( Tfloat size )
339 key.data.fdata = size;
340 TsmAddToStructure( TelPolymarkerSize, 1, &key );
345 /*----------------------------------------------------------------------*/
348 call_func_exec_struct(Tint stid)
352 key.data.ldata = stid;
353 TsmAddToStructure( TelExecuteStructure, 1, &key );
357 /*----------------------------------------------------------------------*/
362 TelHookOnAllClasses();
366 /*----------------------------------------------------------------------*/
368 void /* Ignoring priority */
369 call_func_post_struct( Tint ws, Tint stid, Tfloat priority )
374 TsmSetWSAttri( ws, WSViewStid, &k );
378 /*----------------------------------------------------------------------*/
381 call_func_set_int_shad_meth(Tint mtd)
385 key.data.ldata = mtd;
386 TsmAddToStructure( TelInteriorShadingMethod, 1, &key );
390 /*----------------------------------------------------------------------*/
393 call_func_set_refl_eqn( Tint eqn )
397 key.data.ldata = eqn;
398 TsmAddToStructure( TelInteriorReflectanceEquation, 1, &key );
402 /*----------------------------------------------------------------------*/
405 call_func_set_back_refl_eqn( Tint eqn )
409 key.data.ldata = eqn;
410 TsmAddToStructure( TelBackInteriorReflectanceEquation, 1, &key );
414 /*----------------------------------------------------------------------*/
417 call_func_set_text_font( Tchar *font )
422 key.data.pdata = font;
423 TsmAddToStructure( TelTextFont, 1, &key );
427 /*----------------------------------------------------------------------*/
430 call_func_set_char_space( Tfloat sp )
435 TsmAddToStructure( TelCharacterSpacing, 1, &key );
439 /*----------------------------------------------------------------------*/
442 call_func_set_char_expan( Tfloat exp )
446 key.data.fdata = exp;
447 TsmAddToStructure( TelCharacterExpansionFactor, 1, &key );
451 /*----------------------------------------------------------------------*/
456 call_func_set_text_zoomable( Tint flag )
460 key.data.ldata = flag;
461 TsmAddToStructure( TelTextZoomable, 1, &key );
465 /*----------------------------------------------------------------------*/
469 call_func_set_text_angle( Tfloat angl )
473 key.data.ldata = angl;
474 TsmAddToStructure( TelTextAngle, 1, &key );
478 /*----------------------------------------------------------------------*/
482 call_func_set_text_fontaspect( OSD_FontAspect fontaspect )
486 key.data.ldata = fontaspect;
487 TsmAddToStructure( TelTextFontAspect, 1, &key );
493 /*----------------------------------------------------------------------*/
495 /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */
496 void call_func_set_polygon_offset_params( Tint mode, Tfloat factor, Tfloat units )
499 TEL_POFFSET_PARAM param;
502 param.factor = factor;
505 key.data.pdata = ¶m;
506 TsmAddToStructure( TelPolygonOffset, 1, &key );
508 /* OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets */
510 /*----------------------------------------------------------------------*/
513 call_func_set_pick_id(Tint pid)
517 key.data.ldata = pid;
518 TsmAddToStructure( TelPickId, 1, &key );
521 /*----------------------------------------------------------------------*/
523 static void redraw_all_structs( Tint wsid, Tint vstid )
526 GLint blend_dst, blend_src;
527 GLboolean blend_state;
529 GLboolean zbuff_state, zbuff_w;
531 /* Est-il necessaire de faire de la transparence ? */
532 TsmGetWSAttri( wsid, WSTransparency, &k );
533 TelSetTransparency( k.ldata );
535 /* ajout PCT pour gestion des textures */
536 TsmGetWSAttri(wsid, WSSurfaceDetail, &k);
541 ForbidSetTextureMapping = 1;
542 SecondPassNeeded = 0;
545 TsmDisplayStructure( vstid, wsid );
548 /* TOD_ENVIRONMENT */
550 ForbidSetTextureMapping = 1;
551 SecondPassNeeded = 0;
553 TsmGetWSAttri(wsid, WSTextureEnv, &k);
554 SetCurrentTexture(k.ldata);
556 TsmDisplayStructure( vstid, wsid );
563 ForbidSetTextureMapping = 0;
564 SecondPassNeeded = 0;
566 TsmDisplayStructure( vstid, wsid );
570 if (SecondPassNeeded)
573 TsmGetWSAttri(wsid, WSTextureEnv, &k);
574 SetCurrentTexture(k.ldata);
577 /* sauvegarde de quelques parametres OpenGL */
578 glGetBooleanv(GL_DEPTH_WRITEMASK, &zbuff_w);
579 glGetIntegerv(GL_DEPTH_FUNC, &zbuff_f);
580 glGetIntegerv(GL_BLEND_DST, &blend_dst);
581 glGetIntegerv(GL_BLEND_SRC, &blend_src);
582 zbuff_state = glIsEnabled(GL_DEPTH_TEST);
583 blend_state = glIsEnabled(GL_BLEND);
586 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
589 glDepthFunc(GL_EQUAL);
590 glDepthMask(GL_FALSE);
591 glEnable(GL_DEPTH_TEST);
593 ForbidSetTextureMapping = 1;
594 TsmDisplayStructure(vstid, wsid );
597 /* restauration des parametres OpenGL */
598 glBlendFunc(blend_src, blend_dst);
599 if (!blend_state) glDisable(GL_BLEND);
601 glDepthFunc(zbuff_f);
602 glDepthMask(zbuff_w);
603 if (!zbuff_state) glDisable(GL_DEPTH_FUNC);
609 /*----------------------------------------------------------------------*/
612 call_func_redraw_all_structs( Tint wsid, Tint swap )
614 call_func_redraw_all_structs_begin (wsid);
615 call_func_redraw_all_structs_proc (wsid);
616 call_func_redraw_all_structs_end (wsid, swap);
620 /*----------------------------------------------------------------------*/
623 call_func_set_anno_char_ht( Tfloat h )
628 TsmAddToStructure( TelTextHeight, 1, &key );
632 /*----------------------------------------------------------------------*/
634 void /* unimplemented */
635 call_func_set_anno_char_up_vec( Tfloat path[2] )
640 /*----------------------------------------------------------------------*/
642 void /* unimplemented */
643 call_func_set_anno_path( Tint path )
648 /*----------------------------------------------------------------------*/
651 void /* unimplemented */
652 call_func_set_anno_align( Tint hor, Tint ver )
654 /*OCC7456 abd 14.12.2004 Text alingnment attributes */
659 k.data.pdata = &data;
661 TsmAddToStructure( TelTextAlign, 1, &k );
662 /*OCC7456 abd 14.12.2004 Text alingnment attributes */
667 /*----------------------------------------------------------------------*/
670 call_func_anno_text_rel3( tel_point pt, Techar *str )
674 k[0].id = TEXT_ATTACH_PT_ID;
675 k[0].data.pdata = pt;
676 k[1].id = TEXT_STRING_ID;
677 k[1].data.pdata = str;
678 TsmAddToStructure( TelText, 2, &k[0], &k[1] );
683 /*----------------------------------------------------------------------*/
686 call_func_dcue_ind(Tint dcid)
690 key.data.ldata = dcid;
691 TsmAddToStructure( TelDepthCueIndex, 1, &key );
695 /*----------------------------------------------------------------------*/
698 call_func_set_texture_id(Tint dcid)
702 key.data.ldata = dcid;
703 TsmAddToStructure( TelTextureId, 1, &key );
707 /*----------------------------------------------------------------------*/
710 call_func_set_do_texturemap(Tint dcid)
714 key.data.ldata = dcid;
715 TsmAddToStructure( TelDoTextureMap, 1, &key );
719 /*----------------------------------------------------------------------*/
725 pr_matrix( matrix3 mat )
727 printf( "%1.12f %1.12f %1.12f %1.12f\n", mat[0][0], mat[0][1], mat[0][2], mat[0][3] );
728 printf( "%1.12f %1.12f %1.12f %1.12f\n", mat[1][0], mat[1][1], mat[1][2], mat[1][3] );
729 printf( "%1.12f %1.12f %1.12f %1.12f\n", mat[2][0], mat[2][1], mat[2][2], mat[2][3] );
730 printf( "%1.12f %1.12f %1.12f %1.12f\n", mat[3][0], mat[3][1], mat[3][2], mat[3][3] );
737 * Evaluates orientation matrix.
739 /* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */
740 void call_func_eval_ori_matrix3 (
741 point3 *vrp, /* view reference point */
742 vec3 *vpn, /* view plane normal */
743 vec3 *vup, /* view up vector */
745 float mout[4][4]) /* OUT view orientation matrix */
748 /* Translate to VRP then change the basis.
749 * The old basis is: e1 = < 1, 0, 0>, e2 = < 0, 1, 0>, e3 = < 0, 0, 1>.
750 * The new basis is: ("x" means cross product)
752 * e1' = VUP x VPN / |VUP x VPN|
754 * Therefore the transform from old to new is x' = TAx, where:
756 * | e1'x e2'x e3'x 0 | | 1 0 0 0 |
757 * A = | e1'y e2'y e3'y 0 |, T = | 0 1 0 0 |
758 * | e1'z e2'z e3'z 0 | | 0 0 1 0 |
759 * | 0 0 0 1 | | -vrp.x -vrp.y -vrp.z 1 |
764 * These ei's are really ei primes.
766 register float (*m)[4][4];
767 point3 e1, e2, e3, e4;
771 * e1' = VUP x VPN / |VUP x VPN|, but do the division later.
773 e1.x = vup->delta_y * vpn->delta_z - vup->delta_z * vpn->delta_y;
774 e1.y = vup->delta_z * vpn->delta_x - vup->delta_x * vpn->delta_z;
775 e1.z = vup->delta_x * vpn->delta_y - vup->delta_y * vpn->delta_x;
776 s = sqrt( e1.x * e1.x + e1.y * e1.y + e1.z * e1.z);
780 v = sqrt( e3.x * e3.x + e3.y * e3.y + e3.z * e3.z);
782 * Check for vup and vpn colinear (zero dot product).
784 if ((s > -EPSI) && (s < EPSI))
788 * Check for a normal vector not null.
790 if ((v > -EPSI) && (v < EPSI))
808 e2.x = e3.y * e1.z - e3.z * e1.y;
809 e2.y = e3.z * e1.x - e3.x * e1.z;
810 e2.z = e3.x * e1.y - e3.y * e1.x;
812 * Add the translation
814 e4.x = -( e1.x * vrp->x + e1.y * vrp->y + e1.z * vrp->z);
815 e4.y = -( e2.x * vrp->x + e2.y * vrp->y + e2.z * vrp->z);
816 e4.z = -( e3.x * vrp->x + e3.y * vrp->y + e3.z * vrp->z);
818 * Homogeneous entries
820 * | e1.x e2.x e3.x 0.0 | | 1 0 0 0 |
821 * | e1.y e2.y e3.y 0.0 | * | 0 1 0 0 |
822 * | e1.z e2.z e3.z 0.0 | | a b 1 c |
823 * | e4.x e4.y e4.z 1.0 | | 0 0 0 1 |
826 m = (float (*)[4][4])mout;
831 (*m)[0][3] = ( float )0.0;
836 (*m)[1][3] = ( float )0.0;
841 (*m)[2][3] = ( float )0.0;
846 (*m)[3][3] = ( float )1.0;
851 printf( "\n->call_func_eval_ori_matrix3 \n" );
852 printf( "orientation_matrix :\n" );
858 /*----------------------------------------------------------------------*/
860 * Evaluates mapping matrix.
862 /* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */
863 void call_func_eval_map_matrix3(
874 matrix3 aux_mat1, aux_mat2, aux_mat3;
880 Spar[i][j] = Sper[i][j] = aux_mat1[i][j] = aux_mat2[i][j] =
881 aux_mat3[i][j] = Tper[i][j] = Tpar[i][j] = Tprp[i][j] =
882 Shear[i][j] = Scale[i][j] = ( float )(i == j);
884 Prp.x = Map->proj_ref_point.x;
885 Prp.y = Map->proj_ref_point.y;
886 Prp.z = Map->proj_ref_point.z;
891 if (Map->proj_type == TYPE_PARAL)
897 float cx, cy, gx, gy, xsf, ysf, zsf;
899 float dopx, dopy, dopz;
900 matrix3 tmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
901 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
902 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
903 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
904 matrix3 smat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
905 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
906 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
907 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
908 matrix3 shmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
909 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
910 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
911 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
912 matrix3 tshmat = { { ( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0 },
913 { ( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0 },
914 { ( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0 },
915 { ( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0 } };
918 cx = Map->win.x_min + Map->win.x_max, cx /= ( float )2.0;
919 cy = Map->win.y_min + Map->win.y_max, cy /= ( float )2.0;
921 gx = 2.0/ (Map->win.x_max - Map->win.x_min);
922 gy = 2.0/ (Map->win.y_max - Map->win.y_min);
926 tmat[2][3] = (Map->front_plane + Map->back_plane)/(Map->front_plane - Map->back_plane);
930 smat[2][2] = -2./(Map->front_plane - Map->back_plane);
938 shmat[0][2] = -(dopx/dopz);
939 shmat[1][2] = -(dopy/dopz);
941 /* multiply to obtain mapping matrix */
942 call_util_mat_mul( tmat, shmat, tshmat );
943 call_util_mat_mul( smat, tshmat, mat );
946 printf( "\n->call_func_eval_map_matrix3 FMN\n" );
947 printf("prp %f %f %f \n", Prp.x, Prp.y, Prp.z);
948 printf("vpd fpd bpd %f %f %f \n", Map->view_plane, Map->front_plane, Map->back_plane);
949 printf("window limits %f %f %f %f\n", Map->win.x_min, Map->win.x_max,
950 Map->win.y_min, Map->win.y_max);
951 printf( "mapping_matrix :\n" );
958 Map->proj_vp.z_min = ( float )0.0;
959 Map->proj_vp.z_max = ( float )1.0;
962 /* Shear matrix calculation */
963 umid = ( float )(Map->win.x_min+Map->win.x_max)/( float )2.0;
964 vmid = ( float )(Map->win.y_min+Map->win.y_max)/( float )2.0;
965 if(Prp.z == Map->view_plane){
966 /* Projection reference point is on the view plane */
970 Shear[2][0] = ( float )(-1.0) * ((Prp.x-umid)/(Prp.z-Map->view_plane));
971 Shear[2][1] = ( float )(-1.0) * ((Prp.y-vmid)/(Prp.z-Map->view_plane));
974 * Calculate the lower left coordinate of the view plane
975 * after the Shearing Transformation.
977 call_util_apply_trans2(Map->win.x_min, Map->win.y_min,
978 Map->view_plane, Shear, &(temp.x), &(temp.y), &(temp.z));
980 /* Translate the back plane to the origin */
981 Tpar[3][0] = ( float )(-1.0) * temp.x;
982 Tpar[3][1] = ( float )(-1.0) * temp.y;
983 Tpar[3][2] = ( float )(-1.0) * Map->back_plane;
985 call_util_mat_mul(Shear, Tpar, aux_mat1);
987 /* Calculation of Scaling transformation */
988 Spar[0][0] = ( float )1.0 / (Map->win.x_max - Map->win.x_min);
989 Spar[1][1] = ( float )1.0 / (Map->win.y_max - Map->win.y_min);
990 Spar[2][2] = ( float )1.0 / (Map->front_plane - Map->back_plane );
991 call_util_mat_mul (aux_mat1, Spar, aux_mat2);
992 /* Atlast we transformed view volume to NPC */
994 /* Translate and scale the view plane to projection view port */
995 if(Map->proj_vp.x_min < 0.0 || Map->proj_vp.y_min < 0.0 ||
996 Map->proj_vp.z_min < 0.0 || Map->proj_vp.x_max > 1.0 ||
997 Map->proj_vp.y_max > 1.0 || Map->proj_vp.z_max > 1.0 ||
998 Map->proj_vp.x_min > Map->proj_vp.x_max ||
999 Map->proj_vp.y_min > Map->proj_vp.y_max ||
1000 Map->proj_vp.z_min > Map->proj_vp.z_max){
1006 aux_mat1[i][j] = (float)(i==j);
1007 aux_mat1[0][0] = Map->proj_vp.x_max-Map->proj_vp.x_min;
1008 aux_mat1[1][1] = Map->proj_vp.y_max-Map->proj_vp.y_min;
1009 aux_mat1[2][2] = Map->proj_vp.z_max-Map->proj_vp.z_min;
1010 aux_mat1[3][0] = Map->proj_vp.x_min;
1011 aux_mat1[3][1] = Map->proj_vp.y_min;
1012 aux_mat1[3][2] = Map->proj_vp.z_min;
1013 call_util_mat_mul (aux_mat2, aux_mat1, mat);
1016 printf( "\n->call_func_eval_map_matrix3 - ORTHOGRAPHIC projection\n" );
1017 printf("prp %f %f %f \n", Prp.x, Prp.y, Prp.z);
1018 printf("vpd fpd bpd %f %f %f \n", Map->view_plane, Map->front_plane, Map->back_plane);
1019 printf("window limits %f %f %f %f\n", Map->win.x_min, Map->win.x_max,
1020 Map->win.y_min, Map->win.y_max);
1021 printf( "mapping_matrix :\n" );
1031 else if (Map->proj_type == TYPE_PERSPECT)
1038 Map->proj_vp.z_min = ( float )0.0;
1039 Map->proj_vp.z_max = ( float )1.0;
1042 B = Map->back_plane;
1043 F = Map->front_plane;
1044 V = Map->view_plane;
1046 if(Prp.z == Map->view_plane){
1047 /* Centre of Projection is on the view plane */
1051 if(Map->proj_vp.x_min < 0.0 || Map->proj_vp.y_min < 0.0 ||
1052 Map->proj_vp.z_min < 0.0 || Map->proj_vp.x_max > 1.0 ||
1053 Map->proj_vp.y_max > 1.0 || Map->proj_vp.z_max > 1.0 ||
1054 Map->proj_vp.x_min > Map->proj_vp.x_max ||
1055 Map->proj_vp.y_min > Map->proj_vp.y_max ||
1056 Map->proj_vp.z_min > Map->proj_vp.z_max ||
1062 /* This is the transformation to move VRC to Center Of Projection */
1063 Tprp[3][0] = ( float )(-1.0)*Prp.x;
1064 Tprp[3][1] = ( float )(-1.0)*Prp.y;
1065 Tprp[3][2] = ( float )(-1.0)*Prp.z;
1067 /* Calculation of Shear matrix */
1068 umid = ( float )(Map->win.x_min+Map->win.x_max)/( float )2.0-Prp.x;
1069 vmid = ( float )(Map->win.y_min+Map->win.y_max)/( float )2.0-Prp.y;
1070 Shear[2][0] = ( float )(-1.0)*umid/(Map->view_plane-Prp.z);
1071 Shear[2][1] = ( float )(-1.0)*vmid/(Map->view_plane-Prp.z);
1072 call_util_mat_mul(Tprp, Shear, aux_mat3);
1074 /* Scale the view volume to canonical view volume
1075 * Centre of projection at origin.
1076 * 0 <= N <= -1, -0.5 <= U <= 0.5, -0.5 <= V <= 0.5
1078 Scale[0][0] = (( float )(-1.0)*Prp.z+V)/
1079 ((Map->win.x_max-Map->win.x_min)*(( float )(-1.0)*Prp.z+B));
1080 Scale[1][1] = (( float )(-1.0)*Prp.z+V)/
1081 ((Map->win.y_max-Map->win.y_min)*(( float )(-1.0)*Prp.z+B));
1082 Scale[2][2] = ( float )(-1.0) / (( float )(-1.0)*Prp.z+B);
1084 call_util_mat_mul(aux_mat3, Scale, aux_mat1);
1087 * Transform the Perspective view volume into
1088 * Parallel view volume.
1089 * Lower left coordinate: (-0.5,-0.5, -1)
1090 * Upper right coordinate: (0.5, 0.5, 1.0)
1092 Zvmin = ( float )(-1.0*(-1.0*Prp.z+F)/(-1.0*Prp.z+B));
1093 aux_mat2[2][2] = ( float )1.0/(( float )1.0+Zvmin);
1094 aux_mat2[2][3] = ( float )(-1.0);
1095 aux_mat2[3][2] = ( float )(-1.0)*Zvmin*aux_mat2[2][2];
1096 aux_mat2[3][3] = ( float )0.0;
1097 call_util_mat_mul(aux_mat1, aux_mat2, Shear);
1101 aux_mat1[i][j] = aux_mat2[i][j] = (float)(i==j);
1103 /* Translate and scale the view plane to projection view port */
1104 aux_mat2[0][0] = (Map->proj_vp.x_max-Map->proj_vp.x_min);
1105 aux_mat2[1][1] = (Map->proj_vp.y_max-Map->proj_vp.y_min);
1106 aux_mat2[2][2] = (Map->proj_vp.z_max-Map->proj_vp.z_min);
1107 aux_mat2[3][0] = aux_mat2[0][0]/( float )2.0+Map->proj_vp.x_min;
1108 aux_mat2[3][1] = aux_mat2[1][1]/( float )2.0+Map->proj_vp.y_min;
1109 aux_mat2[3][2] = aux_mat2[2][2]+Map->proj_vp.z_min;
1110 call_util_mat_mul (Shear, aux_mat2, mat);
1113 printf( "\n->call_func_eval_map_matrix3 - PERSPECTIVE projection\n" );
1114 printf("prp %f %f %f \n", Prp.x, Prp.y, Prp.z);
1115 printf("vpd fpd bpd %f %f %f \n", Map->view_plane, Map->front_plane, Map->back_plane);
1116 printf("window limits %f %f %f %f\n", Map->win.x_min, Map->win.x_max,
1117 Map->win.y_min, Map->win.y_max);
1118 printf("viewport limits %f %f %f %f %f %f\n", Map->proj_vp.x_min, Map->proj_vp.x_max,
1119 Map->proj_vp.y_min, Map->proj_vp.y_max,
1120 Map->proj_vp.z_min, Map->proj_vp.z_max);
1121 printf( "mapping_matrix :\n" );
1131 /*----------------------------------------------------------------------*/
1134 call_util_apply_trans2( float ix, float iy, float iz, matrix3 mat,
1135 float *ox, float *oy, float *oz )
1138 *ox = ix*mat[0][0]+iy*mat[1][0]+iz*mat[2][0]+mat[3][0];
1139 *oy = ix*mat[0][1]+iy*mat[1][1]+iz*mat[2][1]+mat[3][1];
1140 *oz = ix*mat[0][2]+iy*mat[1][2]+iz*mat[2][2]+mat[3][2];
1141 temp = ix * mat[0][3]+iy * mat[1][3]+iz * mat[2][3]+mat[3][3];
1147 /*----------------------------------------------------------------------*/
1150 call_util_mat_mul( matrix3 mat_a, matrix3 mat_b, matrix3 mat_c)
1156 for (mat_c[i][j] = ( float )0.0,k=0; k<4; k++)
1157 mat_c[i][j] += mat_a[i][k] * mat_b[k][j];
1160 /*----------------------------------------------------------------------*/
1163 call_func_redraw_all_structs_begin( Tint wsid )
1166 static Tmatrix3 identity = {
1167 {( float )1.0, ( float )0.0, ( float )0.0, ( float )0.0},
1168 {( float )0.0, ( float )1.0, ( float )0.0, ( float )0.0},
1169 {( float )0.0, ( float )0.0, ( float )1.0, ( float )0.0},
1170 {( float )0.0, ( float )0.0, ( float )0.0, ( float )1.0}
1174 * Gestion de la pile des transformations pour les structures
1175 * connectees dans la vue <wsid>
1177 if (trsf_stack == NULL) {
1178 trsf_stack = (tsm_trsf_stack) malloc (sizeof (TSM_TRSF_STACK));
1179 trsf_stack->next = NULL;
1180 trsf_stack->prev = NULL;
1181 matcpy (trsf_stack->LocalTran3, identity);
1182 cur_trsf_stack = trsf_stack;
1185 TelClearViews(wsid);
1187 /* Par defaut on desactive les lumieres */
1193 /*----------------------------------------------------------------------*/
1196 call_func_redraw_all_structs_proc( Tint wsid )
1206 TsmGetWSAttri( wsid, WSViewStid, &k );
1208 TsmGetWSAttri ( wsid, WSBackfacing, &kbf );
1209 g_nBackfacing = kbf.ldata;
1211 if ( g_nBackfacing > 0 )
1213 glDisable ( GL_CULL_FACE );
1215 else if ( g_nBackfacing < 0 ) {
1217 glEnable ( GL_CULL_FACE );
1218 glCullFace ( GL_BACK );
1227 printf("OpenGl_funcs::call_func_redraw_all_structs:TsmPushAttri \n");
1229 TsmPushAttri(); /* save previous graphics context */
1231 TglActiveWs = wsid; /* Indispensable precedemment dans TsmDisplayStructure */
1232 /* Avec le mode Ajout cette init n'etait plus faite */
1234 /* mise en place des matrices de projection et de mapping */
1235 kk.id = TelViewIndex;
1236 kk.data.ldata = vstid;
1237 TsmSetAttri( 1, &kk );
1238 TelSetViewIndex (wsid, vstid);
1240 if ( g_fUpdateAM ) goto forceRedraw;
1242 /* Mode animation */
1245 if ((listIndexFlag) && (listIndexView == vstid))
1247 #ifdef DEBUG_ANIMATION
1248 printf("call_func_redraw_all_structs::glCallList1 \n");
1250 glCallList(listIndex);
1263 #ifdef DEBUG_ANIMATION
1264 printf("call_func_redraw_all_structs::glNewList \n");
1266 glNewList(listIndex, GL_COMPILE_AND_EXECUTE);
1267 redraw_all_structs( wsid, vstid );
1268 #ifdef DEBUG_ANIMATION
1269 printf("call_func_redraw_all_structs::glEndList \n");
1272 listIndexFlag = GL_TRUE;
1273 listIndexView = vstid;
1279 /* Optimisation si displaylist est toujours valable */
1280 if ((listIndexFlag) && (listIndexView == vstid))
1282 #ifdef DEBUG_ANIMATION
1283 printf("call_func_redraw_all_structs::glCallList2 \n");
1285 glCallList(listIndex);
1289 #ifdef DEBUG_ANIMATION
1290 printf("call_func_redraw_all_structs::redraw_all_structs \n");
1296 redraw_all_structs( wsid, vstid );
1298 } /* Mode Animation */
1301 printf("OpenGl_funcs::call_func_redraw_all_structs:TsmPopAttri \n");
1303 /* restore previous graphics context; before update lights */
1308 /* affichage de Triedre Non Zoomable de la vue s'il existe */
1310 printf("call_func_redraw_all_structS => CALL_TRIEDRON... \n");
1312 call_triedron_redraw_from_wsid (wsid);
1313 call_graduatedtrihedron_redraw(wsid);
1316 } /* Test vue valide */
1321 /*----------------------------------------------------------------------*/
1324 call_func_redraw_all_structs_end( Tint wsid, Tint swap )
1331 TsmGetWSAttri( wsid, WSViewStid, &k );
1336 /* On swap les buffers */
1337 TsmGetWSAttri( wsid, WSDbuff, &k );
1338 if( (k.ldata == TOn) && (swap) )
1339 TelSwapBuffers( wsid );
1343 } /* Test vue valide */
1346 * Mise a jour de l'update_state
1349 TsmSetWSAttri( wsid, WSUpdateState, &k );
1355 void call_func_set_degenerate_model ( Tint model, Tfloat skipRatio ) {
1361 deg.skipRatio = skipRatio;
1363 key.data.pdata = °
1364 TsmAddToStructure ( TelDegenerationMode, 1, &key );
1366 } /* end call_func_set_degenerate_model */
1371 call_func_set_transform_persistence( Tint mode, Tfloat x, Tfloat y, Tfloat z )
1374 TEL_TRANSFORM_PERSISTENCE pers;
1382 key.data.pdata = &pers;
1383 TsmAddToStructure( TelTransformPersistence, 1, &key );
1386 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */