]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/gtkgensurf/gensurf.h
reformat code! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / contrib / gtkgensurf / gensurf.h
1 /*
2    GenSurf plugin for GtkRadiant
3    Copyright (C) 2001 David Hyde, Loki software and qeradiant.com
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #ifndef _GENSURF_H_
21 #define _GENSURF_H_
22
23 #include "globaldefs.h"
24 #include <string.h>
25 #include "qertypes.h"
26 #include <stdio.h>
27
28 #include "mathlib.h"
29 #include "iscenegraph.h"
30
31 #define USE_QERTABLE_DEFINE
32
33 #include "qerplugin.h"
34
35 extern _QERFuncTable_1 g_FuncTable;
36
37 #include "irender.h"
38 #include "iselection.h"
39
40 #define USE_ENTITYTABLE_DEFINE
41
42 #include "ientity.h"
43
44 extern _QEREntityTable __ENTITYTABLENAME;
45
46 #define USE_PATCHTABLE_DEFINE
47
48 #include "ipatch.h"
49
50 extern _QERPatchTable __PATCHTABLENAME;
51
52 #define USE_BRUSHTABLE_DEFINE
53
54 #include "ibrush.h"
55
56 extern _QERBrushTable __BRUSHTABLENAME;
57
58 #include "igl.h"
59 #include "ientity.h"
60
61 #include "iui_gtk.h"
62
63 #include "gendlgs.h"
64
65
66 #define PLUGIN
67 #define Q3RADIANT
68
69 //#if GDEF_OS_LINUX || GDEF_OS_MACOS
70 #if 1
71
72 #include <algorithm>
73
74 #else
75 template <class T>
76 inline T min( T x, T y ) { return ( x < y ) ? x : y; }
77 template <class T>
78 inline T max( T x, T y ) { return ( x > y ) ? x : y; }
79 #endif
80
81 typedef struct { long x, y; } Point;
82 typedef struct { long left, top, right, bottom; } Rect;
83
84 #define NAME_MAX 255
85
86 typedef void *LPVOID;
87 typedef char *LPSTR;
88
89 //#endif
90 inline bool PtInRect(Rect *rc, Point pt)
91 {
92     if (pt.x < rc->left) {
93         return false;
94     }
95     if (pt.x > rc->right) {
96         return false;
97     }
98     if (pt.y < rc->bottom) {
99         return false;
100     }
101     if (pt.y > rc->top) {
102         return false;
103     }
104     return true;
105 }
106
107 #define NUMGAMES 7
108
109 #define CONTENTS_SOLID  0x00000001
110 #define CONTENTS_DETAIL 0x08000000  // brushes to be added after vis leafs
111 #define CONTENTS_LADDER 0x20000000
112 #define SURF_HINT       0x100   // make a primary bsp splitter
113 #define SURF_SKIP       0x200   // completely ignore, allowing non-closed brushes
114 #define HINT_OFFSET 96
115
116 #define PI 3.14159265358979224
117 #define RadiansToDegrees(a) ( floor( a * 57.2957795 - 0.5 ) + 1. )
118 #define DegreesToRadians(a) ( a / 57.2957795 )
119
120 #define BOGUS_RANGE 65536
121 /*
122    #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
123    #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
124    #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
125    #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
126    #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
127    #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
128  */
129 #define XYZVectorSubtract(a, b, c) {c[0] = (float)a[0] - (float)b[0]; c[1] = (float)a[1] - (float)b[1]; c[2] = (float)a[2] - (float)b[2]; }
130 #define side(u1, v1, u2, v2, u3, v3) ( v3 - v1 ) * ( u2 - u1 ) - ( u3 - u1 ) * ( v2 - v1 )
131
132 #define QUAKE2    0
133 #define HALFLIFE  1
134 #define SIN       2
135 #define HERETIC2  3
136 #define KINGPIN   4
137 #define GENESIS3D 5
138 #define QUAKE3    6
139
140 #define MAX_FACES_PER_BRUSH 6
141 #define SLIVER_ANGLE DegreesToRadians( 20 )
142 #define MAX_NODES ( MAX_ROWS + 1 ) * ( MAX_ROWS + 1 )
143 #define MAX_TRIS  (MAX_ROWS)*( MAX_ROWS )
144
145 typedef float vec;
146 typedef vec vec3[3];
147 typedef vec vec2[2];
148
149 typedef struct {
150     vec3 v[3];
151     char texture[64];
152     float Shift[2];
153     float Rotate;
154     float Scale[2];
155     int Contents;
156     int Surface;
157     int Value;
158 } FACE;
159
160 typedef struct {
161     vec3 normal;
162     vec dist;
163 } PLANE;
164
165 typedef struct {
166     int numpoints;
167     vec3 p[4];          // variable sized
168 } MY_WINDING;
169
170 typedef struct {
171     int Number;
172     int NumFaces;
173     FACE face[MAX_FACES_PER_BRUSH];
174 } BRUSH;
175
176 typedef struct tagXYZ {
177     int fixed;
178     int done;
179     double p[3];
180     double pp[3];    // these used only for general 3D projection (not isometric)
181     double fixed_value;
182     double range;
183     double rate;
184 } XYZ;
185
186 // Q2 PAK file structures
187 typedef struct {
188     char id[4]; // Should be 'PACK'
189     int dstart; // Offest in the file to the directory
190     int dsize;  // Size in bytes of the directory, same as num_items*64
191 } pak_header_t;
192
193 typedef struct {
194     char name[56]; // The name of the item, normal C string
195     int start; // Offset in .pak file to start of item
196     int size; // Size of item in bytes
197 } pak_item_t;
198
199 // SiN .SIN structures
200 #define SINPAKHEADER        ( ( 'K' << 24 ) + ( 'A' << 16 ) + ( 'P' << 8 ) + 'S' )
201 #define MAX_PAK_FILENAME_LENGTH 120
202
203 typedef struct {
204     char name[MAX_PAK_FILENAME_LENGTH];
205     int filepos, filelen;
206 } dpackfile_t;
207
208 typedef struct {
209     int ident;          // == IDPAKHEADER
210     int dirofs;
211     int dirlen;
212 } dpackheader_t;
213
214 // Half-Life WAD file structures
215 typedef struct {
216     char identification[4];             // should be WAD2 or 2DAW
217     int numlumps;
218     int infotableofs;
219 } wadinfo_t;
220
221 typedef struct {
222     int filepos;
223     int disksize;
224     int size;                           // uncompressed
225     char type;
226     char compression;
227     char pad1, pad2;
228     char name[16];                      // must be null terminated
229 } lumpinfo_t;
230
231 typedef struct {
232     int signature;
233     short version;
234     short bitflag;
235     short compression_method;
236     short modfiletime;
237     short modfiledate;
238     int crc;
239     int compressed_size;
240     int uncompressed_size;
241     short filename_size;
242     short extra_size;
243 } zipheader_t;
244
245 typedef struct {
246     double x[2];
247     double y[2];
248     double z[2];
249 } bounding_box;
250
251 typedef struct {
252     float p[3];
253     int used;
254     int tri;
255     float error;
256     int fixed;
257 } NODE;
258
259 typedef struct {
260     int v[3];
261     int n[3];      // indices of neighboring triangles
262     PLANE plane;
263     int flag;
264     float min[3];
265     float max[3];
266 } TRI;
267
268 //--------------- bitmap.c -----------------------------
269 bool OpenBitmap();
270
271 double CalculateSnapValue(double value);
272
273 void GenerateBitmapMapping();
274
275 //--------------- face.c -------------------------------
276 void PlaneFromPoints(float *, float *, float *, PLANE *);
277
278 //void CrossProduct (vec3 v1, vec3 v2, vec3 cross);
279 //vec VectorNormalize (vec3 in, vec3 out);
280 //--------------- gendlg.c -----------------------------
281 GtkWidget *create_main_dialog();
282
283 void About(GtkWidget *parent);
284
285 //--------------- genmap.c -----------------------------
286 double AtLeast(double, double);
287
288 bool CanEdit(int, int);
289
290 void CloseFuncGroup();
291
292 bool FixedPoint(int, int);
293
294 void GenerateMap();
295
296 void GenerateXYZ();
297
298 double LessThan(double, double);
299
300 void MakeBrush(BRUSH *);
301
302 double MoreThan(double, double);
303
304 double Nearest(double, double);
305
306 double NoMoreThan(double, double);
307
308 void OpenFuncGroup();
309
310 void PlasmaCloud();
311
312 int PlayerStartZ(double, double);
313
314 void SubdividePlasma(int, int, int, int);
315
316 bool ValidSurface();
317
318 void XYZtoV(XYZ *, vec3 *);
319
320 scene::Node *MakePatch(void);
321
322 //---------------- gensurf.c ---------------------------
323 bool GenSurfInit();
324
325 void ReadIniFile(const char *);
326
327 void WriteIniFile(const char *);
328
329 void OpenSetup(GtkWidget *, int);
330
331 void SaveSetup(GtkWidget *);
332
333 //---------------- heretic.c ---------------------------
334 int GetDefSurfaceProps(char *);
335
336 //---------------- view.c ------------------------------
337 void CreateViewWindow();
338
339 void DrawGrid(Rect);
340
341 void DrawPreview(Rect);
342
343 void evaluate();
344
345 void GetScaleFactor(Rect);
346
347 void project(XYZ *);
348
349 void Scale(Rect, XYZ, Point *);
350
351 void ShowPreview();
352
353 void UpdatePreview(bool);
354
355 //---------------- plugin.c -----------------------------
356 void UseFaceBounds();
357
358 extern _QERFuncTable_1 g_FuncTable;
359 extern _QERQglTable g_GLTable;
360 extern _QERUIGtkTable g_UIGtkTable;
361 extern _QEREntityTable g_EntityTable;
362 //#define MAX_ROWS 64
363 #define MAX_ROWS 128
364
365 #define PLANE_XY0 0
366 #define PLANE_XY1 1
367 #define PLANE_YZ0 2
368 #define PLANE_XZ0 3
369 #define PLANE_YZ1 4
370 #define PLANE_XZ1 5
371
372 #define WAVE_COS_SIN    0
373 #define WAVE_HCYLINDER  1
374 #define WAVE_VCYLINDER  2
375 #define WAVE_BITMAP     3
376 #define WAVE_ROUGH_ONLY 4
377 #define WAVE_FORMULA    5
378 #define WAVE_FIRST      WAVE_COS_SIN
379 #define WAVE_LAST       WAVE_FORMULA
380 #define DLG_WAVE_LAST   DLG_WAVE_01 + WAVE_LAST - WAVE_FIRST
381
382 #define MSG_VERTEX_SELECTED WM_USER + 1
383
384 typedef struct tagMYBITMAP {
385     char name[NAME_MAX];
386     char defpath[NAME_MAX];
387     double black_value;
388     double white_value;
389     int width, height;
390     unsigned char *colors;
391 } MYBITMAP;
392
393 typedef struct tagELEMENT {
394     int i;
395     int j;
396 } ELEMENT;
397
398 extern char gszAppDir[NAME_MAX];
399 extern char gszCaption[64];
400 extern char gszHelpFile[NAME_MAX];
401 extern char gszIni[NAME_MAX];
402 extern char gszMapFile[NAME_MAX];
403 extern char gszVersion[64];
404 extern double Amplitude;
405 extern double Roughness;
406 extern double TexOffset[2];
407 extern double TexScale[2];
408 extern double WaveLength;
409 extern double Hll, Hur, Vll, Vur;
410 extern double Z00, Z01, Z10, Z11;
411 extern double yaw, pitch, roll;
412 extern ELEMENT Vertex[(MAX_ROWS + 1) * (MAX_ROWS + 1)];
413 extern int AddHints;
414 extern int ArghRad2;
415 extern int AutoOverwrite;
416 extern int Decimate;
417 extern int FileAppend;
418 extern int FixBorders;
419 extern int HideBackFaces;
420 extern int NH, NV;
421 extern int NumVerticesSelected;
422 extern int Plane;
423 extern int Preview;
424 extern int RandomSeed;
425 extern int Skybox;
426 extern int UseDetail;
427 extern int UseLadder;
428 extern int VertexMode;
429 extern int vid_x, vid_y;
430 extern int WaveType;
431 extern int gNumNodes;
432 extern int gNumTris;
433 extern int view_x, view_y;
434 extern int view_cx, view_cy;
435 extern int UsePatches;
436 extern int SlantAngle;
437 extern int GimpHints;
438 extern int Antialiasing;           // ^Fishman - Antializing for the preview window.
439 extern int AddTerrainKey;           // ^Fishman - Add terrain key to func_group.
440 extern int SnapToGrid;           // Hydra : snap to grid
441 extern int SP;       // ^Fishman - Snap to grid.
442
443
444 /*extern HCURSOR   ghCursorCurrent;
445    extern HCURSOR   ghCursorDefault;
446    extern HCURSOR   ghCursorVertex;
447    extern HINSTANCE ghInst;*/
448 extern ui::Window g_pRadiantWnd;
449 extern ui::Window g_pWnd;
450 /*extern HWND      ghwndAngles;
451    extern HWND      ghwndFix;
452  */extern GtkWidget *g_pWndPreview;
453 extern GtkWidget *g_pPreviewWidget;
454 extern MYBITMAP gbmp;
455 extern NODE *gNode;
456 extern TRI *gTri;
457 extern XYZ xyz[MAX_ROWS + 1][MAX_ROWS + 1];
458
459 extern int Game;
460 extern bounding_box PlayerBox[NUMGAMES];
461 //extern char      gszOutputDir[NUMGAMES][NAME_MAX];
462 extern char Texture[NUMGAMES][3][64];
463 //extern char      gszTextureDir[NUMGAMES][NAME_MAX];
464 extern char GameName[NUMGAMES][16];
465 //extern char      pakfile[NUMGAMES][NAME_MAX];
466 //extern char      lastpakfile[NUMGAMES][NAME_MAX];
467 //extern int       UsePak[NUMGAMES];
468 //extern char      GameDir[NUMGAMES][NAME_MAX];
469 //extern char      ExcelFunc[1024];
470
471 #endif // _GENSURF_H_