b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | /*********************************************************************** |
20 | |
21 | FONCTION : |
22 | ---------- |
23 | File Include OpenGl_telem_util : |
24 | |
25 | |
26 | REMARQUES: |
27 | ---------- |
28 | |
29 | |
30 | HISTORIQUE DES MODIFICATIONS : |
31 | -------------------------------- |
32 | xx-xx-xx : xxx ; Creation. |
33 | 22-04-96 : FMN ; Ajout TelReadImage TelDrawImage |
34 | 23-12-96 : CAL ; Probleme dans la macro vecmag |
35 | 12-02-97 : FMN ; Suppression TelEnquireFacilities() |
36 | 07-10-97 : FMN ; Simplification WNT |
37 | 23-12-97 : FMN ; Suppression TelBackInteriorStyle, TelBackInteriorStyleIndex |
38 | |
39 | ************************************************************************/ |
40 | |
41 | #ifndef OPENGL_TELEM_UTIL_H |
42 | #define OPENGL_TELEM_UTIL_H |
43 | |
2166f0fa |
44 | #include <InterfaceGraphic_telem.hxx> |
5f8b738e |
45 | #include <cmath> |
7fd59977 |
46 | |
47 | /* |
48 | * ShortRealLast () = 3.40282346638528860e+38 |
49 | * ShortRealFirst () = 3.40282346638528860e+38 |
50 | */ |
51 | #define shortreallast() (3.e+38) |
52 | #define shortrealfirst() (-3.e+38) |
53 | |
54 | /* vector manipulation macros */ |
55 | #define square(a) ((a)*(a)) |
56 | |
57 | /* add */ |
58 | #define vecadd(a,b,c) { (a)[0]=(b)[0]+(c)[0]; \ |
59 | (a)[1]=(b)[1]+(c)[1]; \ |
60 | (a)[2]=(b)[2]+(c)[2]; } |
61 | |
62 | /* subtract */ |
63 | #define vecsub(a,b,c) { (a)[0]=(b)[0]-(c)[0]; \ |
64 | (a)[1]=(b)[1]-(c)[1]; \ |
65 | (a)[2]=(b)[2]-(c)[2]; } |
66 | |
67 | /* dot product */ |
68 | #define vecdot(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) |
69 | |
70 | /* cross product */ |
71 | #define veccrs(a,b,c) { Tfloat x, y, z; \ |
72 | x = (b)[1]*(c)[2] - (b)[2]*(c)[1]; \ |
73 | y = (b)[2]*(c)[0] - (b)[0]*(c)[2]; \ |
74 | z = (b)[0]*(c)[1] - (b)[1]*(c)[0]; \ |
75 | (a)[0] = x; \ |
76 | (a)[1] = y; \ |
77 | (a)[2] = z; } |
78 | /* scale */ |
79 | #define vecscl(a,b) { (b)[0] *= (a); (b)[1] *= (a); (b)[2] *= (a); } |
80 | |
81 | /* magnitude square */ |
82 | #define vecmg2(a) (square((a)[0])+square((a)[1])+square((a)[2])) |
83 | |
84 | /* magnitude */ |
5f8b738e |
85 | #define vecmag(a) (std::sqrt((double)vecmg2(a))) |
7fd59977 |
86 | |
87 | /* normalize */ |
7fd59977 |
88 | #define vecnrmd(a,d) ( d = (Tfloat)vecmag(a), \ |
89 | ( d > 1e-10 ? (a[0] /= d, a[1] /= d, a[2] /= d, d) : (Tfloat)0. ) ) |
90 | #define vecnrm(a) { Tfloat d; vecnrmd(a,d); } |
7fd59977 |
91 | |
92 | /* angle between two vectors */ |
93 | #define vecang(a,b,d) { d = (Tfloat)(vecmag(a)*vecmag(b)); \ |
94 | d = vecdot(a,b)/d; \ |
95 | d = d < -1.0F ? -1.0F : d > 1.0F ? 1.0F : d; \ |
96 | d = ( Tfloat )acos(d); } |
97 | |
98 | /* point along a vector at a distance */ |
99 | #define vecgnd(a,b,c,d) { Tfloat w; w = d/vecmag(c); \ |
100 | (a)[0] = (b)[0]+(c)[0]*w; \ |
101 | (a)[1] = (b)[1]+(c)[1]*w; \ |
102 | (a)[2] = (b)[2]+(c)[2]*w; } |
103 | /* copy */ |
104 | #define veccpy(a,b) ((a)[0]=(b)[0],(a)[1]=(b)[1],(a)[2]=(b)[2]) |
105 | |
106 | /* end vector macros */ |
107 | |
108 | typedef struct |
109 | { |
110 | Tmatrix3 mat; |
111 | } |
112 | Tmatrix3Struct; |
113 | |
114 | #define matcpy(d,s) { *((Tmatrix3Struct*)(d)) = *((Tmatrix3Struct*)(s)); } |
115 | /* |
116 | (d)[0][0]=(s)[0][0],(d)[0][1]=(s)[0][1],(d)[0][2]=(s)[0][2],(d)[0][3]=(s)[0][3], |
117 | (d)[1][0]=(s)[1][0],(d)[1][1]=(s)[1][1],(d)[1][2]=(s)[1][2],(d)[1][3]=(s)[1][3], |
118 | (d)[2][0]=(s)[2][0],(d)[2][1]=(s)[2][1],(d)[2][2]=(s)[2][2],(d)[2][3]=(s)[2][3], |
119 | (d)[3][0]=(s)[3][0],(d)[3][1]=(s)[3][1],(d)[3][2]=(s)[3][2],(d)[3][3]=(s)[3][3] |
120 | */ |
121 | |
122 | #define matdump(m) { \ |
123 | int i, j; \ |
124 | for (i=0; i<4; i++) {\ |
125 | printf ("\t"); \ |
126 | for (j=0; j<4; j++) \ |
127 | printf ("%f ", m[i][j]); \ |
128 | printf ("\n"); \ |
129 | } \ |
130 | } |
131 | |
7fd59977 |
132 | extern int TelGetPolygonNormal( tel_point, Tint*, Tint, Tfloat* ); |
133 | extern int TelGetNormal( Tfloat*, Tfloat*, Tfloat*, Tfloat* ); |
7fd59977 |
134 | extern void TelMultiplymat3( Tmatrix3, Tmatrix3, Tmatrix3 ); |
7fd59977 |
135 | |
136 | #endif |