2 BobToolz plugin for GtkRadiant
\r
3 Copyright (C) 2001 Gordon Biggans
\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
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
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
28 #include "funchandlers.h"
\r
30 //#include "dialogs-gtk.h"
\r
32 /************************
\r
34 ************************/
\r
45 | / | / ----> WEST, definitely
\r
51 /************************
\r
53 ************************/
\r
55 vec3_t g_Origin = {0.0f, 0.0f, 0.0f};
\r
57 extern bool bFacesAll[];
\r
59 /************************
\r
61 ************************/
\r
63 float Deg2Rad(float angle)
\r
65 return (float)(angle*Q_PI/180);
\r
68 void AddFaceWithTexture(brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)
\r
70 _QERFaceData faceData;
\r
71 FillDefaultTexture(&faceData, va, vb, vc, texture);
\r
73 faceData.m_nContents |= FACE_DETAIL;
\r
75 g_FuncTable.m_pfnAddFaceData(brush, &faceData);
\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
82 g_ShadersTable.m_pfnShader_ForName(texture); // need to call frist to load?
\r
84 qtexture_t* pqtTexInfo;
\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
96 float scale[2] = {0.5f, 0.5f};
\r
97 float shift[2] = {0, 0};
\r
101 int texWidth = pqtTexInfo->width;
\r
102 float width = maxX - minX;
\r
104 scale[0] = width/texWidth;
\r
105 shift[0] = -(float)((int)maxX%(int)width)/scale[0];
\r
110 int texHeight = pqtTexInfo->height;
\r
111 float height = maxY - minY;
\r
113 scale[1] = height/texHeight;
\r
114 shift[1] = (float)((int)minY%(int)height)/scale[1];
\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
124 g_FuncTable.m_pfnAddFaceData(brush, &addFace);
\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
133 // the IShader is not kept referenced, DecRef it
\r
137 /************************
\r
139 ************************/
\r
141 void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
\r
143 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
\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
164 if(dir != MOVE_EAST)
\r
165 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
\r
167 if(dir != MOVE_WEST)
\r
168 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
\r
170 if(dir != MOVE_NORTH)
\r
171 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
\r
173 if(dir != MOVE_SOUTH)
\r
174 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
\r
176 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
\r
178 if(dir == MOVE_EAST)
\r
179 AddFaceWithTexture(newBrush, v1, v3, v5, "textures/common/caulk", FALSE);
\r
181 if(dir == MOVE_WEST)
\r
182 AddFaceWithTexture(newBrush, v2, v6, v8, "textures/common/caulk", FALSE);
\r
184 if(dir == MOVE_NORTH)
\r
185 AddFaceWithTexture(newBrush, v1, v6, v5, "textures/common/caulk", FALSE);
\r
187 if(dir == MOVE_SOUTH)
\r
188 AddFaceWithTexture(newBrush, v7, v3, v8, "textures/common/caulk", FALSE);
\r
192 if(dir != MOVE_WEST)
\r
193 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
\r
195 if(dir != MOVE_EAST)
\r
196 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
\r
198 if(dir != MOVE_NORTH)
\r
199 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
\r
201 if(dir != MOVE_SOUTH)
\r
202 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
\r
205 AddFaceWithTexture(newBrush, v6, v5, v7, "textures/common/caulk", FALSE);
\r
207 if(dir == MOVE_WEST)
\r
208 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", FALSE);
\r
210 if(dir == MOVE_EAST)
\r
211 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", FALSE);
\r
213 if(dir == MOVE_NORTH)
\r
214 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", FALSE);
\r
216 if(dir == MOVE_SOUTH)
\r
217 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE);
\r
220 g_FuncTable.m_pfnCommitBrushHandle(newBrush);
\r
223 //-----------------------------------------------------------------------------------
\r
224 //-----------------------------------------------------------------------------------
\r
226 void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)
\r
228 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
\r
230 //----- Build Outer Bounds ---------
\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
248 //v8 needed this time, becoz of sloping faces (2-4-6-8)
\r
250 //----------------------------------
\r
252 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, detail);
\r
254 if(dir != MOVE_EAST)
\r
256 if(dir == MOVE_WEST)
\r
257 AddFaceWithTexture(newBrush, v5, v2, v7, riserTexture, detail);
\r
259 AddFaceWithTexture(newBrush, v5, v2, v7, "textures/common/caulk", detail);
\r
262 if(dir != MOVE_WEST)
\r
264 if(dir == MOVE_EAST)
\r
265 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, detail);
\r
267 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", detail);
\r
270 if(dir != MOVE_NORTH)
\r
272 if(dir == MOVE_SOUTH)
\r
273 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, detail);
\r
275 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", detail);
\r
278 if(dir != MOVE_SOUTH)
\r
280 if(dir == MOVE_NORTH)
\r
281 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, detail);
\r
283 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", detail);
\r
287 if(dir == MOVE_EAST)
\r
288 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", detail);
\r
290 if(dir == MOVE_WEST)
\r
291 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", detail);
\r
293 if(dir == MOVE_NORTH)
\r
294 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", detail);
\r
296 if(dir == MOVE_SOUTH)
\r
297 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);
\r
299 g_FuncTable.m_pfnCommitBrushHandle(newBrush);
\r
302 //-----------------------------------------------------------------------------------
\r
303 //-----------------------------------------------------------------------------------
\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
308 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
\r
310 //----- Build Outer Bounds ---------
\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
326 //----------------------------------
\r
328 //----- Add Six Cube Faces ---------
\r
331 AddFaceWithTexture(newBrush, v1, v2, v3, texture, FALSE);
\r
333 AddFaceWithTexture(newBrush, v1, v3, v6, texture, FALSE);
\r
335 AddFaceWithTexture(newBrush, v1, v7, v2, texture, FALSE);
\r
338 AddFaceWithTexture(newBrush, v5, v6, v3, texture, FALSE);
\r
340 AddFaceWithTexture(newBrush, v5, v2, v7, texture, FALSE);
\r
342 AddFaceWithTexture(newBrush, v5, v7, v6, texture, FALSE);
\r
344 //----------------------------------
\r
349 brush_t* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
\r
351 return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
\r
354 //-----------------------------------------------------------------------------------
\r
355 //-----------------------------------------------------------------------------------
\r
357 void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)
\r
359 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
\r
361 //----- Build Outer Bounds ---------
\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
377 //----------------------------------
\r
379 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, FALSE);
\r
380 // top gets current texture
\r
383 if(direction == MOVE_EAST)
\r
384 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, FALSE);
\r
386 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
\r
387 // west facing side, etc...
\r
390 if(direction == MOVE_NORTH)
\r
391 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, FALSE);
\r
393 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
\r
395 if(direction == MOVE_SOUTH)
\r
396 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, FALSE);
\r
398 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", FALSE);
\r
400 if(direction == MOVE_WEST)
\r
401 AddFaceWithTexture(newBrush, v7, v5, v2, riserTexture, FALSE);
\r
403 AddFaceWithTexture(newBrush, v7, v5, v2, "textures/common/caulk", FALSE);
\r
406 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
\r
409 g_FuncTable.m_pfnCommitBrushHandle(newBrush);
\r
413 //-----------------------------------------------------------------------------------
\r
414 //-----------------------------------------------------------------------------------
\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
428 //----- Build Outer Bounds ---------
\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
444 float width = (max[xy] - min[xy])/2;
\r
448 VectorCopy(v1, ve_1);
\r
449 VectorCopy(v3, ve_2);
\r
450 VectorCopy(v6, ve_3);
\r
454 VectorCopy(v7, ve_1);
\r
455 VectorCopy(v1, ve_2);
\r
456 VectorCopy(v2, ve_3);
\r
463 //----------------------------------
\r
465 brush_t* newBrush1 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
\r
466 brush_t* newBrush2 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
\r
468 AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE);
\r
469 AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE);
\r
471 AddFaceWithTexture(newBrush2, v1, v2, v3, "textures/common/caulk", FALSE);
\r
472 AddFaceWithTexture(newBrush2, v5, v7, v6, "textures/common/caulk", FALSE);
\r
476 AddFaceWithTexture(newBrush1, v1, v3, v6, "textures/common/caulk", FALSE);
\r
477 AddFaceWithTexture(newBrush2, v5, v2, v7, "textures/common/caulk", FALSE);
\r
481 AddFaceWithTexture(newBrush1, v1, v7, v2, "textures/common/caulk", FALSE);
\r
482 AddFaceWithTexture(newBrush2, v5, v6, v3, "textures/common/caulk", FALSE);
\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
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
500 AddFaceWithTextureScaled(newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
\r
501 min[1], min[2], max[1], max[2]);
\r
503 AddFaceWithTextureScaled(newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
\r
504 max[1], min[2], min[1], max[2]);
\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
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
520 AddFaceWithTextureScaled(newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
\r
521 min[0], min[2], max[0], max[2]);
\r
523 AddFaceWithTextureScaled(newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
\r
524 max[0], min[2], min[0], max[2]);
\r
527 //----------------------------------
\r
530 entity_t* pEDoor1 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
\r
531 entity_t* pEDoor2 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
\r
533 epair_t* epDoor11 = GetNextChainItem(NULL, "classname", "func_door");
\r
534 epair_t* epDoor21 = GetNextChainItem(NULL, "classname", "func_door");
\r
541 epDoor12 = GetNextChainItem(epDoor11, "angle", "180");
\r
542 epDoor22 = GetNextChainItem(epDoor21, "angle", "360");
\r
546 epDoor12 = GetNextChainItem(epDoor11, "angle", "270");
\r
547 epDoor22 = GetNextChainItem(epDoor21, "angle", "90");
\r
550 srand((unsigned)time(NULL));
\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
557 g_FuncTable.m_pfnCommitBrushHandleToEntity(newBrush1, pEDoor1);
\r
558 g_FuncTable.m_pfnCommitBrushHandleToEntity(newBrush2, pEDoor2);
\r
560 g_EntityTable.m_pfnSetEntityKeyValList(pEDoor1, epDoor11);
\r
561 g_EntityTable.m_pfnSetEntityKeyValList(pEDoor2, epDoor21);
\r
563 g_FuncTable.m_pfnCommitEntityHandleToMap(pEDoor1);
\r
564 g_FuncTable.m_pfnCommitEntityHandleToMap(pEDoor2);
\r
566 // ResetCurrentTexture();
\r
569 //-----------------------------------------------------------------------------------
\r
570 //-----------------------------------------------------------------------------------
\r
572 void MakeBevel(vec3_t vMin, vec3_t vMax)
\r
574 int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
\r
575 //$ FIXME: m_pfnGetPatchHandle
\r
576 patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData(nIndex);
\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
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
590 for(int i = 0; i < 3; i++)
\r
592 for(int j = 0; j < 3; j++)
\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
601 g_FuncTable.m_pfnCommitPatchHandleToMap(nIndex, pm, "textures/common/caulk");
\r
604 void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
\r
606 vec3_t* topPoints = new vec3_t[nSteps+1];
\r
607 vec3_t* botPoints = new vec3_t[nSteps+1];
\r
609 bool bFacesUse[6] = {TRUE, TRUE, FALSE, TRUE, FALSE, FALSE};
\r
612 VectorCopy(vMin, centre);
\r
613 centre[0] = vMax[0];
\r
615 int height = (int)(vMax[2] - vMin[2]) / nSteps;
\r
618 VectorCopy(vMax, vTop);
\r
619 VectorCopy(vMin, vBot);
\r
620 vTop[2] = vMin[2] + height;
\r
623 for(i = 0; i <= nSteps; i++)
\r
625 VectorCopy(centre, topPoints[i]);
\r
626 VectorCopy(centre, botPoints[i]);
\r
628 topPoints[i][2] = vMax[2];
\r
629 botPoints[i][2] = vMin[2];
\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
634 botPoints[i][0] = topPoints[i][0];
\r
635 botPoints[i][1] = topPoints[i][1];
\r
639 for(int j = 0; j < 3; j++)
\r
640 VectorCopy(topPoints[j], tp[j]);
\r
642 for(i = 0; i < nSteps; i++)
\r
644 brush_t* brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
\r
646 for(int j = 0; j < 3; j++)
\r
647 tp[j][2] = vTop[2];
\r
649 AddFaceWithTexture(brush, tp[2], tp[1], tp[0], mainTexture, FALSE);
\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
654 g_FuncTable.m_pfnCommitBrushHandle(brush);
\r
660 delete[] topPoints;
\r
661 delete[] botPoints;
\r
665 MakeBevel(vMin, vMax);
\r