Sun, 24 Mar 2013 21:41:24 +0200
Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
3 | * Copyright (C) 2013 Santeri `arezey` Piippo |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
18 | |
0 | 19 | #ifndef __COMMON_H__ |
20 | #define __COMMON_H__ | |
21 | ||
22 | #define APPNAME "ldforge" | |
23 | #define APPNAME_DISPLAY "LDForge" | |
24 | #define APPNAME_CAPS "LDFORGE" | |
25 | ||
26 | #define VERSION_MAJOR 0 | |
27 | #define VERSION_MAJOR_STR "0" | |
28 | #define VERSION_MINOR 1 | |
29 | #define VERSION_MINOR_STR "1" | |
30 | ||
31 | #define VERSION_STRING VERSION_MAJOR_STR "." VERSION_MINOR_STR | |
32 | ||
33 | #define CONFIG_WITH_QT | |
34 | ||
35 | #include <stdio.h> | |
36 | #include <stdlib.h> | |
37 | #include <assert.h> | |
38 | #include <vector> | |
39 | #include <stdint.h> | |
40 | #include "stdarg.h" | |
41 | #include "str.h" | |
42 | #include "config.h" | |
64
ada4679d5bce
Considerably improved sub-file inlining. Use a matrix class instead of double[9], educated myself on what matrix multiplication actually is and fixed the algorithm up. Aside from I/O problems, 32551.dat is correctly rendered now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
43 | #include "types.h" |
0 | 44 | |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
45 | #ifdef __GNUC__ |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
46 | #define FORMAT_PRINTF(M,N) __attribute__ ((format (printf, M, N))) |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
47 | #else |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
48 | #define FORMAT_PRINTF(M,N) |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
49 | #endif // __GNUC__ |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
50 | |
29
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
51 | #ifdef WIN32 |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
52 | #define DIRSLASH "\\" |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
53 | #else // WIN32 |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
54 | #define DIRSLASH "/" |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
55 | #endif // WIN32 |
55406ce7446e
Added LDraw path setting dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
56 | |
40
215b9f8f0cd7
Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
57 | static const double fMaxCoord = 10000.0; |
215b9f8f0cd7
Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
58 | static const short dMainColor = 16; |
215b9f8f0cd7
Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
59 | static const short dEdgeColor = 24; |
215b9f8f0cd7
Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
60 | |
0 | 61 | using std::vector; |
62 | ||
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
63 | class ForgeWindow; |
0 | 64 | class LDObject; |
65 | class bbox; | |
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
66 | class OpenFile; |
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
67 | class QApplication; |
0 | 68 | |
69 | // ============================================================================= | |
70 | // Plural expression | |
71 | #define PLURAL(n) ((n != 1) ? "s" : "") | |
72 | ||
73 | // Shortcut for formatting | |
74 | #define PERFORM_FORMAT(in, out) \ | |
75 | va_list v; \ | |
76 | va_start (v, in); \ | |
77 | char* out = vdynformat (in, v, 256); \ | |
78 | va_end (v); | |
79 | ||
80 | // Shortcuts for stuffing vertices into printf-formatting. | |
81 | #define FMT_VERTEX "(%.3f, %.3f, %.3f)" | |
82 | #define FVERTEX(V) V.x, V.y, V.z | |
83 | ||
84 | typedef unsigned char byte; | |
85 | ||
86 | template<class T> inline T clamp (T a, T min, T max) { | |
87 | return (a > max) ? max : (a < min) ? min : a; | |
88 | } | |
89 | ||
90 | template<class T> inline T min (T a, T b) { | |
91 | return (a < b) ? a : b; | |
92 | } | |
93 | ||
94 | template<class T> inline T max (T a, T b) { | |
95 | return (a > b) ? a : b; | |
96 | } | |
97 | ||
98 | static const double pi = 3.14159265358979323846f; | |
99 | ||
100 | // main.cpp | |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
101 | enum logtype_e { |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
102 | LOG_Normal, |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
103 | LOG_Success, |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
104 | LOG_Info, |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
105 | LOG_Warning, |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
106 | LOG_Error, |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
107 | }; |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
108 | |
62
915fc477cb6a
Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
44
diff
changeset
|
109 | // Vertex at (0, 0, 0) |
915fc477cb6a
Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
44
diff
changeset
|
110 | extern const vertex g_Origin; |
915fc477cb6a
Got inlining working. 3002.dat renders properly now! Now just to iron out the bugs and hone the behavior..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
44
diff
changeset
|
111 | |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
112 | void logf (const char* fmt, ...) FORMAT_PRINTF (1, 2); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
113 | void logf (logtype_e eType, const char* fmt, ...) FORMAT_PRINTF (2, 3); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
114 | |
0 | 115 | extern OpenFile* g_CurrentFile; |
116 | extern bbox g_BBox; | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
117 | extern ForgeWindow* g_qWindow; |
0 | 118 | extern vector<OpenFile*> g_LoadedFiles; |
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
119 | extern QApplication* g_qMainApp; |
0 | 120 | |
121 | #ifndef unix | |
122 | typedef unsigned int uint; | |
123 | typedef unsigned long ulong; | |
124 | #endif // unix | |
125 | ||
126 | typedef int8_t xchar; | |
127 | typedef int16_t xshort; | |
128 | typedef int32_t xlong; | |
129 | typedef int64_t xlonglong; | |
130 | typedef uint8_t xuchar; | |
131 | typedef uint16_t xushort; | |
132 | typedef uint32_t xulong; | |
133 | typedef uint64_t xulonglong; | |
134 | ||
63
aa40ce18f869
Implemented the inline action to expose inlining to the user. Also added a `deep inline` action to inline subfile recursively down into polygons and lines only.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
135 | #define FOREACH(T, PTRS, COUNTER, ARRAY) \ |
aa40ce18f869
Implemented the inline action to expose inlining to the user. Also added a `deep inline` action to inline subfile recursively down into polygons and lines only.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
136 | for (T PTRS* COUNTER##ptr = &(*ARRAY.begin ()), PTRS COUNTER = *COUNTER##ptr; \ |
aa40ce18f869
Implemented the inline action to expose inlining to the user. Also added a `deep inline` action to inline subfile recursively down into polygons and lines only.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
137 | COUNTER##ptr < &(*ARRAY.end ()); COUNTER = *(++COUNTER##ptr)) |
aa40ce18f869
Implemented the inline action to expose inlining to the user. Also added a `deep inline` action to inline subfile recursively down into polygons and lines only.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
138 | |
0 | 139 | #endif |