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 ){
64 return (float)( angle * Q_PI / 180 );
67 void AddFaceWithTexture( brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail ){
68 _QERFaceData faceData;
69 FillDefaultTexture( &faceData, va, vb, vc, texture );
71 faceData.m_nContents |= FACE_DETAIL;
74 g_FuncTable.m_pfnAddFaceData( brush, &faceData );
77 void AddFaceWithTextureScaled( brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc,
78 const char* texture, bool bVertScale, bool bHorScale,
79 float minX, float minY, float maxX, float maxY ){
80 g_ShadersTable.m_pfnShader_ForName( texture ); // need to call frist to load?
82 qtexture_t* pqtTexInfo;
84 // TTimo: there used to be a call to pfnHasShader here
85 // this was not necessary. In Radiant everything is shader.
86 // If a texture doesn't have a shader script, a default shader object is used.
87 // The IShader object was leaking also
88 // collect texture info: sizes, etc
89 IShader* i = g_ShadersTable.m_pfnShader_ForName( texture );
90 pqtTexInfo = i->getTexture(); // shader width/height doesn't come out properly
93 float scale[2] = {0.5f, 0.5f};
94 float shift[2] = {0, 0};
97 int texWidth = pqtTexInfo->width;
98 float width = maxX - minX;
100 scale[0] = width / texWidth;
101 shift[0] = -(float)( (int)maxX % (int)width ) / scale[0];
105 int texHeight = pqtTexInfo->height;
106 float height = maxY - minY;
108 scale[1] = height / texHeight;
109 shift[1] = (float)( (int)minY % (int)height ) / scale[1];
112 _QERFaceData addFace;
113 FillDefaultTexture( &addFace, va, vb, vc, texture );
114 addFace.m_fScale[0] = scale[0];
115 addFace.m_fScale[1] = scale[1];
116 addFace.m_fShift[0] = shift[0];
117 addFace.m_fShift[1] = shift[1];
119 g_FuncTable.m_pfnAddFaceData( brush, &addFace );
123 // shouldn't even get here, as default missing texture should be returned if
124 // texture doesn't exist, but just in case
125 AddFaceWithTexture( brush, va, vb, vc, texture, FALSE );
126 Sys_ERROR( "BobToolz::Invalid Texture Name-> %s", texture );
128 // the IShader is not kept referenced, DecRef it
132 /************************
134 ************************/
136 void Build_Wedge( int dir, vec3_t min, vec3_t max, bool bUp ){
137 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
139 vec3_t v1, v2, v3, v5, v6, v7, v8;
140 VectorCopy( min, v1 );
141 VectorCopy( min, v2 );
142 VectorCopy( min, v3 );
143 VectorCopy( max, v5 );
144 VectorCopy( max, v6 );
145 VectorCopy( max, v7 );
146 VectorCopy( max, v8 );
157 if ( dir != MOVE_EAST ) {
158 AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", FALSE );
161 if ( dir != MOVE_WEST ) {
162 AddFaceWithTexture( newBrush, v7, v5, v8, "textures/common/caulk", FALSE );
165 if ( dir != MOVE_NORTH ) {
166 AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", FALSE );
169 if ( dir != MOVE_SOUTH ) {
170 AddFaceWithTexture( newBrush, v3, v8, v6, "textures/common/caulk", FALSE );
173 AddFaceWithTexture( newBrush, v1, v2, v3, "textures/common/caulk", FALSE );
175 if ( dir == MOVE_EAST ) {
176 AddFaceWithTexture( newBrush, v1, v3, v5, "textures/common/caulk", FALSE );
179 if ( dir == MOVE_WEST ) {
180 AddFaceWithTexture( newBrush, v2, v6, v8, "textures/common/caulk", FALSE );
183 if ( dir == MOVE_NORTH ) {
184 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 if ( dir != MOVE_WEST ) {
194 AddFaceWithTexture( newBrush, v7, v5, v8, "textures/common/caulk", FALSE );
197 if ( dir != MOVE_EAST ) {
198 AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", FALSE );
201 if ( dir != MOVE_NORTH ) {
202 AddFaceWithTexture( newBrush, v3, v8, v6, "textures/common/caulk", FALSE );
205 if ( dir != MOVE_SOUTH ) {
206 AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", FALSE );
210 AddFaceWithTexture( newBrush, v6, v5, v7, "textures/common/caulk", FALSE );
212 if ( dir == MOVE_WEST ) {
213 AddFaceWithTexture( newBrush, v1, v5, v3, "textures/common/caulk", FALSE );
216 if ( dir == MOVE_EAST ) {
217 AddFaceWithTexture( newBrush, v2, v8, v6, "textures/common/caulk", FALSE );
220 if ( dir == MOVE_NORTH ) {
221 AddFaceWithTexture( newBrush, v1, v5, v6, "textures/common/caulk", FALSE );
224 if ( dir == MOVE_SOUTH ) {
225 AddFaceWithTexture( newBrush, v7, v8, v3, "textures/common/caulk", FALSE );
229 g_FuncTable.m_pfnCommitBrushHandle( newBrush );
232 //-----------------------------------------------------------------------------------
233 //-----------------------------------------------------------------------------------
235 void Build_StairStep_Wedge( int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail ){
236 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
238 //----- Build Outer Bounds ---------
240 vec3_t v1, v2, v3, v5, v6, v7, v8;
241 VectorCopy( min, v1 );
242 VectorCopy( min, v2 );
243 VectorCopy( min, v3 );
244 VectorCopy( max, v5 );
245 VectorCopy( max, v6 );
246 VectorCopy( max, v7 );
247 VectorCopy( max, v8 );
256 //v8 needed this time, becoz of sloping faces (2-4-6-8)
258 //----------------------------------
260 AddFaceWithTexture( newBrush, v6, v5, v7, mainTexture, detail );
262 if ( dir != MOVE_EAST ) {
263 if ( dir == MOVE_WEST ) {
264 AddFaceWithTexture( newBrush, v5, v2, v7, riserTexture, detail );
267 AddFaceWithTexture( newBrush, v5, v2, v7, "textures/common/caulk", detail );
271 if ( dir != MOVE_WEST ) {
272 if ( dir == MOVE_EAST ) {
273 AddFaceWithTexture( newBrush, v1, v3, v6, riserTexture, detail );
276 AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", detail );
280 if ( dir != MOVE_NORTH ) {
281 if ( dir == MOVE_SOUTH ) {
282 AddFaceWithTexture( newBrush, v3, v5, v6, riserTexture, detail );
285 AddFaceWithTexture( newBrush, v3, v5, v6, "textures/common/caulk", detail );
289 if ( dir != MOVE_SOUTH ) {
290 if ( dir == MOVE_NORTH ) {
291 AddFaceWithTexture( newBrush, v1, v7, v2, riserTexture, detail );
294 AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", detail );
299 if ( dir == MOVE_EAST ) {
300 AddFaceWithTexture( newBrush, v1, v5, v3, "textures/common/caulk", detail );
303 if ( dir == MOVE_WEST ) {
304 AddFaceWithTexture( newBrush, v2, v8, v6, "textures/common/caulk", detail );
307 if ( dir == MOVE_NORTH ) {
308 AddFaceWithTexture( newBrush, v1, v5, v6, "textures/common/caulk", detail );
311 if ( dir == MOVE_SOUTH ) {
312 AddFaceWithTexture( newBrush, v7, v8, v3, "textures/common/caulk", detail );
315 g_FuncTable.m_pfnCommitBrushHandle( newBrush );
318 //-----------------------------------------------------------------------------------
319 //-----------------------------------------------------------------------------------
321 // internal use only, to get a box without finishing construction
322 brush_t* Build_Get_BoundingCube_Selective( vec3_t min, vec3_t max, char* texture, bool* useFaces ){
323 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
325 //----- Build Outer Bounds ---------
327 vec3_t v1, v2, v3, v5, v6, v7;
328 VectorCopy( min, v1 );
329 VectorCopy( min, v2 );
330 VectorCopy( min, v3 );
331 VectorCopy( max, v5 );
332 VectorCopy( max, v6 );
333 VectorCopy( max, v7 );
341 //----------------------------------
343 //----- Add Six Cube Faces ---------
346 AddFaceWithTexture( newBrush, v1, v2, v3, texture, FALSE );
349 AddFaceWithTexture( newBrush, v1, v3, v6, texture, FALSE );
352 AddFaceWithTexture( newBrush, v1, v7, v2, texture, FALSE );
356 AddFaceWithTexture( newBrush, v5, v6, v3, texture, FALSE );
359 AddFaceWithTexture( newBrush, v5, v2, v7, texture, FALSE );
362 AddFaceWithTexture( newBrush, v5, v7, v6, texture, FALSE );
365 //----------------------------------
370 brush_t* Build_Get_BoundingCube( vec3_t min, vec3_t max, char* texture ){
371 return Build_Get_BoundingCube_Selective( min, max, texture, bFacesAll );
374 //-----------------------------------------------------------------------------------
375 //-----------------------------------------------------------------------------------
377 void Build_StairStep( vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction ){
378 brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
380 //----- Build Outer Bounds ---------
382 vec3_t v1, v2, v3, v5, v6, v7;
383 VectorCopy( min, v1 );
384 VectorCopy( min, v2 );
385 VectorCopy( min, v3 );
386 VectorCopy( max, v5 );
387 VectorCopy( max, v6 );
388 VectorCopy( max, v7 );
396 //----------------------------------
398 AddFaceWithTexture( newBrush, v6, v5, v7, mainTexture, FALSE );
399 // top gets current texture
402 if ( direction == MOVE_EAST ) {
403 AddFaceWithTexture( newBrush, v1, v3, v6, riserTexture, FALSE );
406 AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", FALSE );
408 // west facing side, etc...
411 if ( direction == MOVE_NORTH ) {
412 AddFaceWithTexture( newBrush, v1, v7, v2, riserTexture, FALSE );
415 AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", FALSE );
418 if ( direction == MOVE_SOUTH ) {
419 AddFaceWithTexture( newBrush, v3, v5, v6, riserTexture, FALSE );
422 AddFaceWithTexture( newBrush, v3, v5, v6, "textures/common/caulk", FALSE );
425 if ( direction == MOVE_WEST ) {
426 AddFaceWithTexture( newBrush, v7, v5, v2, riserTexture, FALSE );
429 AddFaceWithTexture( newBrush, v7, v5, v2, "textures/common/caulk", FALSE );
433 AddFaceWithTexture( newBrush, v1, v2, v3, "textures/common/caulk", FALSE );
436 g_FuncTable.m_pfnCommitBrushHandle( newBrush );
440 //-----------------------------------------------------------------------------------
441 //-----------------------------------------------------------------------------------
443 void BuildDoorsX2( vec3_t min, vec3_t max,
444 bool bSclMainHor, bool bSclMainVert,
445 bool bSclTrimHor, bool bSclTrimVert,
446 const char* mainTexture, const char* trimTexture,
449 if ( direction == 0 ) {
456 //----- Build Outer Bounds ---------
458 vec3_t v1, v2, v3, v5, v6, v7, ve_1, ve_2, ve_3;
459 VectorCopy( min, v1 );
460 VectorCopy( min, v2 );
461 VectorCopy( min, v3 );
462 VectorCopy( max, v5 );
463 VectorCopy( max, v6 );
464 VectorCopy( max, v7 );
472 float width = ( max[xy] - min[xy] ) / 2;
474 if ( direction == 0 ) {
475 VectorCopy( v1, ve_1 );
476 VectorCopy( v3, ve_2 );
477 VectorCopy( v6, ve_3 );
481 VectorCopy( v7, ve_1 );
482 VectorCopy( v1, ve_2 );
483 VectorCopy( v2, ve_3 );
490 //----------------------------------
492 brush_t* newBrush1 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
493 brush_t* newBrush2 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
495 AddFaceWithTexture( newBrush1, v1, v2, v3, "textures/common/caulk", FALSE );
496 AddFaceWithTexture( newBrush1, v5, v7, v6, "textures/common/caulk", FALSE );
498 AddFaceWithTexture( newBrush2, v1, v2, v3, "textures/common/caulk", FALSE );
499 AddFaceWithTexture( newBrush2, v5, v7, v6, "textures/common/caulk", FALSE );
501 if ( direction == 0 ) {
502 AddFaceWithTexture( newBrush1, v1, v3, v6, "textures/common/caulk", FALSE );
503 AddFaceWithTexture( newBrush2, v5, v2, v7, "textures/common/caulk", FALSE );
507 AddFaceWithTexture( newBrush1, v1, v7, v2, "textures/common/caulk", FALSE );
508 AddFaceWithTexture( newBrush2, v5, v6, v3, "textures/common/caulk", FALSE );
511 if ( direction == 0 ) {
512 AddFaceWithTextureScaled( newBrush1, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
513 min[0], min[2], max[0], max[2] );
514 AddFaceWithTextureScaled( newBrush1, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
515 max[0], min[2], min[0], max[2] );
518 AddFaceWithTextureScaled( newBrush2, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
519 min[0], min[2], max[0], max[2] );
520 AddFaceWithTextureScaled( newBrush2, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
521 max[0], min[2], min[0], max[2] ); // flip max/min to reverse tex dir
525 AddFaceWithTextureScaled( newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
526 min[1], min[2], max[1], max[2] );
528 AddFaceWithTextureScaled( newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
529 max[1], min[2], min[1], max[2] );
533 AddFaceWithTextureScaled( newBrush1, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
534 min[1], min[2], max[1], max[2] );
535 AddFaceWithTextureScaled( newBrush1, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
536 max[1], min[2], min[1], max[2] );
539 AddFaceWithTextureScaled( newBrush2, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
540 min[1], min[2], max[1], max[2] );
541 AddFaceWithTextureScaled( newBrush2, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
542 max[1], min[2], min[1], max[2] ); // flip max/min to reverse tex dir
545 AddFaceWithTextureScaled( newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
546 min[0], min[2], max[0], max[2] );
548 AddFaceWithTextureScaled( newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
549 max[0], min[2], min[0], max[2] );
552 //----------------------------------
555 entity_t* pEDoor1 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
556 entity_t* pEDoor2 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
558 epair_t* epDoor11 = GetNextChainItem( NULL, "classname", "func_door" );
559 epair_t* epDoor21 = GetNextChainItem( NULL, "classname", "func_door" );
564 if ( direction == 0 ) {
565 epDoor12 = GetNextChainItem( epDoor11, "angle", "180" );
566 epDoor22 = GetNextChainItem( epDoor21, "angle", "360" );
570 epDoor12 = GetNextChainItem( epDoor11, "angle", "270" );
571 epDoor22 = GetNextChainItem( epDoor21, "angle", "90" );
574 srand( (unsigned)time( NULL ) );
577 sprintf( teamname, "t%i", rand() );
578 /*epair_t* epDoor13 = */ GetNextChainItem( epDoor12, "team", teamname );
579 /*epair_t* epDoor23 = */ GetNextChainItem( epDoor22, "team", teamname );
581 g_FuncTable.m_pfnCommitBrushHandleToEntity( newBrush1, pEDoor1 );
582 g_FuncTable.m_pfnCommitBrushHandleToEntity( newBrush2, pEDoor2 );
584 g_EntityTable.m_pfnSetEntityKeyValList( pEDoor1, epDoor11 );
585 g_EntityTable.m_pfnSetEntityKeyValList( pEDoor2, epDoor21 );
587 g_FuncTable.m_pfnCommitEntityHandleToMap( pEDoor1 );
588 g_FuncTable.m_pfnCommitEntityHandleToMap( pEDoor2 );
590 // ResetCurrentTexture();
593 //-----------------------------------------------------------------------------------
594 //-----------------------------------------------------------------------------------
596 void MakeBevel( vec3_t vMin, vec3_t vMax ){
597 int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
598 //$ FIXME: m_pfnGetPatchHandle
599 patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData( nIndex );
604 vec3_t x_3, y_3, z_3;
605 x_3[0] = vMin[0]; x_3[1] = vMin[0]; x_3[2] = vMax[0];
606 y_3[0] = vMin[1]; y_3[1] = vMax[1]; y_3[2] = vMax[1];
607 z_3[0] = vMin[2]; z_3[1] = ( vMax[2] + vMin[2] ) / 2; z_3[2] = vMax[2];
609 /* x_3[0] = 0; x_3[1] = 0; x_3[2] = 64;
610 y_3[0] = 0; y_3[1] = 64; y_3[2] = 64;
611 z_3[0] = 0; z_3[1] = 32; z_3[2] = 64;*/
613 for ( int i = 0; i < 3; i++ )
615 for ( int j = 0; j < 3; j++ )
617 pm->ctrl[i][j].xyz[0] = x_3[i];
618 pm->ctrl[i][j].xyz[1] = y_3[i];
619 pm->ctrl[i][j].xyz[2] = z_3[j];
624 g_FuncTable.m_pfnCommitPatchHandleToMap( nIndex, pm, "textures/common/caulk" );
627 void BuildCornerStairs( vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex ){
628 vec3_t* topPoints = new vec3_t[nSteps + 1];
629 vec3_t* botPoints = new vec3_t[nSteps + 1];
631 bool bFacesUse[6] = {TRUE, TRUE, FALSE, TRUE, FALSE, FALSE};
634 VectorCopy( vMin, centre );
637 int height = (int)( vMax[2] - vMin[2] ) / nSteps;
640 VectorCopy( vMax, vTop );
641 VectorCopy( vMin, vBot );
642 vTop[2] = vMin[2] + height;
645 for ( i = 0; i <= nSteps; i++ )
647 VectorCopy( centre, topPoints[i] );
648 VectorCopy( centre, botPoints[i] );
650 topPoints[i][2] = vMax[2];
651 botPoints[i][2] = vMin[2];
653 topPoints[i][0] -= 10 * sinf( Q_PI * i / ( 2 * nSteps ) );
654 topPoints[i][1] += 10 * cosf( Q_PI * i / ( 2 * nSteps ) );
656 botPoints[i][0] = topPoints[i][0];
657 botPoints[i][1] = topPoints[i][1];
661 for ( int j = 0; j < 3; j++ )
662 VectorCopy( topPoints[j], tp[j] );
664 for ( i = 0; i < nSteps; i++ )
666 brush_t* brush = Build_Get_BoundingCube_Selective( vBot, vTop, "textures/common/caulk", bFacesUse );
668 for ( int j = 0; j < 3; j++ )
671 AddFaceWithTexture( brush, tp[2], tp[1], tp[0], mainTexture, FALSE );
673 AddFaceWithTexture( brush, centre, botPoints[i + 1], topPoints[i + 1], "textures/common/caulk", FALSE );
674 AddFaceWithTexture( brush, centre, topPoints[i], botPoints[i], riserTex, FALSE );
676 g_FuncTable.m_pfnCommitBrushHandle( brush );
687 MakeBevel( vMin, vMax );