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
25 #include "gtkr_list.h"
32 #include "funchandlers.h"
36 #include "refcounted_ptr.h"
45 //#include "dialogs-gtk.h"
47 /************************
49 ************************/
60 | / | / ----> WEST, definitely
66 /************************
68 ************************/
70 vec3_t g_Origin = {0.0f, 0.0f, 0.0f};
72 extern bool bFacesAll[];
74 /************************
76 ************************/
78 float Deg2Rad(float angle)
80 return (float)(angle*Q_PI/180);
83 void AddFaceWithTexture(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)
85 _QERFaceData faceData;
86 FillDefaultTexture(&faceData, va, vb, vc, texture);
88 faceData.m_texdef.contents |= FACE_DETAIL;
90 brush->m_brush->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_texdef);
94 void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc,
95 const char* texture, bool bVertScale, bool bHorScale,
96 float minX, float minY, float maxX, float maxY)
98 qtexture_t* pqtTexInfo;
100 // TTimo: there used to be a call to pfnHasShader here
101 // this was not necessary. In Radiant everything is shader.
102 // If a texture doesn't have a shader script, a default shader object is used.
103 // The IShader object was leaking also
104 // collect texture info: sizes, etc
105 IShader* i = QERApp_Shader_ForName(texture);
106 pqtTexInfo = i->getTexture(); // shader width/height doesn't come out properly
110 float scale[2] = {0.5f, 0.5f};
111 float shift[2] = {0, 0};
115 int texWidth = pqtTexInfo->width;
116 float width = maxX - minX;
118 scale[0] = width/texWidth;
119 shift[0] = -(float)((int)maxX%(int)width)/scale[0];
124 int texHeight = pqtTexInfo->height;
125 float height = maxY - minY;
127 scale[1] = height/texHeight;
128 shift[1] = (float)((int)minY%(int)height)/scale[1];
131 _QERFaceData addFace;
132 FillDefaultTexture(&addFace, va, vb, vc, texture);
133 addFace.m_texdef.scale[0] = scale[0];
134 addFace.m_texdef.scale[1] = scale[1];
135 addFace.m_texdef.shift[0] = shift[0];
136 addFace.m_texdef.shift[1] = shift[1];
139 brush->m_brush->addPlane(addFace.m_p0, addFace.m_p1, addFace.m_p2, addFace.m_texdef);
144 // shouldn't even get here, as default missing texture should be returned if
145 // texture doesn't exist, but just in case
146 AddFaceWithTexture(brush, va, vb, vc, texture, FALSE);
147 Sys_ERROR("BobToolz::Invalid Texture Name-> %s", texture);
149 // the IShader is not kept referenced, DecRef it
153 /************************
155 ************************/
157 void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
159 scene::Node* newBrush = Brush_AllocNode();
161 vec3_t v1, v2, v3, v5, v6, v7, v8;
181 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
184 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
186 if(dir != MOVE_NORTH)
187 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
189 if(dir != MOVE_SOUTH)
190 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
192 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
195 AddFaceWithTexture(newBrush, v1, v3, v5, "textures/common/caulk", FALSE);
198 AddFaceWithTexture(newBrush, v2, v6, v8, "textures/common/caulk", FALSE);
200 if(dir == MOVE_NORTH)
201 AddFaceWithTexture(newBrush, v1, v6, v5, "textures/common/caulk", FALSE);
203 if(dir == MOVE_SOUTH)
204 AddFaceWithTexture(newBrush, v7, v3, v8, "textures/common/caulk", FALSE);
209 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", FALSE);
212 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
214 if(dir != MOVE_NORTH)
215 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", FALSE);
217 if(dir != MOVE_SOUTH)
218 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
221 AddFaceWithTexture(newBrush, v6, v5, v7, "textures/common/caulk", FALSE);
224 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", FALSE);
227 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", FALSE);
229 if(dir == MOVE_NORTH)
230 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", FALSE);
232 if(dir == MOVE_SOUTH)
233 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE);
236 GetWorldspawn()->m_traverse->insert(newBrush);
239 //-----------------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------------
242 void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)
244 scene::Node* newBrush = Brush_AllocNode();
246 //----- Build Outer Bounds ---------
248 vec3_t v1, v2, v3, v5, v6, v7, v8;
264 //v8 needed this time, becoz of sloping faces (2-4-6-8)
266 //----------------------------------
268 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, detail);
273 AddFaceWithTexture(newBrush, v5, v2, v7, riserTexture, detail);
275 AddFaceWithTexture(newBrush, v5, v2, v7, "textures/common/caulk", detail);
281 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, detail);
283 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", detail);
286 if(dir != MOVE_NORTH)
288 if(dir == MOVE_SOUTH)
289 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, detail);
291 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", detail);
294 if(dir != MOVE_SOUTH)
296 if(dir == MOVE_NORTH)
297 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, detail);
299 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", detail);
304 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", detail);
307 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", detail);
309 if(dir == MOVE_NORTH)
310 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", detail);
312 if(dir == MOVE_SOUTH)
313 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);
315 GetWorldspawn()->m_traverse->insert(newBrush);
318 //-----------------------------------------------------------------------------------
319 //-----------------------------------------------------------------------------------
321 // internal use only, to get a box without finishing construction
322 scene::Node* Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)
324 scene::Node* newBrush = Brush_AllocNode();
326 //----- Build Outer Bounds ---------
328 vec3_t v1, v2, v3, v5, v6, v7;
342 //----------------------------------
344 //----- Add Six Cube Faces ---------
347 AddFaceWithTexture(newBrush, v1, v2, v3, texture, FALSE);
349 AddFaceWithTexture(newBrush, v1, v3, v6, texture, FALSE);
351 AddFaceWithTexture(newBrush, v1, v7, v2, texture, FALSE);
354 AddFaceWithTexture(newBrush, v5, v6, v3, texture, FALSE);
356 AddFaceWithTexture(newBrush, v5, v2, v7, texture, FALSE);
358 AddFaceWithTexture(newBrush, v5, v7, v6, texture, FALSE);
360 //----------------------------------
365 scene::Node* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
367 return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
370 //-----------------------------------------------------------------------------------
371 //-----------------------------------------------------------------------------------
373 void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)
375 scene::Node* newBrush = Brush_AllocNode();
377 //----- Build Outer Bounds ---------
379 vec3_t v1, v2, v3, v5, v6, v7;
393 //----------------------------------
395 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, FALSE);
396 // top gets current texture
399 if(direction == MOVE_EAST)
400 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, FALSE);
402 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", FALSE);
403 // west facing side, etc...
406 if(direction == MOVE_NORTH)
407 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, FALSE);
409 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", FALSE);
411 if(direction == MOVE_SOUTH)
412 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, FALSE);
414 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", FALSE);
416 if(direction == MOVE_WEST)
417 AddFaceWithTexture(newBrush, v7, v5, v2, riserTexture, FALSE);
419 AddFaceWithTexture(newBrush, v7, v5, v2, "textures/common/caulk", FALSE);
422 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
425 GetWorldspawn()->m_traverse->insert(newBrush);
429 //-----------------------------------------------------------------------------------
430 //-----------------------------------------------------------------------------------
432 void BuildDoorsX2(vec3_t min, vec3_t max,
433 bool bSclMainHor, bool bSclMainVert,
434 bool bSclTrimHor, bool bSclTrimVert,
435 const char* mainTexture, const char* trimTexture,
444 //----- Build Outer Bounds ---------
446 vec3_t v1, v2, v3, v5, v6, v7, ve_1, ve_2, ve_3;
460 float width = (max[xy] - min[xy])/2;
464 VectorCopy(v1, ve_1);
465 VectorCopy(v3, ve_2);
466 VectorCopy(v6, ve_3);
470 VectorCopy(v7, ve_1);
471 VectorCopy(v1, ve_2);
472 VectorCopy(v2, ve_3);
479 //----------------------------------
481 scene::Node* newBrush1 = Brush_AllocNode();
482 scene::Node* newBrush2 = Brush_AllocNode();
484 AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE);
485 AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE);
487 AddFaceWithTexture(newBrush2, v1, v2, v3, "textures/common/caulk", FALSE);
488 AddFaceWithTexture(newBrush2, v5, v7, v6, "textures/common/caulk", FALSE);
492 AddFaceWithTexture(newBrush1, v1, v3, v6, "textures/common/caulk", FALSE);
493 AddFaceWithTexture(newBrush2, v5, v2, v7, "textures/common/caulk", FALSE);
497 AddFaceWithTexture(newBrush1, v1, v7, v2, "textures/common/caulk", FALSE);
498 AddFaceWithTexture(newBrush2, v5, v6, v3, "textures/common/caulk", FALSE);
503 AddFaceWithTextureScaled(newBrush1, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
504 min[0], min[2], max[0], max[2]);
505 AddFaceWithTextureScaled(newBrush1, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
506 max[0], min[2], min[0], max[2]);
509 AddFaceWithTextureScaled(newBrush2, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
510 min[0], min[2], max[0], max[2]);
511 AddFaceWithTextureScaled(newBrush2, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
512 max[0], min[2], min[0], max[2]); // flip max/min to reverse tex dir
516 AddFaceWithTextureScaled(newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
517 min[1], min[2], max[1], max[2]);
519 AddFaceWithTextureScaled(newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
520 max[1], min[2], min[1], max[2]);
524 AddFaceWithTextureScaled(newBrush1, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
525 min[1], min[2], max[1], max[2]);
526 AddFaceWithTextureScaled(newBrush1, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
527 max[1], min[2], min[1], max[2]);
530 AddFaceWithTextureScaled(newBrush2, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
531 min[1], min[2], max[1], max[2]);
532 AddFaceWithTextureScaled(newBrush2, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
533 max[1], min[2], min[1], max[2]); // flip max/min to reverse tex dir
536 AddFaceWithTextureScaled(newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
537 min[0], min[2], max[0], max[2]);
539 AddFaceWithTextureScaled(newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
540 max[0], min[2], min[0], max[2]);
543 //----------------------------------
546 scene::Node* pEDoor1 = GlobalEntityCreator().createEntity("func_door");
547 scene::Node* pEDoor2 = GlobalEntityCreator().createEntity("func_door");
551 pEDoor1->m_entity->setkeyvalue("angle", "180");
552 pEDoor2->m_entity->setkeyvalue("angle", "360");
556 pEDoor1->m_entity->setkeyvalue("angle", "270");
557 pEDoor2->m_entity->setkeyvalue("angle", "90");
560 srand((unsigned)time(NULL));
563 sprintf(teamname, "t%i", rand());
564 pEDoor1->m_entity->setkeyvalue("team", teamname);
565 pEDoor2->m_entity->setkeyvalue("team", teamname);
567 pEDoor1->m_traverse->insert(newBrush1);
568 pEDoor2->m_traverse->insert(newBrush2);
570 GlobalSceneGraph().root()->m_traverse->insert(pEDoor1);
571 GlobalSceneGraph().root()->m_traverse->insert(pEDoor2);
573 // ResetCurrentTexture();
576 //-----------------------------------------------------------------------------------
577 //-----------------------------------------------------------------------------------
579 void MakeBevel(vec3_t vMin, vec3_t vMax)
581 scene::Node* patch = Patch_AllocNode();
583 aabb_construct_for_vec3(&aabb, vMin, vMax);
585 patch->m_patch->ConstructPrefab(&aabb, eBevel, 2); // 2 == XY view
588 GetWorldspawn()->m_traverse->insert(patch);
591 void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
593 vec3_t* topPoints = new vec3_t[nSteps+1];
594 vec3_t* botPoints = new vec3_t[nSteps+1];
596 bool bFacesUse[6] = {TRUE, TRUE, FALSE, TRUE, FALSE, FALSE};
599 VectorCopy(vMin, centre);
602 int height = (int)(vMax[2] - vMin[2]) / nSteps;
605 VectorCopy(vMax, vTop);
606 VectorCopy(vMin, vBot);
607 vTop[2] = vMin[2] + height;
610 for(i = 0; i <= nSteps; i++)
612 VectorCopy(centre, topPoints[i]);
613 VectorCopy(centre, botPoints[i]);
615 topPoints[i][2] = vMax[2];
616 botPoints[i][2] = vMin[2];
618 topPoints[i][0] -= 10 * sinf( Q_PI * i / ( 2 * nSteps ) );
619 topPoints[i][1] += 10 * cosf( Q_PI * i / ( 2 * nSteps ) );
621 botPoints[i][0] = topPoints[i][0];
622 botPoints[i][1] = topPoints[i][1];
626 for(int j = 0; j < 3; j++)
627 VectorCopy(topPoints[j], tp[j]);
629 for(i = 0; i < nSteps; i++)
631 scene::Node* brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
633 for(int j = 0; j < 3; j++)
636 AddFaceWithTexture(brush, tp[2], tp[1], tp[0], mainTexture, FALSE);
638 AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE);
639 AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE);
641 GetWorldspawn()->m_traverse->insert(brush);
652 MakeBevel(vMin, vMax);