0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[occt.git] / src / OpenGl / OpenGl_telem_util.cxx
CommitLineData
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
17FONCTION :
18----------
19File OpenGl_telem_util :
20
21
22REMARQUES:
23----------
24
25
26HISTORIQUE DES MODIFICATIONS :
27--------------------------------
28xx-xx-xx : xxx ; Creation.
2907-02-96 : FMN ; - Ajout trace
30- Suppression code inutile
3108-03-96 : FMN ; - Ajout include manquant
3201-04-96 : CAL ; Integration MINSK portage WNT
3315-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
3422-04-96 : FMN ; Ajout TelReadImage TelDrawImage
3510-05-96 : CAL ; Ajout d'un nouveau delta dans les copies
36de pixels (voir CALL_DEF_DELTA)
3725-06-96 : FMN ; Suppression utilisation de glScissor.
3802-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth
39Suppression glViewport inutile.
4018-07-96 : FMN ; Suppression TelFlush inutile.
4108-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle
42version de ogldebug.
4324-10-96 : CAL ; Portage WNT
4423-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers
4530-01-97 : FMN ; Ajout commentaires + WNT.
4612-02-97 : FMN ; Suppression TelEnquireFacilities()
4722-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer
4830-06-97 : FMN ; Suppression OpenGl_telem_light.h
4918-07-97 : FMN ; Utilisation de la toolkit sur les lights
5007-10-97 : FMN ; Simplification WNT + correction Transient
5105-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject
5223-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri
5330-12-97 : FMN ; CTS18312: Correction back material
5404-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899)
5530-09-98 : CAL ; Optimisation pour eviter de charger inutilement
56les matrices de la vue.
5719-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela
58rentre en conflit avec l'utilisation d'une image de fond.
5902.14.100 : JR : Warnings on WNT truncations from double to float
6008-03-01 : GG ; BUC60823 Avoid crash in the normal computation method
61when 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
SK
70#include <InterfaceGraphic_Graphic3d.hxx>
71#include <InterfaceGraphic_Visual3d.hxx>
7fd59977 72
7fd59977 73#define GPRECIS 0.000001
74Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) {
75 Tint status=0;
76
77 norm[0] = norm[1] = norm[2] = 0.;
78 if( npnt > 2 ) {
79 Tfloat a[3], b[3], c[3];
80 Tint i,j,i0,ii=0,jj;
81
82 i0 = 0; if( indexs ) i0 = indexs[0];
83 for( i=1 ; i<npnt ; i++ ) {
84 ii = i; if( indexs ) ii = indexs[i];
85 vecsub( a, pnts[ii].xyz, pnts[i0].xyz );
86 if( vecmg2(a) > GPRECIS ) break;
87 }
88 if( i < npnt-1 ) {
89 for( j=i+1 ; j<npnt ; j++ ) {
90 jj = j; if( indexs ) jj = indexs[j];
91 vecsub( b, pnts[jj].xyz, pnts[i0].xyz );
92 vecsub( c, pnts[jj].xyz, pnts[ii].xyz );
93 if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break;
94 }
95 if( j < npnt ) {
96 Tfloat d;
97 veccrs( norm, a, b );
98 d = vecnrmd( norm, d );
99 status = (d > 0.) ? 1 : 0;
100 }
101 }
102 }
103#ifdef DEB
104 if( !status )
105 printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n");
106#endif
107
108 return status;
109}
110
111Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
112 Tfloat a[3], b[3];
113 Tint status=0;
114
115 norm[0] = norm[1] = norm[2] = 0.;
116 vecsub( a, data2, data1 );
117 vecsub( b, data3, data2 );
118 if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) {
119 Tfloat d;
120 veccrs( norm, a, b );
121 d = vecnrmd( norm, d );
122 status = (d > 0.) ? 1 : 0;
123 }
124#ifdef DEB
125 if( !status )
126 printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n");
127#endif
128
129 return status;
130}
7fd59977 131
2166f0fa 132void TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b)
7fd59977 133{
134 Tint row, col, i;
135 Tmatrix3 res;
136 Tint dim = 4;
137
138 /* on multiplie d'abord les 2 matrices dim x dim */
139 for (row = 0; row < dim; row++) {
140 for (col = 0; col < dim; col++) {
141 Tfloat sum = ( float )0.0;
142 for (i = 0; i < dim; i++)
143 sum += a[row][i] * b[i][col];
144 res[row][col] = sum;
145 }
146 }
147
148 /* on copie ensuite le resultat */
149 matcpy (c, res);
150
151 return;
152}