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