]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/bobtoolz/shapes.cpp
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / contrib / bobtoolz / shapes.cpp
1 /*\r
2 BobToolz plugin for GtkRadiant\r
3 Copyright (C) 2001 Gordon Biggans\r
4 \r
5 This library is free software; you can redistribute it and/or\r
6 modify it under the terms of the GNU Lesser General Public\r
7 License as published by the Free Software Foundation; either\r
8 version 2.1 of the License, or (at your option) any later version.\r
9 \r
10 This library is distributed in the hope that it will be useful,\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
13 Lesser General Public License for more details.\r
14 \r
15 You should have received a copy of the GNU Lesser General Public\r
16 License along with this library; if not, write to the Free Software\r
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
18 */\r
19 \r
20 \r
21 #include "StdAfx.h"\r
22 \r
23 #include "shapes.h"\r
24 \r
25 #include "DPlane.h"\r
26 \r
27 #include "misc.h"\r
28 #include "funchandlers.h"\r
29 \r
30 //#include "dialogs-gtk.h"\r
31 \r
32 /************************\r
33         Cube Diagram\r
34 ************************/\r
35 \r
36 /*\r
37 \r
38                 7 ----- 5\r
39             /|    /|\r
40            / |   / |\r
41           /  |  /  |\r
42         4 ----- 6  |\r
43          |  2|_|___|8\r
44          |  /  |   /\r
45          | /   |  /       ----> WEST, definitely\r
46          |/    | /\r
47         1|_____|/3\r
48 \r
49 */\r
50 \r
51 /************************\r
52         Global Variables\r
53 ************************/\r
54 \r
55 vec3_t  g_Origin = {0.0f, 0.0f, 0.0f};\r
56 \r
57 extern bool bFacesAll[];\r
58 \r
59 /************************\r
60         Helper Functions\r
61 ************************/\r
62 \r
63 float Deg2Rad(float angle)\r
64 {\r
65         return (float)(angle*Q_PI/180);\r
66 }\r
67 \r
68 void AddFaceWithTexture(brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)\r
69 {\r
70         _QERFaceData faceData;\r
71         FillDefaultTexture(&faceData, va, vb, vc, texture);\r
72         if(detail)\r
73                 faceData.m_nContents |= FACE_DETAIL;\r
74         \r
75         g_FuncTable.m_pfnAddFaceData(brush, &faceData);\r
76 }\r
77 \r
78 void AddFaceWithTextureScaled(brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc, \r
79                                                           const char* texture, bool bVertScale, bool bHorScale, \r
80                                                           float minX, float minY, float maxX, float maxY)\r
81 {\r
82         g_ShadersTable.m_pfnShader_ForName(texture); // need to call frist to load?\r
83 \r
84         qtexture_t* pqtTexInfo;\r
85 \r
86   // TTimo: there used to be a call to pfnHasShader here\r
87   //   this was not necessary. In Radiant everything is shader.\r
88   //   If a texture doesn't have a shader script, a default shader object is used.\r
89   // The IShader object was leaking also\r
90         // collect texture info: sizes, etc\r
91         IShader* i = g_ShadersTable.m_pfnShader_ForName(texture);\r
92   pqtTexInfo = i->getTexture(); // shader width/height doesn't come out properly\r
93 \r
94         if(pqtTexInfo)\r
95         {\r
96                 float scale[2] = {0.5f, 0.5f};\r
97                 float shift[2] = {0, 0};\r
98 \r
99                 if(bHorScale)\r
100                 {\r
101                         int texWidth = pqtTexInfo->width;\r
102                         float width = maxX - minX;\r
103 \r
104                         scale[0] = width/texWidth;\r
105                         shift[0] = -(float)((int)maxX%(int)width)/scale[0];\r
106                 }\r
107 \r
108                 if(bVertScale)\r
109                 {\r
110                         int texHeight = pqtTexInfo->height;\r
111                         float height = maxY - minY;\r
112 \r
113                         scale[1] = height/texHeight;\r
114                         shift[1] = (float)((int)minY%(int)height)/scale[1];\r
115                 }\r
116 \r
117                 _QERFaceData addFace;\r
118                 FillDefaultTexture(&addFace, va, vb, vc, texture);\r
119                 addFace.m_fScale[0] = scale[0];\r
120                 addFace.m_fScale[1] = scale[1];\r
121                 addFace.m_fShift[0] = shift[0];\r
122                 addFace.m_fShift[1] = shift[1];\r
123 \r
124                 g_FuncTable.m_pfnAddFaceData(brush, &addFace);\r
125         }\r
126         else\r
127         {\r
128                 // shouldn't even get here, as default missing texture should be returned if\r
129                 // texture doesn't exist, but just in case\r
130                 AddFaceWithTexture(brush, va, vb, vc, texture, FALSE);\r
131                 Sys_ERROR("BobToolz::Invalid Texture Name-> %s", texture);\r
132         }\r
133   // the IShader is not kept referenced, DecRef it\r
134   i->DecRef();\r
135 }\r
136 \r
137 /************************\r
138         --Main Functions--\r
139 ************************/\r
140 \r
141 void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)\r
142 {\r
143         brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();\r
144 \r
145         vec3_t v1, v2, v3, v5, v6, v7, v8;\r
146         VectorCopy(min, v1);\r
147         VectorCopy(min, v2);\r
148         VectorCopy(min, v3);\r
149         VectorCopy(max, v5);\r
150         VectorCopy(max, v6);\r
151         VectorCopy(max, v7);\r
152         VectorCopy(max, v8);\r
153 \r
154         v2[0] = max[0];\r
155         v3[1] = max[1];\r
156 \r
157         v6[0] = min[0];\r
158         v7[1] = min[1];\r
159         v8[2] = min[2];\r
160 \r
161         if(bUp)\r
162         {\r
163 \r
164                 if(dir != MOVE_EAST)\r
165                         AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);\r
166 \r
167                 if(dir != MOVE_WEST)\r
168                         AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);\r
169 \r
170                 if(dir != MOVE_NORTH)\r
171                         AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);\r
172 \r
173                 if(dir != MOVE_SOUTH)\r
174                         AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);\r
175 \r
176                 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);\r
177 \r
178                 if(dir == MOVE_EAST)\r
179                         AddFaceWithTexture(newBrush, v1, v3, v5, "textures/common/caulk", FALSE);\r
180 \r
181                 if(dir == MOVE_WEST)\r
182                         AddFaceWithTexture(newBrush, v2, v6, v8, "textures/common/caulk", FALSE);\r
183 \r
184                 if(dir == MOVE_NORTH)\r
185                         AddFaceWithTexture(newBrush, v1, v6, v5, "textures/common/caulk", FALSE);\r
186 \r
187                 if(dir == MOVE_SOUTH)\r
188                         AddFaceWithTexture(newBrush, v7, v3, v8, "textures/common/caulk", FALSE);\r
189         }\r
190         else\r
191         {\r
192                 if(dir != MOVE_WEST)\r
193                         AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);\r
194 \r
195                 if(dir != MOVE_EAST)\r
196                         AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);\r
197 \r
198                 if(dir != MOVE_NORTH)\r
199                         AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);\r
200 \r
201                 if(dir != MOVE_SOUTH)\r
202                         AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);\r
203 \r
204                 \r
205                 AddFaceWithTexture(newBrush, v6, v5, v7, "textures/common/caulk", FALSE);\r
206 \r
207                 if(dir == MOVE_WEST)\r
208                         AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", FALSE);\r
209 \r
210                 if(dir == MOVE_EAST)\r
211                         AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", FALSE);\r
212 \r
213                 if(dir == MOVE_NORTH)\r
214                         AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", FALSE);\r
215 \r
216                 if(dir == MOVE_SOUTH)\r
217                         AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE);\r
218         }\r
219 \r
220         g_FuncTable.m_pfnCommitBrushHandle(newBrush);\r
221 }\r
222 \r
223 //-----------------------------------------------------------------------------------\r
224 //-----------------------------------------------------------------------------------\r
225 \r
226 void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)\r
227 {\r
228         brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();\r
229 \r
230         //----- Build Outer Bounds ---------\r
231 \r
232         vec3_t v1, v2, v3, v5, v6, v7, v8;\r
233         VectorCopy(min, v1);\r
234         VectorCopy(min, v2);\r
235         VectorCopy(min, v3);\r
236         VectorCopy(max, v5);\r
237         VectorCopy(max, v6);\r
238         VectorCopy(max, v7);\r
239         VectorCopy(max, v8);\r
240 \r
241         v2[0] = max[0];\r
242         v3[1] = max[1];\r
243 \r
244         v6[0] = min[0];\r
245         v7[1] = min[1];\r
246 \r
247         v8[2] = min[2];\r
248         //v8 needed this time, becoz of sloping faces (2-4-6-8)\r
249 \r
250         //----------------------------------\r
251 \r
252         AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, detail);\r
253 \r
254         if(dir != MOVE_EAST)\r
255         {\r
256                 if(dir == MOVE_WEST)\r
257                         AddFaceWithTexture(newBrush, v5, v2, v7, riserTexture, detail);\r
258                 else\r
259                         AddFaceWithTexture(newBrush, v5, v2, v7, "textures/common/caulk", detail);\r
260         }\r
261 \r
262         if(dir != MOVE_WEST)\r
263         {\r
264                 if(dir == MOVE_EAST)\r
265                         AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, detail);\r
266                 else\r
267                         AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", detail);\r
268         }\r
269 \r
270         if(dir != MOVE_NORTH)\r
271         {\r
272                 if(dir == MOVE_SOUTH)\r
273                         AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, detail);\r
274                 else\r
275                         AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", detail);\r
276         }\r
277 \r
278         if(dir != MOVE_SOUTH)\r
279         {\r
280                 if(dir == MOVE_NORTH)\r
281                         AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, detail);\r
282                 else\r
283                         AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", detail);\r
284         }\r
285 \r
286                 \r
287         if(dir == MOVE_EAST)\r
288                 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", detail);\r
289 \r
290         if(dir == MOVE_WEST)\r
291                 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", detail);\r
292 \r
293         if(dir == MOVE_NORTH)\r
294                 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", detail);\r
295 \r
296         if(dir == MOVE_SOUTH)\r
297                 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);\r
298 \r
299         g_FuncTable.m_pfnCommitBrushHandle(newBrush);\r
300 }\r
301 \r
302 //-----------------------------------------------------------------------------------\r
303 //-----------------------------------------------------------------------------------\r
304 \r
305 // internal use only, to get a box without finishing construction\r
306 brush_t* Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)\r
307 {\r
308         brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();\r
309 \r
310         //----- Build Outer Bounds ---------\r
311 \r
312         vec3_t v1, v2, v3, v5, v6, v7;\r
313         VectorCopy(min, v1);\r
314         VectorCopy(min, v2);\r
315         VectorCopy(min, v3);\r
316         VectorCopy(max, v5);\r
317         VectorCopy(max, v6);\r
318         VectorCopy(max, v7);\r
319 \r
320         v2[0] = max[0];\r
321         v3[1] = max[1];\r
322 \r
323         v6[0] = min[0];\r
324         v7[1] = min[1];\r
325 \r
326         //----------------------------------\r
327 \r
328         //----- Add Six Cube Faces ---------\r
329 \r
330         if(useFaces[0])\r
331                 AddFaceWithTexture(newBrush, v1, v2, v3, texture, FALSE);\r
332         if(useFaces[1])\r
333                 AddFaceWithTexture(newBrush, v1, v3, v6, texture, FALSE);\r
334         if(useFaces[2])\r
335                 AddFaceWithTexture(newBrush, v1, v7, v2, texture, FALSE);\r
336 \r
337         if(useFaces[3])\r
338                 AddFaceWithTexture(newBrush, v5, v6, v3, texture, FALSE);\r
339         if(useFaces[4])\r
340                 AddFaceWithTexture(newBrush, v5, v2, v7, texture, FALSE);\r
341         if(useFaces[5])\r
342                 AddFaceWithTexture(newBrush, v5, v7, v6, texture, FALSE);\r
343 \r
344         //----------------------------------\r
345 \r
346         return newBrush;\r
347 }\r
348 \r
349 brush_t* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)\r
350 {\r
351         return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);\r
352 }\r
353 \r
354 //-----------------------------------------------------------------------------------\r
355 //-----------------------------------------------------------------------------------\r
356 \r
357 void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)\r
358 {\r
359         brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();\r
360 \r
361         //----- Build Outer Bounds ---------\r
362 \r
363         vec3_t v1, v2, v3, v5, v6, v7;\r
364         VectorCopy(min, v1);\r
365         VectorCopy(min, v2);\r
366         VectorCopy(min, v3);\r
367         VectorCopy(max, v5);\r
368         VectorCopy(max, v6);\r
369         VectorCopy(max, v7);\r
370 \r
371         v2[0] = max[0];\r
372         v3[1] = max[1];\r
373 \r
374         v6[0] = min[0];\r
375         v7[1] = min[1];\r
376 \r
377         //----------------------------------\r
378 \r
379         AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, FALSE);\r
380         // top gets current texture\r
381 \r
382 \r
383         if(direction == MOVE_EAST)\r
384                 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, FALSE);\r
385         else\r
386                 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);\r
387         // west facing side, etc...\r
388 \r
389         \r
390         if(direction == MOVE_NORTH)\r
391                 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, FALSE);\r
392         else\r
393                 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);\r
394 \r
395         if(direction == MOVE_SOUTH)\r
396                 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, FALSE);\r
397         else\r
398                 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", FALSE);\r
399         \r
400         if(direction == MOVE_WEST)\r
401                 AddFaceWithTexture(newBrush, v7, v5, v2, riserTexture, FALSE);\r
402         else\r
403                 AddFaceWithTexture(newBrush, v7, v5, v2, "textures/common/caulk", FALSE);\r
404 \r
405 \r
406         AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);\r
407         // base is caulked\r
408 \r
409         g_FuncTable.m_pfnCommitBrushHandle(newBrush);\r
410         // finish brush\r
411 }\r
412 \r
413 //-----------------------------------------------------------------------------------\r
414 //-----------------------------------------------------------------------------------\r
415 \r
416 void BuildDoorsX2(vec3_t min, vec3_t max, \r
417                                   bool bSclMainHor, bool bSclMainVert, \r
418                                   bool bSclTrimHor, bool bSclTrimVert,\r
419                                   const char* mainTexture, const char* trimTexture,\r
420                                   int direction)\r
421 {\r
422         int xy;\r
423         if(direction == 0)\r
424                 xy = 0;\r
425         else\r
426                 xy = 1;\r
427 \r
428         //----- Build Outer Bounds ---------\r
429 \r
430         vec3_t v1, v2, v3, v5, v6, v7, ve_1, ve_2, ve_3;\r
431         VectorCopy(min, v1);\r
432         VectorCopy(min, v2);\r
433         VectorCopy(min, v3);\r
434         VectorCopy(max, v5);\r
435         VectorCopy(max, v6);\r
436         VectorCopy(max, v7);\r
437 \r
438         v2[0] = max[0];\r
439         v3[1] = max[1];\r
440 \r
441         v6[0] = min[0];\r
442         v7[1] = min[1];\r
443 \r
444         float width = (max[xy] - min[xy])/2;\r
445         \r
446         if(direction == 0)\r
447         {\r
448                 VectorCopy(v1, ve_1);\r
449                 VectorCopy(v3, ve_2);\r
450                 VectorCopy(v6, ve_3);\r
451         }\r
452         else\r
453         {\r
454                 VectorCopy(v7, ve_1);\r
455                 VectorCopy(v1, ve_2);\r
456                 VectorCopy(v2, ve_3);\r
457         }\r
458 \r
459         ve_1[xy] += width;\r
460         ve_2[xy] += width;\r
461         ve_3[xy] += width;\r
462 \r
463         //----------------------------------\r
464 \r
465         brush_t* newBrush1 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();\r
466         brush_t* newBrush2 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();\r
467 \r
468         AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE);\r
469         AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE);\r
470 \r
471         AddFaceWithTexture(newBrush2, v1, v2, v3, "textures/common/caulk", FALSE);\r
472         AddFaceWithTexture(newBrush2, v5, v7, v6, "textures/common/caulk", FALSE);\r
473 \r
474         if(direction == 0)\r
475         {\r
476                 AddFaceWithTexture(newBrush1, v1, v3, v6, "textures/common/caulk", FALSE);\r
477                 AddFaceWithTexture(newBrush2, v5, v2, v7, "textures/common/caulk", FALSE);\r
478         }\r
479         else\r
480         {\r
481                 AddFaceWithTexture(newBrush1, v1, v7, v2, "textures/common/caulk", FALSE);\r
482                 AddFaceWithTexture(newBrush2, v5, v6, v3, "textures/common/caulk", FALSE);\r
483         }\r
484 \r
485         if(direction == 0)\r
486         {\r
487                 AddFaceWithTextureScaled(newBrush1, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,\r
488                         min[0], min[2], max[0], max[2]);\r
489                 AddFaceWithTextureScaled(newBrush1, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,\r
490                         max[0], min[2], min[0], max[2]);\r
491 \r
492                 \r
493                 AddFaceWithTextureScaled(newBrush2, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,\r
494                         min[0], min[2], max[0], max[2]);\r
495                 AddFaceWithTextureScaled(newBrush2, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,\r
496                         max[0], min[2], min[0], max[2]);        // flip max/min to reverse tex dir\r
497 \r
498 \r
499         \r
500                 AddFaceWithTextureScaled(newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,\r
501                         min[1], min[2], max[1], max[2]);\r
502 \r
503                 AddFaceWithTextureScaled(newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,\r
504                         max[1], min[2], min[1], max[2]);\r
505         }\r
506         else\r
507         {\r
508                 AddFaceWithTextureScaled(newBrush1, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,\r
509                         min[1], min[2], max[1], max[2]);\r
510                 AddFaceWithTextureScaled(newBrush1, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,\r
511                         max[1], min[2], min[1], max[2]);\r
512 \r
513                 \r
514                 AddFaceWithTextureScaled(newBrush2, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,\r
515                         min[1], min[2], max[1], max[2]);\r
516                 AddFaceWithTextureScaled(newBrush2, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,\r
517                         max[1], min[2], min[1], max[2]);        // flip max/min to reverse tex dir\r
518 \r
519 \r
520                 AddFaceWithTextureScaled(newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,\r
521                         min[0], min[2], max[0], max[2]);\r
522 \r
523                 AddFaceWithTextureScaled(newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,\r
524                         max[0], min[2], min[0], max[2]);\r
525         }\r
526 \r
527         //----------------------------------\r
528         \r
529 \r
530         entity_t* pEDoor1 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();\r
531         entity_t* pEDoor2 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();\r
532 \r
533         epair_t* epDoor11 = GetNextChainItem(NULL, "classname", "func_door");\r
534         epair_t* epDoor21 = GetNextChainItem(NULL, "classname", "func_door");\r
535 \r
536         epair_t* epDoor12;\r
537         epair_t* epDoor22;\r
538 \r
539         if(direction == 0)\r
540         {\r
541                 epDoor12 = GetNextChainItem(epDoor11, "angle", "180");\r
542                 epDoor22 = GetNextChainItem(epDoor21, "angle", "360");\r
543         }\r
544         else\r
545         {\r
546                 epDoor12 = GetNextChainItem(epDoor11, "angle", "270");\r
547                 epDoor22 = GetNextChainItem(epDoor21, "angle", "90");\r
548         }\r
549 \r
550         srand((unsigned)time(NULL));\r
551 \r
552         char teamname[256];\r
553         sprintf(teamname, "t%i", rand());\r
554         /*epair_t* epDoor13 = */ GetNextChainItem(epDoor12, "team", teamname);\r
555         /*epair_t* epDoor23 = */ GetNextChainItem(epDoor22, "team", teamname);\r
556 \r
557         g_FuncTable.m_pfnCommitBrushHandleToEntity(newBrush1, pEDoor1);\r
558         g_FuncTable.m_pfnCommitBrushHandleToEntity(newBrush2, pEDoor2);\r
559 \r
560         g_EntityTable.m_pfnSetEntityKeyValList(pEDoor1, epDoor11);\r
561         g_EntityTable.m_pfnSetEntityKeyValList(pEDoor2, epDoor21);\r
562 \r
563         g_FuncTable.m_pfnCommitEntityHandleToMap(pEDoor1);\r
564         g_FuncTable.m_pfnCommitEntityHandleToMap(pEDoor2);\r
565 \r
566 //      ResetCurrentTexture();\r
567 }\r
568 \r
569 //-----------------------------------------------------------------------------------\r
570 //-----------------------------------------------------------------------------------\r
571 \r
572 void MakeBevel(vec3_t vMin, vec3_t vMax)\r
573 {\r
574         int nIndex = g_FuncTable.m_pfnCreatePatchHandle();\r
575     //$ FIXME: m_pfnGetPatchHandle\r
576   patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData(nIndex);\r
577 \r
578         pm->height = 3;\r
579         pm->width = 3;\r
580 \r
581         vec3_t x_3, y_3, z_3;\r
582         x_3[0] = vMin[0];       x_3[1] = vMin[0];                               x_3[2] = vMax[0];\r
583         y_3[0] = vMin[1];       y_3[1] = vMax[1];                               y_3[2] = vMax[1];\r
584         z_3[0] = vMin[2];       z_3[1] = (vMax[2] + vMin[2])/2; z_3[2] = vMax[2];\r
585 \r
586 /*      x_3[0] = 0;             x_3[1] = 0;             x_3[2] = 64;\r
587         y_3[0] = 0;             y_3[1] = 64;    y_3[2] = 64;\r
588         z_3[0] = 0;             z_3[1] = 32;    z_3[2] = 64;*/\r
589 \r
590         for(int i = 0; i < 3; i++)\r
591         {\r
592                 for(int j = 0; j < 3; j++)\r
593                 {\r
594                         pm->ctrl[i][j].xyz[0] = x_3[i];\r
595                         pm->ctrl[i][j].xyz[1] = y_3[i];\r
596                         pm->ctrl[i][j].xyz[2] = z_3[j];\r
597                 }\r
598         }\r
599 \r
600 \r
601         g_FuncTable.m_pfnCommitPatchHandleToMap(nIndex, pm, "textures/common/caulk");\r
602 }\r
603 \r
604 void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)\r
605 {\r
606         vec3_t* topPoints = new vec3_t[nSteps+1];\r
607         vec3_t* botPoints = new vec3_t[nSteps+1];\r
608 \r
609         bool bFacesUse[6] = {TRUE, TRUE, FALSE, TRUE, FALSE, FALSE};\r
610 \r
611         vec3_t centre;\r
612         VectorCopy(vMin, centre);\r
613         centre[0] = vMax[0];\r
614 \r
615         int height = (int)(vMax[2] - vMin[2]) / nSteps;\r
616 \r
617         vec3_t vTop, vBot;\r
618         VectorCopy(vMax, vTop);\r
619         VectorCopy(vMin, vBot);\r
620         vTop[2] = vMin[2] + height;\r
621 \r
622   int i;\r
623         for(i = 0; i <= nSteps; i++)\r
624         {\r
625                 VectorCopy(centre, topPoints[i]);\r
626                 VectorCopy(centre, botPoints[i]);\r
627                 \r
628                 topPoints[i][2] = vMax[2];\r
629                 botPoints[i][2] = vMin[2];\r
630 \r
631                 topPoints[i][0] -= 10 * sinf( Q_PI * i / ( 2 * nSteps ) );\r
632                 topPoints[i][1] += 10 * cosf( Q_PI * i / ( 2 * nSteps ) );\r
633 \r
634                 botPoints[i][0] = topPoints[i][0];\r
635                 botPoints[i][1] = topPoints[i][1];\r
636         }\r
637 \r
638         vec3_t tp[3];\r
639         for(int j = 0; j < 3; j++)\r
640                 VectorCopy(topPoints[j], tp[j]);\r
641 \r
642         for(i = 0; i < nSteps; i++)\r
643         {\r
644                 brush_t* brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);\r
645 \r
646                 for(int j = 0; j < 3; j++)\r
647                         tp[j][2] = vTop[2];\r
648 \r
649                 AddFaceWithTexture(brush, tp[2], tp[1], tp[0], mainTexture, FALSE);\r
650 \r
651                 AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE);\r
652                 AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE);\r
653 \r
654                 g_FuncTable.m_pfnCommitBrushHandle(brush);\r
655 \r
656                 vTop[2] += height;\r
657                 vBot[2] += height;\r
658         }\r
659 \r
660         delete[] topPoints;\r
661         delete[] botPoints;\r
662 \r
663         vMin[2] += height;\r
664         vMax[2] += height;\r
665         MakeBevel(vMin, vMax);\r
666 }\r