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