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