0022819: Redesign of OpenGl driver
[occt.git] / src / OpenGl / OpenGl_telem_util.cxx
CommitLineData
7fd59977 1/***********************************************************************
2
3FONCTION :
4----------
5File OpenGl_telem_util :
6
7
8REMARQUES:
9----------
10
11
12HISTORIQUE DES MODIFICATIONS :
13--------------------------------
14xx-xx-xx : xxx ; Creation.
1507-02-96 : FMN ; - Ajout trace
16- Suppression code inutile
1708-03-96 : FMN ; - Ajout include manquant
1801-04-96 : CAL ; Integration MINSK portage WNT
1915-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
2022-04-96 : FMN ; Ajout TelReadImage TelDrawImage
2110-05-96 : CAL ; Ajout d'un nouveau delta dans les copies
22de pixels (voir CALL_DEF_DELTA)
2325-06-96 : FMN ; Suppression utilisation de glScissor.
2402-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth
25Suppression glViewport inutile.
2618-07-96 : FMN ; Suppression TelFlush inutile.
2708-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle
28version de ogldebug.
2924-10-96 : CAL ; Portage WNT
3023-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers
3130-01-97 : FMN ; Ajout commentaires + WNT.
3212-02-97 : FMN ; Suppression TelEnquireFacilities()
3322-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer
3430-06-97 : FMN ; Suppression OpenGl_telem_light.h
3518-07-97 : FMN ; Utilisation de la toolkit sur les lights
3607-10-97 : FMN ; Simplification WNT + correction Transient
3705-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject
3823-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri
3930-12-97 : FMN ; CTS18312: Correction back material
4004-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899)
4130-09-98 : CAL ; Optimisation pour eviter de charger inutilement
42les matrices de la vue.
4319-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela
44rentre en conflit avec l'utilisation d'une image de fond.
4502.14.100 : JR : Warnings on WNT truncations from double to float
4608-03-01 : GG ; BUC60823 Avoid crash in the normal computation method
47when a face has confused or aligned points.
48
49************************************************************************/
50
51#define IMP190100 /*GG To avoid too many REDRAW in immediat mode,
52// Add TelMakeFrontAndBackBufCurrent() function
53*/
54#define QTOCC_PATCH
55
56/*----------------------------------------------------------------------*/
57/*
58* Includes
59*/
60
61#include <string.h>
62#include <stdio.h>
63#include <stdlib.h>
64
65#ifndef WNT
66# include <X11/Xlib.h>
67#else
68# define STRICT
69# include <windows.h>
70#endif /* WNT */
71
72
73#include <GL/gl.h>
74#include <GL/glu.h>
75#ifndef WNT
76#include <GL/glx.h>
77#endif /* WNT */
78
7fd59977 79#include <OpenGl_tgl_all.hxx>
7fd59977 80#include <OpenGl_telem_util.hxx>
2166f0fa
SK
81#include <InterfaceGraphic_Graphic3d.hxx>
82#include <InterfaceGraphic_Visual3d.hxx>
7fd59977 83
7fd59977 84#define GPRECIS 0.000001
85Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) {
86 Tint status=0;
87
88 norm[0] = norm[1] = norm[2] = 0.;
89 if( npnt > 2 ) {
90 Tfloat a[3], b[3], c[3];
91 Tint i,j,i0,ii=0,jj;
92
93 i0 = 0; if( indexs ) i0 = indexs[0];
94 for( i=1 ; i<npnt ; i++ ) {
95 ii = i; if( indexs ) ii = indexs[i];
96 vecsub( a, pnts[ii].xyz, pnts[i0].xyz );
97 if( vecmg2(a) > GPRECIS ) break;
98 }
99 if( i < npnt-1 ) {
100 for( j=i+1 ; j<npnt ; j++ ) {
101 jj = j; if( indexs ) jj = indexs[j];
102 vecsub( b, pnts[jj].xyz, pnts[i0].xyz );
103 vecsub( c, pnts[jj].xyz, pnts[ii].xyz );
104 if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break;
105 }
106 if( j < npnt ) {
107 Tfloat d;
108 veccrs( norm, a, b );
109 d = vecnrmd( norm, d );
110 status = (d > 0.) ? 1 : 0;
111 }
112 }
113 }
114#ifdef DEB
115 if( !status )
116 printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n");
117#endif
118
119 return status;
120}
121
122Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
123 Tfloat a[3], b[3];
124 Tint status=0;
125
126 norm[0] = norm[1] = norm[2] = 0.;
127 vecsub( a, data2, data1 );
128 vecsub( b, data3, data2 );
129 if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) {
130 Tfloat d;
131 veccrs( norm, a, b );
132 d = vecnrmd( norm, d );
133 status = (d > 0.) ? 1 : 0;
134 }
135#ifdef DEB
136 if( !status )
137 printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n");
138#endif
139
140 return status;
141}
7fd59977 142
2166f0fa 143void TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b)
7fd59977 144{
145 Tint row, col, i;
146 Tmatrix3 res;
147 Tint dim = 4;
148
149 /* on multiplie d'abord les 2 matrices dim x dim */
150 for (row = 0; row < dim; row++) {
151 for (col = 0; col < dim; col++) {
152 Tfloat sum = ( float )0.0;
153 for (i = 0; i < dim; i++)
154 sum += a[row][i] * b[i][col];
155 res[row][col] = sum;
156 }
157 }
158
159 /* on copie ensuite le resultat */
160 matcpy (c, res);
161
162 return;
163}