Fri, 15 Mar 2013 20:11:18 +0200
Initial commit
0 | 1 | #ifndef __COMMON_H__ |
2 | #define __COMMON_H__ | |
3 | ||
4 | #define APPNAME "ldforge" | |
5 | #define APPNAME_DISPLAY "LDForge" | |
6 | #define APPNAME_CAPS "LDFORGE" | |
7 | ||
8 | #define VERSION_MAJOR 0 | |
9 | #define VERSION_MAJOR_STR "0" | |
10 | #define VERSION_MINOR 1 | |
11 | #define VERSION_MINOR_STR "1" | |
12 | ||
13 | #define VERSION_STRING VERSION_MAJOR_STR "." VERSION_MINOR_STR | |
14 | ||
15 | #define CONFIG_WITH_QT | |
16 | ||
17 | #include <stdio.h> | |
18 | #include <stdlib.h> | |
19 | #include <assert.h> | |
20 | #include <vector> | |
21 | #include <stdint.h> | |
22 | #include "stdarg.h" | |
23 | #include "str.h" | |
24 | #include "config.h" | |
25 | ||
26 | using std::vector; | |
27 | ||
28 | class LDForgeWindow; | |
29 | class LDObject; | |
30 | class bbox; | |
31 | ||
32 | // ============================================================================= | |
33 | // vertex (v) | |
34 | // | |
35 | // Vertex class. Not to be confused with LDVertex, which is a vertex used in an | |
36 | // LDraw code file. | |
37 | // | |
38 | // Methods: | |
39 | // - midpoint (vertex&): returns a midpoint | |
40 | // ============================================================================= | |
41 | class vertex { | |
42 | public: | |
43 | double x, y, z; | |
44 | ||
45 | // ========================================================================= | |
46 | // Midpoint between this vertex and another vertex. | |
47 | vertex midpoint (vertex& other); | |
48 | str getStringRep (); | |
49 | }; | |
50 | ||
51 | // ============================================================================= | |
52 | // bearing | |
53 | // | |
54 | // A bearing is a combination of an angle and a pitch. Essentially a 3D angle. | |
55 | // The project method projects a vertex from a given vertex by a given length. | |
56 | // | |
57 | // Prefix: g, since b is bool | |
58 | // ============================================================================= | |
59 | class bearing { | |
60 | double fAngle, fPitch; | |
61 | ||
62 | vertex project (vertex& vSource, ulong ulLength); | |
63 | }; | |
64 | ||
65 | // ============================================================================= | |
66 | typedef struct { | |
67 | str filename; | |
68 | vector<LDObject*> objects; | |
69 | } OpenFile; | |
70 | ||
71 | // Plural expression | |
72 | #define PLURAL(n) ((n != 1) ? "s" : "") | |
73 | ||
74 | // Shortcut for formatting | |
75 | #define PERFORM_FORMAT(in, out) \ | |
76 | va_list v; \ | |
77 | va_start (v, in); \ | |
78 | char* out = vdynformat (in, v, 256); \ | |
79 | va_end (v); | |
80 | ||
81 | // Shortcuts for stuffing vertices into printf-formatting. | |
82 | #define FMT_VERTEX "(%.3f, %.3f, %.3f)" | |
83 | #define FVERTEX(V) V.x, V.y, V.z | |
84 | ||
85 | typedef unsigned char byte; | |
86 | ||
87 | template<class T> inline T clamp (T a, T min, T max) { | |
88 | return (a > max) ? max : (a < min) ? min : a; | |
89 | } | |
90 | ||
91 | template<class T> inline T min (T a, T b) { | |
92 | return (a < b) ? a : b; | |
93 | } | |
94 | ||
95 | template<class T> inline T max (T a, T b) { | |
96 | return (a > b) ? a : b; | |
97 | } | |
98 | ||
99 | static const double pi = 3.14159265358979323846f; | |
100 | ||
101 | // main.cpp | |
102 | extern OpenFile* g_CurrentFile; | |
103 | extern bbox g_BBox; | |
104 | extern LDForgeWindow* g_qWindow; | |
105 | extern vector<OpenFile*> g_LoadedFiles; | |
106 | ||
107 | #ifndef unix | |
108 | typedef unsigned int uint; | |
109 | typedef unsigned long ulong; | |
110 | #endif // unix | |
111 | ||
112 | typedef int8_t xchar; | |
113 | typedef int16_t xshort; | |
114 | typedef int32_t xlong; | |
115 | typedef int64_t xlonglong; | |
116 | typedef uint8_t xuchar; | |
117 | typedef uint16_t xushort; | |
118 | typedef uint32_t xulong; | |
119 | typedef uint64_t xulonglong; | |
120 | ||
121 | #endif |