7fd59977 |
1 | /*********************************************************************** |
2 | |
3 | FONCTION : |
4 | ---------- |
5 | File Include OpenGl_telem_util : |
6 | |
7 | |
8 | REMARQUES: |
9 | ---------- |
10 | |
11 | |
12 | HISTORIQUE DES MODIFICATIONS : |
13 | -------------------------------- |
14 | xx-xx-xx : xxx ; Creation. |
15 | 22-04-96 : FMN ; Ajout TelReadImage TelDrawImage |
16 | 23-12-96 : CAL ; Probleme dans la macro vecmag |
17 | 12-02-97 : FMN ; Suppression TelEnquireFacilities() |
18 | 07-10-97 : FMN ; Simplification WNT |
19 | 23-12-97 : FMN ; Suppression TelBackInteriorStyle, TelBackInteriorStyleIndex |
20 | |
21 | ************************************************************************/ |
22 | |
23 | #ifndef OPENGL_TELEM_UTIL_H |
24 | #define OPENGL_TELEM_UTIL_H |
25 | |
26 | #ifndef IMP190100 |
27 | #define IMP190100 /*GG To avoid too many REDRAW in immediat mode, |
28 | // Add TelMakeFrontAndBackBufCurrent() function |
29 | */ |
30 | #endif |
31 | |
32 | #define BUC60823 /* GG 05/03/01 Avoid to crash in normal computation |
33 | // between confused points |
34 | */ |
35 | |
36 | #include <math.h> |
37 | #include <GL/gl.h> |
38 | #ifndef WNT |
39 | #include <GL/glx.h> |
40 | #endif |
2166f0fa |
41 | #include <InterfaceGraphic_telem.hxx> |
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 */ |
81 | #define vecmag(a) (sqrt((double)vecmg2(a))) |
82 | |
83 | /* normalize */ |
84 | #ifdef BUC60823 |
85 | #define vecnrmd(a,d) ( d = (Tfloat)vecmag(a), \ |
86 | ( d > 1e-10 ? (a[0] /= d, a[1] /= d, a[2] /= d, d) : (Tfloat)0. ) ) |
87 | #define vecnrm(a) { Tfloat d; vecnrmd(a,d); } |
88 | #else |
89 | #define vecnrm(a) { Tfloat d; d = ( Tfloat )vecmag(a); \ |
90 | (a)[0] /= d; (a)[1] /= d; (a)[2] /= d; } |
91 | #endif |
92 | |
93 | /* angle between two vectors */ |
94 | #define vecang(a,b,d) { d = (Tfloat)(vecmag(a)*vecmag(b)); \ |
95 | d = vecdot(a,b)/d; \ |
96 | d = d < -1.0F ? -1.0F : d > 1.0F ? 1.0F : d; \ |
97 | d = ( Tfloat )acos(d); } |
98 | |
99 | /* point along a vector at a distance */ |
100 | #define vecgnd(a,b,c,d) { Tfloat w; w = d/vecmag(c); \ |
101 | (a)[0] = (b)[0]+(c)[0]*w; \ |
102 | (a)[1] = (b)[1]+(c)[1]*w; \ |
103 | (a)[2] = (b)[2]+(c)[2]*w; } |
104 | /* copy */ |
105 | #define veccpy(a,b) ((a)[0]=(b)[0],(a)[1]=(b)[1],(a)[2]=(b)[2]) |
106 | |
107 | /* end vector macros */ |
108 | |
109 | typedef struct |
110 | { |
111 | Tmatrix3 mat; |
112 | } |
113 | Tmatrix3Struct; |
114 | |
115 | #define matcpy(d,s) { *((Tmatrix3Struct*)(d)) = *((Tmatrix3Struct*)(s)); } |
116 | /* |
117 | (d)[0][0]=(s)[0][0],(d)[0][1]=(s)[0][1],(d)[0][2]=(s)[0][2],(d)[0][3]=(s)[0][3], |
118 | (d)[1][0]=(s)[1][0],(d)[1][1]=(s)[1][1],(d)[1][2]=(s)[1][2],(d)[1][3]=(s)[1][3], |
119 | (d)[2][0]=(s)[2][0],(d)[2][1]=(s)[2][1],(d)[2][2]=(s)[2][2],(d)[2][3]=(s)[2][3], |
120 | (d)[3][0]=(s)[3][0],(d)[3][1]=(s)[3][1],(d)[3][2]=(s)[3][2],(d)[3][3]=(s)[3][3] |
121 | */ |
122 | |
123 | #define matdump(m) { \ |
124 | int i, j; \ |
125 | for (i=0; i<4; i++) {\ |
126 | printf ("\t"); \ |
127 | for (j=0; j<4; j++) \ |
128 | printf ("%f ", m[i][j]); \ |
129 | printf ("\n"); \ |
130 | } \ |
131 | } |
132 | |
7fd59977 |
133 | extern int TelGetPolygonNormal( tel_point, Tint*, Tint, Tfloat* ); |
134 | extern int TelGetNormal( Tfloat*, Tfloat*, Tfloat*, Tfloat* ); |
7fd59977 |
135 | extern void TelMultiplymat3( Tmatrix3, Tmatrix3, Tmatrix3 ); |
7fd59977 |
136 | |
137 | #endif |