Perspective3D_api
Documentation Perspective3D
perspective_def.h
Aller à la documentation de ce fichier.
1 
19 #ifndef PERSPECTIVE_DEF_H
20 #define PERSPECTIVE_DEF_H
21 
22 #include <string>
23 
24 //#include <limits>
25 #include <new> /* bad_alloc */
26 #include <cfloat>
27 #include <cmath>
28 #include <type_traits> // std::underlying_type
29 #include "perspective_sys.h"
30 
31 #ifdef PSYS_CXX_ICC /* INTEL_COMPILER */
32 #include <mathimf.h>
33 #endif // PSYS_CXX_ICC
34 
35 #ifndef PI
36 #define PI 3.141592653589793238462643
37 #endif // PI
38 
39 #ifndef PIi // (1. / PI)
40 #define PIi 0.3183098861837907
41 #endif // PIi
42 
43 #ifndef RAD // (180. / PI) : 360/RAD = PI2
44 #define RAD 57.29577951308232
45 #endif // RAD
46 
47 #ifndef DTOR // (1. / RAD) : 360*DTOR = PI2
48 #define DTOR 0.017453292519943295
49 #endif // DTOR
50 
51 #define DEG_RAD(x) (x*DTOR)
52 #define RAD_DEG(x) (x*RAD)
53 
54 #ifndef pfloat // Type pour les nombres flottants
55 
56 #if !defined(TYPE_PFLOAT_DOUBLE) && !defined(TYPE_PFLOAT_FLOAT)
57 #define TYPE_PFLOAT_DOUBLE
58 //#define TYPE_PFLOAT_FLOAT
59 #endif // TYPE_PFLOAT_DOUBLE || TYPE_PFLOAT_FLOAT
60 
61 #ifdef TYPE_PFLOAT_DOUBLE
62 typedef double pfloat;
63 #ifndef EPSILON_FIXE
64 #define EPSILON_FIXE 0.0001
65 #endif // EPSILON_FIXE
66 #ifndef EPSILON_FIXE_LARGE
67 #define EPSILON_FIXE_LARGE 0.001
68 #endif // EPSILON_FIXE_LARGE
69 #ifndef MODULOF
70 #define MODULOF fmod
71 #endif // MODULOF
72 #ifndef RCARREF
73 #define RCARREF sqrt
74 #endif // RCARREF
75 #ifndef RCUBIQUE
76 #define RCUBIQUE(X) (pow(X, 1.0/3.0))
77 #endif // RCUBIQUE
78 #ifndef HYPOTF
79 #define HYPOTF hypot
80 #endif // HYPOTF
81 #ifndef POSITIFD
82 #define POSITIFD fabs
83 #endif // POSITIFD
84 #ifndef SINF
85 #define SINF sin
86 #endif // SINF
87 #ifndef ASINF
88 #define ASINF sinf
89 #endif // ASINF
90 #ifndef COSF
91 #define COSF cos
92 #endif // COSF
93 #ifndef ACOSF
94 #define ACOSF acos
95 #endif // ACOSF
96 #ifndef POWF
97 #define POWF pow
98 #endif // POWF
99 #ifndef TANF
100 #define TANF tan
101 #endif // TANF
102 #ifndef ATANF
103 #define ATANF atan
104 #endif // ATANF
105 #ifndef ATAN2F
106 #define ATAN2F atan2
107 #endif // ATAN2F
108 #ifndef FLOORF
109 #define FLOORF floor
110 #endif // FLOORF
111 #ifndef CEILF
112 #define CEILF ceil
113 #endif // CEILF
114 #ifndef PFLOAT_MAX
115 #define PFLOAT_MAX DBL_MAX
116 #endif // PFLOAT_MAX
117 #ifndef PFLOAT_MIN
118 #define PFLOAT_MIN -DBL_MAX
119 #endif // PFLOAT_MIN
120 #else
121 #ifdef TYPE_PFLOAT_FLOAT
122 typedef float pfloat;
123 #ifndef EPSILON_FIXE
124 #define EPSILON_FIXE 0.001
125 #endif // EPSILON_FIXE
126 #ifndef EPSILON_FIXE_LARGE
127 #define EPSILON_FIXE_LARGE 0.005
128 #endif // EPSILON_FIXE_LARGE
129 #ifndef MODULOF
130 #define MODULOF fmodf
131 #endif // MODULOF
132 #ifndef RCARREF
133 #define RCARREF sqrtf
134 #endif // RCARREF
135 #ifndef RCUBIQUE
136 #define RCUBIQUE(X) (powf(X, 1.0f/3.0f))
137 #endif // RCUBIQUE
138 #ifndef HYPOTF
139 #define HYPOTF hypotf
140 #endif // HYPOTF
141 #ifndef POSITIFD
142 #define POSITIFD fabsf
143 #endif // POSITIFD
144 #ifndef SINF
145 #define SINF sinf
146 #endif // SINF
147 #ifndef ASINF
148 #define ASINF asinf
149 #endif // ASINF
150 #ifndef COSF
151 #define COSF cosf
152 #endif // COSF
153 #ifndef ACOSF
154 #define ACOSF acosf
155 #endif // ACOSF
156 #ifndef POWF
157 #define POWF powf
158 #endif // POWF
159 #ifndef TANF
160 #define TANF tanf
161 #endif // TANF
162 #ifndef ATANF
163 #define ATANF atanf
164 #endif // ATANF
165 #ifndef ATAN2F
166 #define ATAN2F atan2f
167 #endif // ATAN2F
168 #ifndef FLOORF
169 #define FLOORF floorf
170 #endif // FLOORF
171 #ifndef CEILF
172 #define CEILF ceilf
173 #endif // CEILF
174 #ifndef PFLOAT_MAX
175 #define PFLOAT_MAX FLT_MAX
176 #endif // PFLOAT_MAX
177 #ifndef PFLOAT_MIN
178 #define PFLOAT_MIN -FLT_MAX
179 #endif // PFLOAT_MIN
180 #else
181 #error "Impossible de définir un type pour les nombres flottants !"
182 #endif // TYPE_PFLOAT_FLOAT
183 #endif // TYPE_PFLOAT_DOUBLE
184 
185 #ifndef pfloatc
186  #define pfloatc const pfloat
187 #endif // pfloatc
188 
189 //#ifndef PFLOAT_MAX
190 //#define PFLOAT_MAX std::numeric_limits<pfloat>::max()
191 //#endif // PFLOAT_MAX
192 //#ifndef PFLOAT_MIN
193 //#define PFLOAT_MIN std::numeric_limits<pfloat>::min()
194 //#endif // PFLOAT_MIN
195 
196 #ifndef POW2
197  #define POW2(X) ((X)*(X))
198 #endif // POW2
199 
200 #ifdef PSYS_WIN_MSVC // Compatibilitée MSVC
201  #ifndef NAN
202  static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
203  #define NAN (*(const float *) __nan)
204  #endif // NAN
205 #endif // PSYS_WIN_MSVC
206 
207 #define PNAN NAN
208 #endif // pfloat
209 
210 #ifdef NAN
211  #if defined(PSYS_CXX_ICC)
212  #define PISNAN(x) (isnan(x))
213  #elif defined(PSYS_CXX_MSVC)
214  #define PISNAN(x) (_isnan(x))
215  #else
216  #define PISNAN(x) (std::isnan(x))
217  #endif // PSYS_CXX_ICC
218 #else
219  #define PISNAN(x) (x!=x)
220 #endif // NAN
221 
222 #ifdef INFINITY
223  #if defined(PSYS_CXX_ICC)
224  #define PISINF(x) isinf(x)
225  #elif defined(PSYS_CXX_MSVC)
226  #define PISINF(x) (!_finite(x))
227  #else
228  //#define PISINF (isinf(x) != 0)
229  #define PISINF(x) std::isinf(x)
230  #endif // PSYS_CXX_ICC
231 #else
232  #define PISINF(x) (fabs(x) > PFLOAT_MAX)
233 #endif // INFINITY
234 
235 #define FPU_ERROR(x) (PISINF(x) || PISNAN(x))
236 
237 #define IDNUL pint(-1)
238 #define IDERR pint(INT32_MAX) // 2147483647
239 
240 #define COORD0 0.
241 #define COORDNUL PFLOAT_MIN
242 #define COORDNULP PFLOAT_MAX
243 
244 #define VUE_EXTRUSION Perspective3D::vues2D_t::VUEHAUT
245 #define VUE_REVOLUTION Perspective3D::vues2D_t::VUECOTE
246 
247 /* Couleurs pour l'affichage 3D (rvb) */
248 #define COULEUR_POINTS 125, 180, 220
249 #define COULEUR_POINTS_F 0.488f, 0.703f, 0.859f
250 
251 #define COULEUR_SELECT_POINTS 28, 115, 176
252 #define COULEUR_SELECT_POINTS_F 0.101f, 0.449f, 0.687f
253 
254 #define COULEUR_SELECT_LIGNES 70, 70, 70
255 #define COULEUR_SELECT_LIGNES_F 0.274f, 0.274f, 0.274f
256 
257 #define COULEUR_LIGNES 130, 130, 130 /* Lignes de contour des surfaces. */
258 #define COULEUR_LIGNES_F 0.508f, 0.508f, 0.508f
259 
260 //#define COULEUR_LIGNES 50, 50, 50 /* Lignes de contour des surfaces. */
261 //#define COULEUR_LIGNES_F 0.196f, 0.196f, 0.196f
262 
263 #define COULEUR_ARRETES 120, 120, 120 /* Couleur des arrêtes des polygones (triangles) */
264 #define COULEUR_ARRETES_F 0.469f, 0.469f, 0.469f
265 
266 #define COULEUR_REP_SURFACES 130, 40, 200
267 #define COULEUR_REP_SURFACES_F 0.508f, 0.156f, 0.781f
268 
269 /* Tolérances et epsilons dynamiques */
270 namespace Perspective3D
271 {
272  namespace TolerancesP3D
273  {
290 
291  inline void Init(pfloat t_xyz)
292  {
298  }
299  }
300 
302  /* Destiné à être hérité pour surcharger les opérations new/delete et inclure les objets dans le gestionnaire de mémoire. */
303  {
304  public:
305  PBase();
306  ~PBase();
307  static void *operator new(std::size_t taille);
308  static void *operator new[](std::size_t taille);
309  static void operator delete(void *p);
310  static void operator delete[](void *p);
311  };
312 }
313 
314 
315 #ifndef CompareX
316 #define CompareX(a, b, c) (POSITIFD((a-b)) < c) /* Comparaison avec l'espilon donné en argument. */
317 //#define CompareX(a, b, c) ((a==b) || POSITIFD(a-b) < c) /* Comparaison avec l'espilon donné en argument. */
318 #endif // !CompareX
319 
320 #ifndef CompareE
321 #define CompareE(a, b) (CompareX(a, b, EPSILON_FIXE)) /* Comparaison avec Epsilon fixe */
322 #endif // !CompareE
323 #ifndef CompareED
324 #define CompareED(a, b) (CompareX(a, b, EPSILON_FIXE_LARGE)) /* Comparaison avec Epsilon fixe élargi */
325 #endif // !CompareED
326 #ifndef CompareN
327 #define CompareN(a, b) (CompareX(a, b, TolerancesP3D::ToleranceCoords)) /* Comparaison approximative générale (défini par l'utilisateur) */
328 #endif // !CompareN
329 
330 /* Déclaration des opérateurs pour les types énumérés. */
331 #define PENUM_DECL_OPS(NOM) \
332  F_INLINE NOM operator| (NOM c1, NOM c2) { return static_cast<NOM>(static_cast<std::underlying_type<NOM>::type>(c1) | static_cast<std::underlying_type<NOM>::type>(c2)); } \
333  F_INLINE NOM operator|= (NOM &c1, NOM c2) { c1 = static_cast<NOM>(static_cast<std::underlying_type<NOM>::type>(c1) | static_cast<std::underlying_type<NOM>::type>(c2)); return c1; } \
334  F_INLINE NOM operator&= (NOM &c1, NOM c2) { c1 = static_cast<NOM>(static_cast<std::underlying_type<NOM>::type>(c1) & static_cast<std::underlying_type<NOM>::type>(c2)); return c1; } \
335  F_INLINE unsigned int operator& (NOM c1, NOM c2) { return (static_cast<unsigned int>(c1) & static_cast<unsigned int>(c2)); } \
336  F_INLINE bool operator== (NOM c1, NOM c2) { return (static_cast<std::underlying_type<NOM>::type>(c1) == static_cast<std::underlying_type<NOM>::type>(c2)); } \
337  F_INLINE NOM operator^ (NOM c1, NOM c2) { return static_cast<NOM>(static_cast<std::underlying_type<NOM>::type>(c1) ^ static_cast<std::underlying_type<NOM>::type>(c2)); } \
338  F_INLINE NOM operator^= (NOM &c1, NOM c2) { c1 = static_cast<NOM>(static_cast<std::underlying_type<NOM>::type>(c1) ^ static_cast<std::underlying_type<NOM>::type>(c2)); return c1; }
339 
340 /* Conversion type énuméré->int */
341 #define PENUM_CAST_INT(VAL) static_cast<puint>(VAL)
342 
343 #endif // PERSPECTIVE_DEF_H
PSYS_TLS pfloat ToleranceCoords
Espace de nom de l&#39;API 3D.
Definition: perspective_api.h:101
PSYS_TLS pfloat ToleranceCoords_Z
#define DLL_API
Attribut de classe ou méthode exportée par l&#39;API (GCC, Clang ou MSVC). Donc importé côté client...
Definition: perspective_sys.h:524
PSYS_TLS pfloat ToleranceCoords_Y
#define PSYS_TLS
Qualificatif variable locale à un thread (GCC, Clang ou MSVC).
Definition: perspective_sys.h:396
PSYS_TLS pfloat ToleranceCoords_X
double pfloat
Definition: perspective_def.h:62
Definition: perspective_def.h:301
PSYS_TLS pfloat ToleranceCoordsLarge
Détection de la plateforme.
void Init(pfloat t_xyz)
Definition: perspective_def.h:291
PSYS_TLS pfloat EpsilonCoords
PSYS_TLS pfloat EpsilonVecteurs
PSYS_TLS pfloat EpsilonAngles