0023316: OpenGl package can not be compiled on RedHat40-64
[occt.git] / src / OpenGl / OpenGl_telem_util.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19/***********************************************************************
20
21FONCTION :
22----------
23File OpenGl_telem_util :
24
25
26REMARQUES:
27----------
28
29
30HISTORIQUE DES MODIFICATIONS :
31--------------------------------
32xx-xx-xx : xxx ; Creation.
3307-02-96 : FMN ; - Ajout trace
34- Suppression code inutile
3508-03-96 : FMN ; - Ajout include manquant
3601-04-96 : CAL ; Integration MINSK portage WNT
3715-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
3822-04-96 : FMN ; Ajout TelReadImage TelDrawImage
3910-05-96 : CAL ; Ajout d'un nouveau delta dans les copies
40de pixels (voir CALL_DEF_DELTA)
4125-06-96 : FMN ; Suppression utilisation de glScissor.
4202-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth
43Suppression glViewport inutile.
4418-07-96 : FMN ; Suppression TelFlush inutile.
4508-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle
46version de ogldebug.
4724-10-96 : CAL ; Portage WNT
4823-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers
4930-01-97 : FMN ; Ajout commentaires + WNT.
5012-02-97 : FMN ; Suppression TelEnquireFacilities()
5122-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer
5230-06-97 : FMN ; Suppression OpenGl_telem_light.h
5318-07-97 : FMN ; Utilisation de la toolkit sur les lights
5407-10-97 : FMN ; Simplification WNT + correction Transient
5505-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject
5623-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri
5730-12-97 : FMN ; CTS18312: Correction back material
5804-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899)
5930-09-98 : CAL ; Optimisation pour eviter de charger inutilement
60les matrices de la vue.
6119-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela
62rentre en conflit avec l'utilisation d'une image de fond.
6302.14.100 : JR : Warnings on WNT truncations from double to float
6408-03-01 : GG ; BUC60823 Avoid crash in the normal computation method
65when a face has confused or aligned points.
66
67************************************************************************/
68
d64e6d05 69#include <stdio.h>
70
5f8b738e 71#include <OpenGl_GlCore11.hxx>
7fd59977 72
7fd59977 73#include <OpenGl_telem_util.hxx>
2166f0fa
SK
74#include <InterfaceGraphic_Graphic3d.hxx>
75#include <InterfaceGraphic_Visual3d.hxx>
7fd59977 76
7fd59977 77#define GPRECIS 0.000001
78Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) {
79 Tint status=0;
80
81 norm[0] = norm[1] = norm[2] = 0.;
82 if( npnt > 2 ) {
83 Tfloat a[3], b[3], c[3];
84 Tint i,j,i0,ii=0,jj;
85
86 i0 = 0; if( indexs ) i0 = indexs[0];
87 for( i=1 ; i<npnt ; i++ ) {
88 ii = i; if( indexs ) ii = indexs[i];
89 vecsub( a, pnts[ii].xyz, pnts[i0].xyz );
90 if( vecmg2(a) > GPRECIS ) break;
91 }
92 if( i < npnt-1 ) {
93 for( j=i+1 ; j<npnt ; j++ ) {
94 jj = j; if( indexs ) jj = indexs[j];
95 vecsub( b, pnts[jj].xyz, pnts[i0].xyz );
96 vecsub( c, pnts[jj].xyz, pnts[ii].xyz );
97 if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break;
98 }
99 if( j < npnt ) {
100 Tfloat d;
101 veccrs( norm, a, b );
102 d = vecnrmd( norm, d );
103 status = (d > 0.) ? 1 : 0;
104 }
105 }
106 }
107#ifdef DEB
108 if( !status )
109 printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n");
110#endif
111
112 return status;
113}
114
115Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
116 Tfloat a[3], b[3];
117 Tint status=0;
118
119 norm[0] = norm[1] = norm[2] = 0.;
120 vecsub( a, data2, data1 );
121 vecsub( b, data3, data2 );
122 if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) {
123 Tfloat d;
124 veccrs( norm, a, b );
125 d = vecnrmd( norm, d );
126 status = (d > 0.) ? 1 : 0;
127 }
128#ifdef DEB
129 if( !status )
130 printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n");
131#endif
132
133 return status;
134}
7fd59977 135
2166f0fa 136void TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b)
7fd59977 137{
138 Tint row, col, i;
139 Tmatrix3 res;
140 Tint dim = 4;
141
142 /* on multiplie d'abord les 2 matrices dim x dim */
143 for (row = 0; row < dim; row++) {
144 for (col = 0; col < dim; col++) {
145 Tfloat sum = ( float )0.0;
146 for (i = 0; i < dim; i++)
147 sum += a[row][i] * b[i][col];
148 res[row][col] = sum;
149 }
150 }
151
152 /* on copie ensuite le resultat */
153 matcpy (c, res);
154
155 return;
156}