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 | |
2166f0fa |
26 | #include <InterfaceGraphic_telem.hxx> |
5f8b738e |
27 | #include <cmath> |
7fd59977 |
28 | |
29 | /* |
30 | * ShortRealLast () = 3.40282346638528860e+38 |
31 | * ShortRealFirst () = 3.40282346638528860e+38 |
32 | */ |
33 | #define shortreallast() (3.e+38) |
34 | #define shortrealfirst() (-3.e+38) |
35 | |
36 | /* vector manipulation macros */ |
37 | #define square(a) ((a)*(a)) |
38 | |
39 | /* add */ |
40 | #define vecadd(a,b,c) { (a)[0]=(b)[0]+(c)[0]; \ |
41 | (a)[1]=(b)[1]+(c)[1]; \ |
42 | (a)[2]=(b)[2]+(c)[2]; } |
43 | |
44 | /* subtract */ |
45 | #define vecsub(a,b,c) { (a)[0]=(b)[0]-(c)[0]; \ |
46 | (a)[1]=(b)[1]-(c)[1]; \ |
47 | (a)[2]=(b)[2]-(c)[2]; } |
48 | |
49 | /* dot product */ |
50 | #define vecdot(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) |
51 | |
52 | /* cross product */ |
53 | #define veccrs(a,b,c) { Tfloat x, y, z; \ |
54 | x = (b)[1]*(c)[2] - (b)[2]*(c)[1]; \ |
55 | y = (b)[2]*(c)[0] - (b)[0]*(c)[2]; \ |
56 | z = (b)[0]*(c)[1] - (b)[1]*(c)[0]; \ |
57 | (a)[0] = x; \ |
58 | (a)[1] = y; \ |
59 | (a)[2] = z; } |
60 | /* scale */ |
61 | #define vecscl(a,b) { (b)[0] *= (a); (b)[1] *= (a); (b)[2] *= (a); } |
62 | |
63 | /* magnitude square */ |
64 | #define vecmg2(a) (square((a)[0])+square((a)[1])+square((a)[2])) |
65 | |
66 | /* magnitude */ |
5f8b738e |
67 | #define vecmag(a) (std::sqrt((double)vecmg2(a))) |
7fd59977 |
68 | |
69 | /* normalize */ |
7fd59977 |
70 | #define vecnrmd(a,d) ( d = (Tfloat)vecmag(a), \ |
71 | ( d > 1e-10 ? (a[0] /= d, a[1] /= d, a[2] /= d, d) : (Tfloat)0. ) ) |
72 | #define vecnrm(a) { Tfloat d; vecnrmd(a,d); } |
7fd59977 |
73 | |
74 | /* angle between two vectors */ |
75 | #define vecang(a,b,d) { d = (Tfloat)(vecmag(a)*vecmag(b)); \ |
76 | d = vecdot(a,b)/d; \ |
77 | d = d < -1.0F ? -1.0F : d > 1.0F ? 1.0F : d; \ |
78 | d = ( Tfloat )acos(d); } |
79 | |
80 | /* point along a vector at a distance */ |
81 | #define vecgnd(a,b,c,d) { Tfloat w; w = d/vecmag(c); \ |
82 | (a)[0] = (b)[0]+(c)[0]*w; \ |
83 | (a)[1] = (b)[1]+(c)[1]*w; \ |
84 | (a)[2] = (b)[2]+(c)[2]*w; } |
85 | /* copy */ |
86 | #define veccpy(a,b) ((a)[0]=(b)[0],(a)[1]=(b)[1],(a)[2]=(b)[2]) |
87 | |
88 | /* end vector macros */ |
89 | |
90 | typedef struct |
91 | { |
92 | Tmatrix3 mat; |
93 | } |
94 | Tmatrix3Struct; |
95 | |
96 | #define matcpy(d,s) { *((Tmatrix3Struct*)(d)) = *((Tmatrix3Struct*)(s)); } |
97 | /* |
98 | (d)[0][0]=(s)[0][0],(d)[0][1]=(s)[0][1],(d)[0][2]=(s)[0][2],(d)[0][3]=(s)[0][3], |
99 | (d)[1][0]=(s)[1][0],(d)[1][1]=(s)[1][1],(d)[1][2]=(s)[1][2],(d)[1][3]=(s)[1][3], |
100 | (d)[2][0]=(s)[2][0],(d)[2][1]=(s)[2][1],(d)[2][2]=(s)[2][2],(d)[2][3]=(s)[2][3], |
101 | (d)[3][0]=(s)[3][0],(d)[3][1]=(s)[3][1],(d)[3][2]=(s)[3][2],(d)[3][3]=(s)[3][3] |
102 | */ |
103 | |
104 | #define matdump(m) { \ |
105 | int i, j; \ |
106 | for (i=0; i<4; i++) {\ |
107 | printf ("\t"); \ |
108 | for (j=0; j<4; j++) \ |
109 | printf ("%f ", m[i][j]); \ |
110 | printf ("\n"); \ |
111 | } \ |
112 | } |
113 | |
7fd59977 |
114 | extern int TelGetPolygonNormal( tel_point, Tint*, Tint, Tfloat* ); |
115 | extern int TelGetNormal( Tfloat*, Tfloat*, Tfloat*, Tfloat* ); |
7fd59977 |
116 | extern void TelMultiplymat3( Tmatrix3, Tmatrix3, Tmatrix3 ); |
7fd59977 |
117 | |
118 | #endif |