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 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public version 2.1 as published |
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 Include OpenGl_telem_util : |
20 | |
21 | |
22 | REMARQUES: |
23 | ---------- |
24 | |
25 | |
26 | HISTORIQUE DES MODIFICATIONS : |
27 | -------------------------------- |
28 | xx-xx-xx : xxx ; Creation. |
29 | 22-04-96 : FMN ; Ajout TelReadImage TelDrawImage |
30 | 23-12-96 : CAL ; Probleme dans la macro vecmag |
31 | 12-02-97 : FMN ; Suppression TelEnquireFacilities() |
32 | 07-10-97 : FMN ; Simplification WNT |
33 | 23-12-97 : FMN ; Suppression TelBackInteriorStyle, TelBackInteriorStyleIndex |
34 | |
35 | ************************************************************************/ |
36 | |
37 | #ifndef OPENGL_TELEM_UTIL_H |
38 | #define OPENGL_TELEM_UTIL_H |
39 | |
2166f0fa |
40 | #include <InterfaceGraphic_telem.hxx> |
5f8b738e |
41 | #include <cmath> |
7fd59977 |
42 | |
43 | /* |
44 | * ShortRealLast () = 3.40282346638528860e+38 |
45 | * ShortRealFirst () = 3.40282346638528860e+38 |
46 | */ |
47 | #define shortreallast() (3.e+38) |
48 | #define shortrealfirst() (-3.e+38) |
49 | |
50 | /* vector manipulation macros */ |
51 | #define square(a) ((a)*(a)) |
52 | |
53 | /* add */ |
54 | #define vecadd(a,b,c) { (a)[0]=(b)[0]+(c)[0]; \ |
55 | (a)[1]=(b)[1]+(c)[1]; \ |
56 | (a)[2]=(b)[2]+(c)[2]; } |
57 | |
58 | /* subtract */ |
59 | #define vecsub(a,b,c) { (a)[0]=(b)[0]-(c)[0]; \ |
60 | (a)[1]=(b)[1]-(c)[1]; \ |
61 | (a)[2]=(b)[2]-(c)[2]; } |
62 | |
63 | /* dot product */ |
64 | #define vecdot(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) |
65 | |
66 | /* cross product */ |
67 | #define veccrs(a,b,c) { Tfloat x, y, z; \ |
68 | x = (b)[1]*(c)[2] - (b)[2]*(c)[1]; \ |
69 | y = (b)[2]*(c)[0] - (b)[0]*(c)[2]; \ |
70 | z = (b)[0]*(c)[1] - (b)[1]*(c)[0]; \ |
71 | (a)[0] = x; \ |
72 | (a)[1] = y; \ |
73 | (a)[2] = z; } |
74 | /* scale */ |
75 | #define vecscl(a,b) { (b)[0] *= (a); (b)[1] *= (a); (b)[2] *= (a); } |
76 | |
77 | /* magnitude square */ |
78 | #define vecmg2(a) (square((a)[0])+square((a)[1])+square((a)[2])) |
79 | |
80 | /* magnitude */ |
5f8b738e |
81 | #define vecmag(a) (std::sqrt((double)vecmg2(a))) |
7fd59977 |
82 | |
83 | /* normalize */ |
7fd59977 |
84 | #define vecnrmd(a,d) ( d = (Tfloat)vecmag(a), \ |
85 | ( d > 1e-10 ? (a[0] /= d, a[1] /= d, a[2] /= d, d) : (Tfloat)0. ) ) |
86 | #define vecnrm(a) { Tfloat d; vecnrmd(a,d); } |
7fd59977 |
87 | |
88 | /* angle between two vectors */ |
89 | #define vecang(a,b,d) { d = (Tfloat)(vecmag(a)*vecmag(b)); \ |
90 | d = vecdot(a,b)/d; \ |
91 | d = d < -1.0F ? -1.0F : d > 1.0F ? 1.0F : d; \ |
92 | d = ( Tfloat )acos(d); } |
93 | |
94 | /* point along a vector at a distance */ |
95 | #define vecgnd(a,b,c,d) { Tfloat w; w = d/vecmag(c); \ |
96 | (a)[0] = (b)[0]+(c)[0]*w; \ |
97 | (a)[1] = (b)[1]+(c)[1]*w; \ |
98 | (a)[2] = (b)[2]+(c)[2]*w; } |
99 | /* copy */ |
100 | #define veccpy(a,b) ((a)[0]=(b)[0],(a)[1]=(b)[1],(a)[2]=(b)[2]) |
101 | |
102 | /* end vector macros */ |
103 | |
104 | typedef struct |
105 | { |
106 | Tmatrix3 mat; |
107 | } |
108 | Tmatrix3Struct; |
109 | |
110 | #define matcpy(d,s) { *((Tmatrix3Struct*)(d)) = *((Tmatrix3Struct*)(s)); } |
111 | /* |
112 | (d)[0][0]=(s)[0][0],(d)[0][1]=(s)[0][1],(d)[0][2]=(s)[0][2],(d)[0][3]=(s)[0][3], |
113 | (d)[1][0]=(s)[1][0],(d)[1][1]=(s)[1][1],(d)[1][2]=(s)[1][2],(d)[1][3]=(s)[1][3], |
114 | (d)[2][0]=(s)[2][0],(d)[2][1]=(s)[2][1],(d)[2][2]=(s)[2][2],(d)[2][3]=(s)[2][3], |
115 | (d)[3][0]=(s)[3][0],(d)[3][1]=(s)[3][1],(d)[3][2]=(s)[3][2],(d)[3][3]=(s)[3][3] |
116 | */ |
117 | |
118 | #define matdump(m) { \ |
119 | int i, j; \ |
120 | for (i=0; i<4; i++) {\ |
121 | printf ("\t"); \ |
122 | for (j=0; j<4; j++) \ |
123 | printf ("%f ", m[i][j]); \ |
124 | printf ("\n"); \ |
125 | } \ |
126 | } |
127 | |
7fd59977 |
128 | extern int TelGetPolygonNormal( tel_point, Tint*, Tint, Tfloat* ); |
129 | extern int TelGetNormal( Tfloat*, Tfloat*, Tfloat*, Tfloat* ); |
7fd59977 |
130 | extern void TelMultiplymat3( Tmatrix3, Tmatrix3, Tmatrix3 ); |
7fd59977 |
131 | |
132 | #endif |