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