2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
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.
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.
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
28 #include "funchandlers.h"
30 //#include "dialogs-gtk.h"
32 /************************
34 ************************/
45 | / | / ----> WEST, definitely
51 /************************
53 ************************/
55 vec3_t g_Origin = {0.0f, 0.0f, 0.0f};
57 extern bool bFacesAll[];
59 /************************
61 ************************/
63 float Deg2Rad(float angle)
65 return (float)(angle*Q_PI/180);
68 void AddFaceWithTexture(brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)
70 _QERFaceData faceData;
71 FillDefaultTexture(&faceData, va, vb, vc, texture);
73 faceData.m_nContents |= FACE_DETAIL;
75 g_FuncTable.m_pfnAddFaceData(brush, &faceData);
78 void AddFaceWithTextureScaled(brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc,
79 const char* texture, bool bVertScale, bool bHorScale,
80 float minX, float minY, float maxX, float maxY)
82 g_ShadersTable.m_pfnShader_ForName(texture); // need to call frist to load?
84 qtexture_t* pqtTexInfo;
86 // TTimo: there used to be a call to pfnHasShader here
87 // this was not necessary. In Radiant everything is shader.
88 // If a texture doesn't have a shader script, a default shader object is used.
89 // The IShader object was leaking also
90 // collect texture info: sizes, etc
91 IShader* i = g_ShadersTable.m_pfnShader_ForName(texture);
92 pqtTexInfo = i->getTexture(); // shader width/height doesn't come out properly
96 float scale[2] = {0.5f, 0.5f};
97 float shift[2] = {0, 0};
101 int texWidth = pqtTexInfo->width;
102 float width = maxX - minX;
104 scale[0] = width/texWidth;
105 shift[0] = -(float)((int)maxX%(int)width)/scale[0];
110 int texHeight = pqtTexInfo->height;
111 float height = maxY - minY;
113 scale[1] = height/texHeight;
114 shift[1] = (float)((int)minY%(int)height)/scale[1];
117 _QERFaceData addFace;
118 FillDefaultTexture(&addFace, va, vb, vc, texture);
119 addFace.m_fScale[0] = scale[0];
120 addFace.m_fScale[1] = scale[1];
121 addFace.m_fShift[0] = shift[0];
122 addFace.m_fShift[1] = shift[1];
124 g_FuncTable.m_pfnAddFaceData(brush, &addFace);
128 // shouldn't even get here, as default missing texture should be returned if
129 // texture doesn't exist, but just in case
130 AddFaceWithTexture(brush, va, vb, vc, texture, FALSE);
131 Sys_ERROR("BobToolz::Invalid Texture Name-> %s", texture);
133 // the IShader is not kept referenced, DecRef it
137 /************************
139 ************************/
141 void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
143 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
145 vec3_t v1, v2, v3, v5, v6, v7, v8;
165 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
168 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
170 if(dir != MOVE_NORTH)
171 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
173 if(dir != MOVE_SOUTH)
174 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
176 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
179 AddFaceWithTexture(newBrush, v1, v3, v5, "textures/common/caulk", FALSE);
182 AddFaceWithTexture(newBrush, v2, v6, v8, "textures/common/caulk", FALSE);
184 if(dir == MOVE_NORTH)
185 AddFaceWithTexture(newBrush, v1, v6, v5, "textures/common/caulk", FALSE);
187 if(dir == MOVE_SOUTH)
188 AddFaceWithTexture(newBrush, v7, v3, v8, "textures/common/caulk", FALSE);
193 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
196 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
198 if(dir != MOVE_NORTH)
199 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
201 if(dir != MOVE_SOUTH)
202 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
205 AddFaceWithTexture(newBrush, v6, v5, v7, "textures/common/caulk", FALSE);
208 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", FALSE);
211 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", FALSE);
213 if(dir == MOVE_NORTH)
214 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", FALSE);
216 if(dir == MOVE_SOUTH)
217 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE);
220 g_FuncTable.m_pfnCommitBrushHandle(newBrush);
223 //-----------------------------------------------------------------------------------
224 //-----------------------------------------------------------------------------------
226 void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)
228 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
230 //----- Build Outer Bounds ---------
232 vec3_t v1, v2, v3, v5, v6, v7, v8;
248 //v8 needed this time, becoz of sloping faces (2-4-6-8)
250 //----------------------------------
252 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, detail);
257 AddFaceWithTexture(newBrush, v5, v2, v7, riserTexture, detail);
259 AddFaceWithTexture(newBrush, v5, v2, v7, "textures/common/caulk", detail);
265 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, detail);
267 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", detail);
270 if(dir != MOVE_NORTH)
272 if(dir == MOVE_SOUTH)
273 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, detail);
275 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", detail);
278 if(dir != MOVE_SOUTH)
280 if(dir == MOVE_NORTH)
281 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, detail);
283 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", detail);
288 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", detail);
291 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", detail);
293 if(dir == MOVE_NORTH)
294 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", detail);
296 if(dir == MOVE_SOUTH)
297 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);
299 g_FuncTable.m_pfnCommitBrushHandle(newBrush);
302 //-----------------------------------------------------------------------------------
303 //-----------------------------------------------------------------------------------
305 // internal use only, to get a box without finishing construction
306 brush_t* Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)
308 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
310 //----- Build Outer Bounds ---------
312 vec3_t v1, v2, v3, v5, v6, v7;
326 //----------------------------------
328 //----- Add Six Cube Faces ---------
331 AddFaceWithTexture(newBrush, v1, v2, v3, texture, FALSE);
333 AddFaceWithTexture(newBrush, v1, v3, v6, texture, FALSE);
335 AddFaceWithTexture(newBrush, v1, v7, v2, texture, FALSE);
338 AddFaceWithTexture(newBrush, v5, v6, v3, texture, FALSE);
340 AddFaceWithTexture(newBrush, v5, v2, v7, texture, FALSE);
342 AddFaceWithTexture(newBrush, v5, v7, v6, texture, FALSE);
344 //----------------------------------
349 brush_t* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
351 return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
354 //-----------------------------------------------------------------------------------
355 //-----------------------------------------------------------------------------------
357 void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)
359 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
361 //----- Build Outer Bounds ---------
363 vec3_t v1, v2, v3, v5, v6, v7;
377 //----------------------------------
379 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, FALSE);
380 // top gets current texture
383 if(direction == MOVE_EAST)
384 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, FALSE);
386 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
387 // west facing side, etc...
390 if(direction == MOVE_NORTH)
391 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, FALSE);
393 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
395 if(direction == MOVE_SOUTH)
396 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, FALSE);
398 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", FALSE);
400 if(direction == MOVE_WEST)
401 AddFaceWithTexture(newBrush, v7, v5, v2, riserTexture, FALSE);
403 AddFaceWithTexture(newBrush, v7, v5, v2, "textures/common/caulk", FALSE);
406 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
409 g_FuncTable.m_pfnCommitBrushHandle(newBrush);
413 //-----------------------------------------------------------------------------------
414 //-----------------------------------------------------------------------------------
416 void BuildDoorsX2(vec3_t min, vec3_t max,
417 bool bSclMainHor, bool bSclMainVert,
418 bool bSclTrimHor, bool bSclTrimVert,
419 const char* mainTexture, const char* trimTexture,
428 //----- Build Outer Bounds ---------
430 vec3_t v1, v2, v3, v5, v6, v7, ve_1, ve_2, ve_3;
444 float width = (max[xy] - min[xy])/2;
448 VectorCopy(v1, ve_1);
449 VectorCopy(v3, ve_2);
450 VectorCopy(v6, ve_3);
454 VectorCopy(v7, ve_1);
455 VectorCopy(v1, ve_2);
456 VectorCopy(v2, ve_3);
463 //----------------------------------
465 brush_t* newBrush1 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
466 brush_t* newBrush2 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
468 AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE);
469 AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE);
471 AddFaceWithTexture(newBrush2, v1, v2, v3, "textures/common/caulk", FALSE);
472 AddFaceWithTexture(newBrush2, v5, v7, v6, "textures/common/caulk", FALSE);
476 AddFaceWithTexture(newBrush1, v1, v3, v6, "textures/common/caulk", FALSE);
477 AddFaceWithTexture(newBrush2, v5, v2, v7, "textures/common/caulk", FALSE);
481 AddFaceWithTexture(newBrush1, v1, v7, v2, "textures/common/caulk", FALSE);
482 AddFaceWithTexture(newBrush2, v5, v6, v3, "textures/common/caulk", FALSE);
487 AddFaceWithTextureScaled(newBrush1, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
488 min[0], min[2], max[0], max[2]);
489 AddFaceWithTextureScaled(newBrush1, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
490 max[0], min[2], min[0], max[2]);
493 AddFaceWithTextureScaled(newBrush2, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
494 min[0], min[2], max[0], max[2]);
495 AddFaceWithTextureScaled(newBrush2, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
496 max[0], min[2], min[0], max[2]); // flip max/min to reverse tex dir
500 AddFaceWithTextureScaled(newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
501 min[1], min[2], max[1], max[2]);
503 AddFaceWithTextureScaled(newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
504 max[1], min[2], min[1], max[2]);
508 AddFaceWithTextureScaled(newBrush1, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
509 min[1], min[2], max[1], max[2]);
510 AddFaceWithTextureScaled(newBrush1, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
511 max[1], min[2], min[1], max[2]);
514 AddFaceWithTextureScaled(newBrush2, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
515 min[1], min[2], max[1], max[2]);
516 AddFaceWithTextureScaled(newBrush2, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
517 max[1], min[2], min[1], max[2]); // flip max/min to reverse tex dir
520 AddFaceWithTextureScaled(newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
521 min[0], min[2], max[0], max[2]);
523 AddFaceWithTextureScaled(newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
524 max[0], min[2], min[0], max[2]);
527 //----------------------------------
530 entity_t* pEDoor1 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
531 entity_t* pEDoor2 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
533 epair_t* epDoor11 = GetNextChainItem(NULL, "classname", "func_door");
534 epair_t* epDoor21 = GetNextChainItem(NULL, "classname", "func_door");
541 epDoor12 = GetNextChainItem(epDoor11, "angle", "180");
542 epDoor22 = GetNextChainItem(epDoor21, "angle", "360");
546 epDoor12 = GetNextChainItem(epDoor11, "angle", "270");
547 epDoor22 = GetNextChainItem(epDoor21, "angle", "90");
550 srand((unsigned)time(NULL));
553 sprintf(teamname, "t%i", rand());
554 /*epair_t* epDoor13 = */ GetNextChainItem(epDoor12, "team", teamname);
555 /*epair_t* epDoor23 = */ GetNextChainItem(epDoor22, "team", teamname);
557 g_FuncTable.m_pfnCommitBrushHandleToEntity(newBrush1, pEDoor1);
558 g_FuncTable.m_pfnCommitBrushHandleToEntity(newBrush2, pEDoor2);
560 g_EntityTable.m_pfnSetEntityKeyValList(pEDoor1, epDoor11);
561 g_EntityTable.m_pfnSetEntityKeyValList(pEDoor2, epDoor21);
563 g_FuncTable.m_pfnCommitEntityHandleToMap(pEDoor1);
564 g_FuncTable.m_pfnCommitEntityHandleToMap(pEDoor2);
566 // ResetCurrentTexture();
569 //-----------------------------------------------------------------------------------
570 //-----------------------------------------------------------------------------------
572 void MakeBevel(vec3_t vMin, vec3_t vMax)
574 int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
575 //$ FIXME: m_pfnGetPatchHandle
576 patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData(nIndex);
581 vec3_t x_3, y_3, z_3;
582 x_3[0] = vMin[0]; x_3[1] = vMin[0]; x_3[2] = vMax[0];
583 y_3[0] = vMin[1]; y_3[1] = vMax[1]; y_3[2] = vMax[1];
584 z_3[0] = vMin[2]; z_3[1] = (vMax[2] + vMin[2])/2; z_3[2] = vMax[2];
586 /* x_3[0] = 0; x_3[1] = 0; x_3[2] = 64;
587 y_3[0] = 0; y_3[1] = 64; y_3[2] = 64;
588 z_3[0] = 0; z_3[1] = 32; z_3[2] = 64;*/
590 for(int i = 0; i < 3; i++)
592 for(int j = 0; j < 3; j++)
594 pm->ctrl[i][j].xyz[0] = x_3[i];
595 pm->ctrl[i][j].xyz[1] = y_3[i];
596 pm->ctrl[i][j].xyz[2] = z_3[j];
601 g_FuncTable.m_pfnCommitPatchHandleToMap(nIndex, pm, "textures/common/caulk");
604 void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
606 vec3_t* topPoints = new vec3_t[nSteps+1];
607 vec3_t* botPoints = new vec3_t[nSteps+1];
609 bool bFacesUse[6] = {TRUE, TRUE, FALSE, TRUE, FALSE, FALSE};
612 VectorCopy(vMin, centre);
615 int height = (int)(vMax[2] - vMin[2]) / nSteps;
618 VectorCopy(vMax, vTop);
619 VectorCopy(vMin, vBot);
620 vTop[2] = vMin[2] + height;
623 for(i = 0; i <= nSteps; i++)
625 VectorCopy(centre, topPoints[i]);
626 VectorCopy(centre, botPoints[i]);
628 topPoints[i][2] = vMax[2];
629 botPoints[i][2] = vMin[2];
631 topPoints[i][0] -= 10 * sinf( Q_PI * i / ( 2 * nSteps ) );
632 topPoints[i][1] += 10 * cosf( Q_PI * i / ( 2 * nSteps ) );
634 botPoints[i][0] = topPoints[i][0];
635 botPoints[i][1] = topPoints[i][1];
639 for(int j = 0; j < 3; j++)
640 VectorCopy(topPoints[j], tp[j]);
642 for(i = 0; i < nSteps; i++)
644 brush_t* brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
646 for(int j = 0; j < 3; j++)
649 AddFaceWithTexture(brush, tp[2], tp[1], tp[0], mainTexture, FALSE);
651 AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE);
652 AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE);
654 g_FuncTable.m_pfnCommitBrushHandle(brush);
665 MakeBevel(vMin, vMax);