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
30 #include "funchandlers.h"
34 #include "refcounted_ptr.h"
43 //#include "dialogs-gtk.h"
45 /************************
47 ************************/
58 | / | / ----> WEST, definitely
64 /************************
66 ************************/
68 vec3_t g_Origin = {0.0f, 0.0f, 0.0f};
70 extern bool bFacesAll[];
72 /************************
74 ************************/
76 float Deg2Rad(float angle)
78 return (float)(angle*Q_PI/180);
81 void AddFaceWithTexture(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)
83 _QERFaceData faceData;
84 FillDefaultTexture(&faceData, va, vb, vc, texture);
86 faceData.m_texdef.contents |= FACE_DETAIL;
87 GlobalBrushCreator().addBrushFace(brush, faceData);
90 void AddFaceWithTextureScaled(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc,
91 const char* texture, bool bVertScale, bool bHorScale,
92 float minX, float minY, float maxX, float maxY)
94 qtexture_t* pqtTexInfo;
96 // TTimo: there used to be a call to pfnHasShader here
97 // this was not necessary. In Radiant everything is shader.
98 // If a texture doesn't have a shader script, a default shader object is used.
99 // The IShader object was leaking also
100 // collect texture info: sizes, etc
101 IShader* i = QERApp_Shader_ForName(texture);
102 pqtTexInfo = i->getTexture(); // shader width/height doesn't come out properly
106 float scale[2] = {0.5f, 0.5f};
107 float shift[2] = {0, 0};
111 int texWidth = pqtTexInfo->width;
112 float width = maxX - minX;
114 scale[0] = width/texWidth;
115 shift[0] = -(float)((int)maxX%(int)width)/scale[0];
120 int texHeight = pqtTexInfo->height;
121 float height = maxY - minY;
123 scale[1] = height/texHeight;
124 shift[1] = (float)((int)minY%(int)height)/scale[1];
127 _QERFaceData addFace;
128 FillDefaultTexture(&addFace, va, vb, vc, texture);
129 addFace.m_texdef.scale[0] = scale[0];
130 addFace.m_texdef.scale[1] = scale[1];
131 addFace.m_texdef.shift[0] = shift[0];
132 addFace.m_texdef.shift[1] = shift[1];
134 GlobalBrushCreator().addBrushFace(brush, addFace);
138 // shouldn't even get here, as default missing texture should be returned if
139 // texture doesn't exist, but just in case
140 AddFaceWithTexture(brush, va, vb, vc, texture, FALSE);
141 Sys_ERROR("BobToolz::Invalid Texture Name-> %s", texture);
143 // the IShader is not kept referenced, DecRef it
147 /************************
149 ************************/
151 void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
153 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
155 vec3_t v1, v2, v3, v5, v6, v7, v8;
175 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
178 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
180 if(dir != MOVE_NORTH)
181 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
183 if(dir != MOVE_SOUTH)
184 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
186 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
189 AddFaceWithTexture(newBrush, v1, v3, v5, "textures/common/caulk", FALSE);
192 AddFaceWithTexture(newBrush, v2, v6, v8, "textures/common/caulk", FALSE);
194 if(dir == MOVE_NORTH)
195 AddFaceWithTexture(newBrush, v1, v6, v5, "textures/common/caulk", FALSE);
197 if(dir == MOVE_SOUTH)
198 AddFaceWithTexture(newBrush, v7, v3, v8, "textures/common/caulk", FALSE);
203 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
206 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
208 if(dir != MOVE_NORTH)
209 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
211 if(dir != MOVE_SOUTH)
212 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
215 AddFaceWithTexture(newBrush, v6, v5, v7, "textures/common/caulk", FALSE);
218 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", FALSE);
221 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", FALSE);
223 if(dir == MOVE_NORTH)
224 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", FALSE);
226 if(dir == MOVE_SOUTH)
227 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE);
230 Node_getTraversable(GetWorldspawn())->insert(newBrush);
233 //-----------------------------------------------------------------------------------
234 //-----------------------------------------------------------------------------------
236 void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)
238 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
240 //----- Build Outer Bounds ---------
242 vec3_t v1, v2, v3, v5, v6, v7, v8;
258 //v8 needed this time, becoz of sloping faces (2-4-6-8)
260 //----------------------------------
262 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, detail);
267 AddFaceWithTexture(newBrush, v5, v2, v7, riserTexture, detail);
269 AddFaceWithTexture(newBrush, v5, v2, v7, "textures/common/caulk", detail);
275 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, detail);
277 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", detail);
280 if(dir != MOVE_NORTH)
282 if(dir == MOVE_SOUTH)
283 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, detail);
285 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", detail);
288 if(dir != MOVE_SOUTH)
290 if(dir == MOVE_NORTH)
291 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, detail);
293 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", detail);
298 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", detail);
301 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", detail);
303 if(dir == MOVE_NORTH)
304 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", detail);
306 if(dir == MOVE_SOUTH)
307 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);
309 Node_getTraversable(GetWorldspawn())->insert(newBrush);
312 //-----------------------------------------------------------------------------------
313 //-----------------------------------------------------------------------------------
315 // internal use only, to get a box without finishing construction
316 scene::Node& Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)
318 scene::Node& newBrush(GlobalBrushCreator().createBrush());
320 //----- Build Outer Bounds ---------
322 vec3_t v1, v2, v3, v5, v6, v7;
336 //----------------------------------
338 //----- Add Six Cube Faces ---------
341 AddFaceWithTexture(newBrush, v1, v2, v3, texture, FALSE);
343 AddFaceWithTexture(newBrush, v1, v3, v6, texture, FALSE);
345 AddFaceWithTexture(newBrush, v1, v7, v2, texture, FALSE);
348 AddFaceWithTexture(newBrush, v5, v6, v3, texture, FALSE);
350 AddFaceWithTexture(newBrush, v5, v2, v7, texture, FALSE);
352 AddFaceWithTexture(newBrush, v5, v7, v6, texture, FALSE);
354 //----------------------------------
359 scene::Node& Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
361 return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
364 //-----------------------------------------------------------------------------------
365 //-----------------------------------------------------------------------------------
367 void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)
369 scene::Node& newBrush(GlobalBrushCreator().createBrush());
371 //----- Build Outer Bounds ---------
373 vec3_t v1, v2, v3, v5, v6, v7;
387 //----------------------------------
389 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, FALSE);
390 // top gets current texture
393 if(direction == MOVE_EAST)
394 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, FALSE);
396 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
397 // west facing side, etc...
400 if(direction == MOVE_NORTH)
401 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, FALSE);
403 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
405 if(direction == MOVE_SOUTH)
406 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, FALSE);
408 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", FALSE);
410 if(direction == MOVE_WEST)
411 AddFaceWithTexture(newBrush, v7, v5, v2, riserTexture, FALSE);
413 AddFaceWithTexture(newBrush, v7, v5, v2, "textures/common/caulk", FALSE);
416 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
419 Node_getTraversable(GetWorldspawn())->insert(newBrush);
423 //-----------------------------------------------------------------------------------
424 //-----------------------------------------------------------------------------------
426 void BuildDoorsX2(vec3_t min, vec3_t max,
427 bool bSclMainHor, bool bSclMainVert,
428 bool bSclTrimHor, bool bSclTrimVert,
429 const char* mainTexture, const char* trimTexture,
438 //----- Build Outer Bounds ---------
440 vec3_t v1, v2, v3, v5, v6, v7, ve_1, ve_2, ve_3;
454 float width = (max[xy] - min[xy])/2;
458 VectorCopy(v1, ve_1);
459 VectorCopy(v3, ve_2);
460 VectorCopy(v6, ve_3);
464 VectorCopy(v7, ve_1);
465 VectorCopy(v1, ve_2);
466 VectorCopy(v2, ve_3);
473 //----------------------------------
475 NodeSmartReference newBrush1(GlobalBrushCreator().createBrush());
476 NodeSmartReference newBrush2(GlobalBrushCreator().createBrush());
478 AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE);
479 AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE);
481 AddFaceWithTexture(newBrush2, v1, v2, v3, "textures/common/caulk", FALSE);
482 AddFaceWithTexture(newBrush2, v5, v7, v6, "textures/common/caulk", FALSE);
486 AddFaceWithTexture(newBrush1, v1, v3, v6, "textures/common/caulk", FALSE);
487 AddFaceWithTexture(newBrush2, v5, v2, v7, "textures/common/caulk", FALSE);
491 AddFaceWithTexture(newBrush1, v1, v7, v2, "textures/common/caulk", FALSE);
492 AddFaceWithTexture(newBrush2, v5, v6, v3, "textures/common/caulk", FALSE);
497 AddFaceWithTextureScaled(newBrush1, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
498 min[0], min[2], max[0], max[2]);
499 AddFaceWithTextureScaled(newBrush1, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
500 max[0], min[2], min[0], max[2]);
503 AddFaceWithTextureScaled(newBrush2, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
504 min[0], min[2], max[0], max[2]);
505 AddFaceWithTextureScaled(newBrush2, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
506 max[0], min[2], min[0], max[2]); // flip max/min to reverse tex dir
510 AddFaceWithTextureScaled(newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
511 min[1], min[2], max[1], max[2]);
513 AddFaceWithTextureScaled(newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
514 max[1], min[2], min[1], max[2]);
518 AddFaceWithTextureScaled(newBrush1, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
519 min[1], min[2], max[1], max[2]);
520 AddFaceWithTextureScaled(newBrush1, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
521 max[1], min[2], min[1], max[2]);
524 AddFaceWithTextureScaled(newBrush2, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
525 min[1], min[2], max[1], max[2]);
526 AddFaceWithTextureScaled(newBrush2, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
527 max[1], min[2], min[1], max[2]); // flip max/min to reverse tex dir
530 AddFaceWithTextureScaled(newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
531 min[0], min[2], max[0], max[2]);
533 AddFaceWithTextureScaled(newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
534 max[0], min[2], min[0], max[2]);
537 //----------------------------------
540 NodeSmartReference pEDoor1 = GlobalEntityCreator().createEntity("func_door");
541 NodeSmartReference pEDoor2 = GlobalEntityCreator().createEntity("func_door");
545 pEDoor1->m_entity->setkeyvalue("angle", "180");
546 pEDoor2->m_entity->setkeyvalue("angle", "360");
550 pEDoor1->m_entity->setkeyvalue("angle", "270");
551 pEDoor2->m_entity->setkeyvalue("angle", "90");
554 srand((unsigned)time(NULL));
557 sprintf(teamname, "t%i", rand());
558 pEDoor1->m_entity->setkeyvalue("team", teamname);
559 pEDoor2->m_entity->setkeyvalue("team", teamname);
561 Node_getTraversable(pEDoor1)->insert(newBrush1);
562 Node_getTraversable(pEDoor2)->insert(newBrush2);
564 Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor1);
565 Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor2);
567 // ResetCurrentTexture();
570 //-----------------------------------------------------------------------------------
571 //-----------------------------------------------------------------------------------
573 void MakeBevel(vec3_t vMin, vec3_t vMax)
575 NodeSmartReference patch(GlobalPatchCreator().createPatch());
577 aabb_construct_for_vec3(&aabb, vMin, vMax);
579 patch->m_patch->ConstructPrefab(&aabb, eBevel, 2); // 2 == XY view
582 Node_getTraversable(GetWorldspawn())->insert(patch);
585 void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
587 vec3_t* topPoints = new vec3_t[nSteps+1];
588 vec3_t* botPoints = new vec3_t[nSteps+1];
590 bool bFacesUse[6] = {TRUE, TRUE, FALSE, TRUE, FALSE, FALSE};
593 VectorCopy(vMin, centre);
596 int height = (int)(vMax[2] - vMin[2]) / nSteps;
599 VectorCopy(vMax, vTop);
600 VectorCopy(vMin, vBot);
601 vTop[2] = vMin[2] + height;
604 for(i = 0; i <= nSteps; i++)
606 VectorCopy(centre, topPoints[i]);
607 VectorCopy(centre, botPoints[i]);
609 topPoints[i][2] = vMax[2];
610 botPoints[i][2] = vMin[2];
612 topPoints[i][0] -= 10 * sinf( Q_PI * i / ( 2 * nSteps ) );
613 topPoints[i][1] += 10 * cosf( Q_PI * i / ( 2 * nSteps ) );
615 botPoints[i][0] = topPoints[i][0];
616 botPoints[i][1] = topPoints[i][1];
620 for(int j = 0; j < 3; j++)
621 VectorCopy(topPoints[j], tp[j]);
623 for(i = 0; i < nSteps; i++)
625 scene::Node& brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
627 for(int j = 0; j < 3; j++)
630 AddFaceWithTexture(brush, tp[2], tp[1], tp[0], mainTexture, FALSE);
632 AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE);
633 AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE);
635 Node_getTraversable(GetWorldspawn())->insert(brush);
646 MakeBevel(vMin, vMax);