b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | /*********************************************************************** |
16 | |
17 | FONCTION : |
18 | ---------- |
19 | File OpenGl_telem_util : |
20 | |
21 | |
22 | REMARQUES: |
23 | ---------- |
24 | |
25 | |
26 | HISTORIQUE DES MODIFICATIONS : |
27 | -------------------------------- |
28 | xx-xx-xx : xxx ; Creation. |
29 | 07-02-96 : FMN ; - Ajout trace |
30 | - Suppression code inutile |
31 | 08-03-96 : FMN ; - Ajout include manquant |
32 | 01-04-96 : CAL ; Integration MINSK portage WNT |
33 | 15-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH |
34 | 22-04-96 : FMN ; Ajout TelReadImage TelDrawImage |
35 | 10-05-96 : CAL ; Ajout d'un nouveau delta dans les copies |
36 | de pixels (voir CALL_DEF_DELTA) |
37 | 25-06-96 : FMN ; Suppression utilisation de glScissor. |
38 | 02-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth |
39 | Suppression glViewport inutile. |
40 | 18-07-96 : FMN ; Suppression TelFlush inutile. |
41 | 08-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle |
42 | version de ogldebug. |
43 | 24-10-96 : CAL ; Portage WNT |
44 | 23-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers |
45 | 30-01-97 : FMN ; Ajout commentaires + WNT. |
46 | 12-02-97 : FMN ; Suppression TelEnquireFacilities() |
47 | 22-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer |
48 | 30-06-97 : FMN ; Suppression OpenGl_telem_light.h |
49 | 18-07-97 : FMN ; Utilisation de la toolkit sur les lights |
50 | 07-10-97 : FMN ; Simplification WNT + correction Transient |
51 | 05-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject |
52 | 23-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri |
53 | 30-12-97 : FMN ; CTS18312: Correction back material |
54 | 04-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899) |
55 | 30-09-98 : CAL ; Optimisation pour eviter de charger inutilement |
56 | les matrices de la vue. |
57 | 19-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela |
58 | rentre en conflit avec l'utilisation d'une image de fond. |
59 | 02.14.100 : JR : Warnings on WNT truncations from double to float |
60 | 08-03-01 : GG ; BUC60823 Avoid crash in the normal computation method |
61 | when a face has confused or aligned points. |
62 | |
63 | ************************************************************************/ |
64 | |
d64e6d05 |
65 | #include <stdio.h> |
66 | |
5f8b738e |
67 | #include <OpenGl_GlCore11.hxx> |
7fd59977 |
68 | |
7fd59977 |
69 | #include <OpenGl_telem_util.hxx> |
2166f0fa |
70 | #include <InterfaceGraphic_Graphic3d.hxx> |
7fd59977 |
71 | |
7fd59977 |
72 | #define GPRECIS 0.000001 |
73 | Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) { |
74 | Tint status=0; |
75 | |
76 | norm[0] = norm[1] = norm[2] = 0.; |
77 | if( npnt > 2 ) { |
78 | Tfloat a[3], b[3], c[3]; |
79 | Tint i,j,i0,ii=0,jj; |
80 | |
81 | i0 = 0; if( indexs ) i0 = indexs[0]; |
82 | for( i=1 ; i<npnt ; i++ ) { |
83 | ii = i; if( indexs ) ii = indexs[i]; |
84 | vecsub( a, pnts[ii].xyz, pnts[i0].xyz ); |
85 | if( vecmg2(a) > GPRECIS ) break; |
86 | } |
87 | if( i < npnt-1 ) { |
88 | for( j=i+1 ; j<npnt ; j++ ) { |
89 | jj = j; if( indexs ) jj = indexs[j]; |
90 | vecsub( b, pnts[jj].xyz, pnts[i0].xyz ); |
91 | vecsub( c, pnts[jj].xyz, pnts[ii].xyz ); |
92 | if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break; |
93 | } |
94 | if( j < npnt ) { |
95 | Tfloat d; |
96 | veccrs( norm, a, b ); |
97 | d = vecnrmd( norm, d ); |
98 | status = (d > 0.) ? 1 : 0; |
99 | } |
100 | } |
101 | } |
0797d9d3 |
102 | #ifdef OCCT_DEBUG |
7fd59977 |
103 | if( !status ) |
104 | printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n"); |
105 | #endif |
106 | |
107 | return status; |
108 | } |
109 | |
110 | Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) { |
111 | Tfloat a[3], b[3]; |
112 | Tint status=0; |
113 | |
114 | norm[0] = norm[1] = norm[2] = 0.; |
115 | vecsub( a, data2, data1 ); |
116 | vecsub( b, data3, data2 ); |
117 | if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) { |
118 | Tfloat d; |
119 | veccrs( norm, a, b ); |
120 | d = vecnrmd( norm, d ); |
121 | status = (d > 0.) ? 1 : 0; |
122 | } |
0797d9d3 |
123 | #ifdef OCCT_DEBUG |
7fd59977 |
124 | if( !status ) |
125 | printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n"); |
126 | #endif |
127 | |
128 | return status; |
129 | } |
7fd59977 |
130 | |
2166f0fa |
131 | void TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b) |
7fd59977 |
132 | { |
133 | Tint row, col, i; |
134 | Tmatrix3 res; |
135 | Tint dim = 4; |
136 | |
137 | /* on multiplie d'abord les 2 matrices dim x dim */ |
138 | for (row = 0; row < dim; row++) { |
139 | for (col = 0; col < dim; col++) { |
140 | Tfloat sum = ( float )0.0; |
141 | for (i = 0; i < dim; i++) |
142 | sum += a[row][i] * b[i][col]; |
143 | res[row][col] = sum; |
144 | } |
145 | } |
146 | |
147 | /* on copie ensuite le resultat */ |
148 | matcpy (c, res); |
149 | |
150 | return; |
151 | } |