]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/gtkgensurf/gensurf.h
b137c025bbdc12253ece301bd4c539d44051af8e
[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 <gtk/gtk.h>
24 #include <glib/gi18n.h>
25
26 #include "qerplugin.h"
27 //#include "qertypes.h"
28
29 #include "igl.h"
30 #include "iui_gtk.h"
31 #include "ientity.h"
32
33 #include "gendlgs.h"
34
35 #define PLUGIN
36 #define Q3RADIANT
37
38 #if defined(__linux__) || defined(__APPLE__)
39 template <class T>
40 inline T min (T x, T y) { return (x < y) ? x : y; }
41 template <class T>
42 inline T max (T x, T y) { return (x > y) ? x : y; }
43
44 typedef struct { long x, y; } POINT;
45 typedef struct { long left, top, right, bottom; } RECT;
46 #endif
47 inline bool PtInRect (RECT *rc, POINT pt)
48 {
49   if (pt.x < rc->left) return false;
50   if (pt.x > rc->right) return false;
51   if (pt.y < rc->bottom) return false;
52   if (pt.y > rc->top) return false;
53   return true;
54 }
55
56 #define NUMGAMES 7
57
58 #define CONTENTS_SOLID  0x00000001
59 #define CONTENTS_DETAIL 0x08000000      // brushes to be added after vis leafs
60 #define CONTENTS_LADDER 0x20000000
61 #define SURF_HINT               0x100   // make a primary bsp splitter
62 #define SURF_SKIP               0x200   // completely ignore, allowing non-closed brushes
63 #define HINT_OFFSET 96
64
65 #define PI 3.14159265358979224
66 #define RadiansToDegrees(a) (floor(a*57.2957795 - 0.5)+1.)
67 #define DegreesToRadians(a) (a/57.2957795)
68
69 #define BOGUS_RANGE     65536
70 #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
71 #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
72 #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
73 #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
74 #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
75 #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
76 #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];}
77 #define side(u1,v1,u2,v2,u3,v3) (v3-v1)*(u2-u1) - (u3-u1)*(v2-v1)
78
79 #define QUAKE2    0
80 #define HALFLIFE  1
81 #define SIN       2
82 #define HERETIC2  3
83 #define KINGPIN   4
84 #define GENESIS3D 5
85 #define QUAKE3    6
86
87 #define MAX_FACES_PER_BRUSH 6
88 #define SLIVER_ANGLE DegreesToRadians(20)
89 #define MAX_NODES (MAX_ROWS+1)*(MAX_ROWS+1)
90 #define MAX_TRIS  (MAX_ROWS)*(MAX_ROWS)
91
92 typedef float vec;
93 typedef vec vec3[3];
94 typedef vec vec2[2];
95
96 typedef struct
97 {
98         vec3   v[3];
99         char   texture[64];
100         float  Shift[2];
101         float  Rotate;
102         float  Scale[2];
103         int    Contents;
104         int    Surface;
105         int    Value;
106 } FACE;
107
108 typedef struct
109 {
110         vec3 normal;
111         vec  dist;
112 } PLANE;
113
114 typedef struct
115 {
116         int             numpoints;
117         vec3    p[4];           // variable sized
118 } MY_WINDING;
119
120 typedef struct
121 {
122         int  Number;
123         int  NumFaces;
124         FACE face[MAX_FACES_PER_BRUSH];
125 } BRUSH;
126
127 typedef struct tagXYZ
128 {
129         int fixed;
130         int done;
131         double p[3];
132         double pp[3];    // these used only for general 3D projection (not isometric)
133         double fixed_value;
134         double range;
135         double rate;
136 } XYZ;
137
138 // Q2 PAK file structures
139 typedef struct
140 {
141         char id[4]; // Should be 'PACK'
142         int dstart; // Offest in the file to the directory
143         int dsize;  // Size in bytes of the directory, same as num_items*64
144 } pak_header_t;
145
146 typedef struct
147 {
148         char name[56]; // The name of the item, normal C string
149         int start; // Offset in .pak file to start of item
150         int size; // Size of item in bytes
151 } pak_item_t;
152
153 // SiN .SIN structures
154 #define SINPAKHEADER            (('K'<<24)+('A'<<16)+('P'<<8)+'S')
155 #define MAX_PAK_FILENAME_LENGTH 120
156
157 typedef struct
158 {
159         char    name[MAX_PAK_FILENAME_LENGTH];
160         int             filepos, filelen;
161 } dpackfile_t;
162
163 typedef struct
164 {
165         int             ident;          // == IDPAKHEADER
166         int             dirofs;
167         int             dirlen;
168 } dpackheader_t;
169
170 // Half-Life WAD file structures
171 typedef struct
172 {
173         char            identification[4];              // should be WAD2 or 2DAW
174         int                     numlumps;
175         int                     infotableofs;
176 } wadinfo_t;
177
178 typedef struct
179 {
180         int                     filepos;
181         int                     disksize;
182         int                     size;                                   // uncompressed
183         char            type;
184         char            compression;
185         char            pad1, pad2;
186         char            name[16];                               // must be null terminated
187 } lumpinfo_t;
188
189 typedef struct
190 {
191         int             signature;
192         short   version;
193         short   bitflag;
194         short   compression_method;
195         short   modfiletime;
196         short   modfiledate;
197         int             crc;
198         int             compressed_size;
199         int             uncompressed_size;
200         short   filename_size;
201         short   extra_size;
202 } zipheader_t;
203
204 typedef struct
205 {
206         double  x[2];
207         double  y[2];
208         double  z[2];
209 } bounding_box;
210
211 typedef struct
212 {
213         float p[3];
214         int   used;
215         int   tri;
216         float error;
217         int   fixed;
218 } NODE;
219
220 typedef struct
221 {
222         int   v[3];
223         int   n[3];    // indices of neighboring triangles
224         PLANE plane;
225         int   flag;
226         float min[3];
227         float max[3];
228 } TRI;
229
230 //--------------- bitmap.c -----------------------------
231 bool OpenBitmap ();
232 void GenerateBitmapMapping ();
233 //--------------- face.c -------------------------------
234 void PlaneFromPoints (float *, float *, float *, PLANE *);
235 void CrossProduct (vec3 v1, vec3 v2, vec3 cross);
236 vec VectorNormalize (vec3 in, vec3 out);
237 //--------------- gendlg.c -----------------------------
238 GtkWidget* create_main_dialog ();
239 void About (GtkWidget *parent);
240 //--------------- genmap.c -----------------------------
241 double AtLeast(double,double);
242 bool CanEdit(int, int);
243 void CloseFuncGroup();
244 bool FixedPoint(int,int);
245 void GenerateMap();
246 void GenerateXYZ();
247 double LessThan(double,double);
248 void MakeBrush(BRUSH *);
249 double MoreThan(double,double);
250 double Nearest(double,double);
251 double NoMoreThan(double,double);
252 void OpenFuncGroup();
253 void PlasmaCloud();
254 int PlayerStartZ(double,double);
255 void SubdividePlasma(int,int,int,int);
256 bool ValidSurface();
257 void XYZtoV(XYZ *, vec3 *);
258 void MakePatch(patchMesh_t *);
259 double CalculateSnapValue(double value);
260
261 //---------------- gensurf.c ---------------------------
262 bool GenSurfInit ();
263 void ReadIniFile (const char *);
264 void WriteIniFile (const char *);
265 void OpenSetup (GtkWidget*,int);
266 void SaveSetup (GtkWidget*);
267 //---------------- heretic.c ---------------------------
268 int GetDefSurfaceProps(char *);
269 //---------------- view.c ------------------------------
270 void CreateViewWindow ();
271 void DrawGrid(RECT);
272 void DrawPreview(RECT);
273 void evaluate();
274 void GetScaleFactor(RECT);
275 void project(XYZ *);
276 void Scale(RECT,XYZ,POINT *);
277 void ShowPreview ();
278 void UpdatePreview (bool);
279
280 //---------------- plugin.c -----------------------------
281 void UseFaceBounds();
282
283 extern _QERFuncTable_1 g_FuncTable;
284 extern _QERQglTable g_GLTable;
285 extern _QERUIGtkTable g_UIGtkTable;
286 extern _QEREntityTable g_EntityTable;
287 //#define MAX_ROWS 64
288 #define MAX_ROWS 128
289
290 #define PLANE_XY0 0
291 #define PLANE_XY1 1
292 #define PLANE_YZ0 2
293 #define PLANE_XZ0 3
294 #define PLANE_YZ1 4
295 #define PLANE_XZ1 5
296
297 #define WAVE_COS_SIN    0
298 #define WAVE_HCYLINDER  1
299 #define WAVE_VCYLINDER  2
300 #define WAVE_BITMAP     3
301 #define WAVE_ROUGH_ONLY 4
302 #define WAVE_FORMULA    5
303 #define WAVE_FIRST      WAVE_COS_SIN
304 #define WAVE_LAST       WAVE_FORMULA
305 #define DLG_WAVE_LAST   DLG_WAVE_01+WAVE_LAST-WAVE_FIRST
306
307 #define MSG_VERTEX_SELECTED WM_USER+1
308
309 typedef struct tagMYBITMAP
310 {
311   char             name[NAME_MAX];
312   char             defpath[NAME_MAX];
313   double           black_value;
314   double           white_value;
315   int width, height;
316   unsigned char* colors;
317 } MYBITMAP;
318
319 typedef struct tagELEMENT {
320         int i;
321         int j;
322 } ELEMENT;
323
324 extern char      gszAppDir[NAME_MAX];
325 extern char      gszCaption[64];
326 extern char      gszHelpFile[NAME_MAX];
327 extern char      gszIni[NAME_MAX];
328 extern char      gszMapFile[NAME_MAX];
329 extern char      gszVersion[64];
330 extern double    Amplitude;
331 extern double    Roughness;
332 extern double    TexOffset[2];
333 extern double    TexScale[2];
334 extern double    WaveLength;
335 extern double    Hll, Hur, Vll, Vur;
336 extern double    Z00, Z01, Z10, Z11;
337 extern double    yaw, pitch, roll;
338 extern ELEMENT   Vertex[(MAX_ROWS+1)*(MAX_ROWS+1)];
339 extern int       AddHints;
340 extern int       ArghRad2;
341 extern int       AutoOverwrite;
342 extern int       Decimate;
343 extern int       FileAppend;
344 extern int       FixBorders;
345 extern int       HideBackFaces;
346 extern int       NH, NV;
347 extern int       NumVerticesSelected;
348 extern int       Plane;
349 extern int       Preview;
350 extern int       RandomSeed;
351 extern int       Skybox;
352 extern int       UseDetail;
353 extern int       UseLadder;
354 extern int       VertexMode;
355 extern int       vid_x, vid_y;
356 extern int       WaveType;
357 extern int       gNumNodes;
358 extern int       gNumTris;
359 extern int       view_x, view_y;
360 extern int       view_cx, view_cy;
361 extern int       UsePatches;
362 extern int       SlantAngle;
363 extern int       GimpHints;
364 extern int                       Antialiasing; // ^Fishman - Antializing for the preview window.
365 extern int                       AddTerrainKey; // ^Fishman - Add terrain key to func_group.
366 extern int                       SnapToGrid; // Hydra : snap to grid
367 extern int       SP; // ^Fishman - Snap to grid.
368
369 /*extern HCURSOR   ghCursorCurrent;
370 extern HCURSOR   ghCursorDefault;
371 extern HCURSOR   ghCursorVertex;
372 extern HINSTANCE ghInst;*/
373 extern GtkWidget *g_pRadiantWnd;
374 extern GtkWidget *g_pWnd;
375 /*extern HWND      ghwndAngles;
376 extern HWND      ghwndFix;
377 */extern GtkWidget     *g_pWndPreview;
378 extern GtkWidget *g_pPreviewWidget;
379 extern MYBITMAP  gbmp;
380 extern NODE      *gNode;
381 extern TRI       *gTri;
382 extern XYZ       xyz[MAX_ROWS+1][MAX_ROWS+1];
383
384 extern int       Game;
385 extern bounding_box PlayerBox[NUMGAMES];
386 //extern char      gszOutputDir[NUMGAMES][NAME_MAX];
387 extern char      Texture[NUMGAMES][3][64];
388 //extern char      gszTextureDir[NUMGAMES][NAME_MAX];
389 extern char      GameName[NUMGAMES][16];
390 //extern char      pakfile[NUMGAMES][NAME_MAX];
391 //extern char      lastpakfile[NUMGAMES][NAME_MAX];
392 //extern int       UsePak[NUMGAMES];
393 //extern char      GameDir[NUMGAMES][NAME_MAX];
394 //extern char      ExcelFunc[1024];
395
396 #endif // _GENSURF_H_