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
20 // DShape.cpp: implementation of the DShape class.
22 //////////////////////////////////////////////////////////////////////
37 //#include "dialogs-gtk.h"
42 //////////////////////////////////////////////////////////////////////
43 // Construction/Destruction
44 //////////////////////////////////////////////////////////////////////
46 bool bFacesAll[6] = {true, true, true, true, true, true};
56 void DShape::BuildRegularPrism( vec3_t min, vec3_t max, int nSides, bool bAlignTop ){
57 vec3_t vc[MAX_POLYGON_FACES + 2], vd[MAX_POLYGON_FACES + 2];
62 VectorSubtract( max, min, radius );
63 VectorScale( radius, 0.5f, radius );
64 // calc 3d radius and origin
65 VectorAdd( max, min, origin );
66 VectorScale( origin, 0.5f, origin );
71 phase = -( Q_PI / nSides );
72 VectorScale( radius, static_cast<float>( 1.0 / cos( phase ) ), radius );
75 //----- Build Polygon Vertices -----
78 for ( i = 0; i < nSides; i++ )
80 VectorCopy( origin, vc[i] );
81 VectorCopy( origin, vd[i] );
86 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
87 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
93 VectorCopy( vc[0], vc[nSides] );
94 VectorCopy( vd[0], vd[nSides] );
95 VectorCopy( vc[1], vc[nSides + 1] );
96 VectorCopy( vd[1], vd[nSides + 1] );
98 //----------------------------------
100 DBrush* pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ );
102 for ( i = 1; i <= nSides; i++ )
103 pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), false );
105 pB->AddFace( vc[2], vc[1], vc[0], "textures/common/caulk", false );
106 pB->AddFace( vd[0], vd[1], vd[2], "textures/common/caulk", false );
109 void DShape::Commit(){
110 m_Container.GetWorldSpawn()->FixBrushes();
111 m_Container.BuildInRadiant( true );
114 void DShape::BuildInversePrism( vec3_t min, vec3_t max, int nSides, bool bAlignTop ){
115 vec3_t va[MAX_POLYGON_FACES + 1], vb[MAX_POLYGON_FACES + 1];
119 VectorSubtract( max, min, radius );
120 VectorScale( radius, 0.5f, radius );
121 // calc 3d radius and origin
122 VectorAdd( max, min, origin );
123 VectorScale( origin, 0.5f, origin );
128 phase = -( Q_PI / nSides );
129 VectorScale( radius, static_cast<float>( 1.0 / cos( phase ) ), radius );
132 //----- Build Polygon Vertices -----
135 for ( i = 0; i < nSides; i++ )
137 VectorCopy( origin, va[i] );
138 VectorCopy( origin, vb[i] );
143 va[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
144 va[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
150 VectorCopy( va[0], va[nSides] );
151 VectorCopy( vb[0], vb[nSides] );
153 //----------------------------------
155 for ( i = 1; i <= nSides; i++ )
157 DBrush* pB = GetBoundingCube( min, max, "textures/common/caulk" );
160 VectorCopy( va[i - 1], top );
161 VectorCopy( va[i], bottom );
163 if ( va[i - 1][1] > va[i][1] ) {
167 else // flip direction of plane on crossover
173 if ( top[1] != bottom[1] ) { // internal line is flat already if true
174 pB->AddFace( va[i - 1], top, vb[i - 1], "textures/common/caulk", false );
175 pB->AddFace( va[i], vb[i], bottom, "textures/common/caulk", false );
176 } // add cut-off planes
178 pB->AddFace( va[i - 1], vb[i - 1], vb[i], GetCurrentTexture(), false );
179 // add internal polygon plane
183 void DShape::BuildBorderedPrism( vec3_t min, vec3_t max, int nSides, int nBorder, bool bAlignTop ){
184 vec3_t va[MAX_POLYGON_FACES + 2], vb[MAX_POLYGON_FACES + 2];
185 vec3_t vc[MAX_POLYGON_FACES + 2], vd[MAX_POLYGON_FACES + 2];
190 VectorSubtract( max, min, radius );
191 VectorScale( radius, 0.5f, radius );
192 // calc 3d radius and origin
193 VectorAdd( max, min, origin );
194 VectorScale( origin, 0.5f, origin );
196 if ( nBorder >= Min( radius[0], radius[1] ) ) {
197 // DoMessageBox("Border is too large", "Error", MB_OK);
204 phase = -( Q_PI / nSides );
205 VectorScale( radius, static_cast<float>( 1.0 / cos( phase ) ), radius );
208 //----- Build Polygon Vertices -----
211 for ( i = 0; i < nSides; i++ )
213 VectorCopy( origin, va[i] );
214 VectorCopy( origin, vb[i] );
215 VectorCopy( origin, vc[i] );
216 VectorCopy( origin, vd[i] );
221 va[i][0] += ( radius[0] - nBorder ) * sinf( ( 2 * Q_PI * i / nSides ) + phase );
222 va[i][1] += ( radius[1] - nBorder ) * cosf( ( 2 * Q_PI * i / nSides ) + phase );
232 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
233 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
239 VectorCopy( va[0], va[nSides] );
240 VectorCopy( vb[0], vb[nSides] );
241 VectorCopy( va[1], va[nSides + 1] );
242 VectorCopy( vb[1], vb[nSides + 1] );
244 VectorCopy( vc[0], vc[nSides] );
245 VectorCopy( vd[0], vd[nSides] );
246 VectorCopy( vc[1], vc[nSides + 1] );
247 VectorCopy( vd[1], vd[nSides + 1] );
249 //----------------------------------
251 for ( i = 1; i <= nSides; i++ )
253 DBrush* pB = GetBoundingCube( min, max, "textures/common/caulk" );
255 pB->AddFace( origin, vc[i - 1], vd[i - 1], "textures/common/caulk", false );
256 pB->AddFace( origin, vd[i], vc[i], "textures/common/caulk", false );
258 pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), false );
259 pB->AddFace( vb[i], va[i], va[i - 1], GetCurrentTexture(), false );
263 DBrush* DShape::GetBoundingCube_Ext( vec3_t min, vec3_t max, const char *textureName, bool* bUseFaces, bool detail ){
264 DBrush* pB = new DBrush;
265 //----- Build Outer Bounds ---------
267 vec3_t v1, v2, v3, v5, v6, v7;
268 VectorCopy( min, v1 );
269 VectorCopy( min, v2 );
270 VectorCopy( min, v3 );
271 VectorCopy( max, v5 );
272 VectorCopy( max, v6 );
273 VectorCopy( max, v7 );
281 //----------------------------------
283 //----- Add Six Cube Faces ---------
285 if ( bUseFaces[0] ) {
286 pB->AddFace( v1, v2, v3, textureName, detail );
288 if ( bUseFaces[1] ) {
289 pB->AddFace( v1, v3, v6, textureName, detail );
291 if ( bUseFaces[2] ) {
292 pB->AddFace( v1, v7, v2, textureName, detail );
295 if ( bUseFaces[3] ) {
296 pB->AddFace( v5, v6, v3, textureName, detail );
298 if ( bUseFaces[4] ) {
299 pB->AddFace( v5, v2, v7, textureName, detail );
301 if ( bUseFaces[5] ) {
302 pB->AddFace( v5, v7, v6, textureName, detail );
305 //----------------------------------
310 DBrush* DShape::GetBoundingCube( vec3_t min, vec3_t max, const char *textureName, DEntity* ent, bool* bUseFaces ){
313 pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ );
316 pB = ent->NewBrush( m_nNextBrush++ );
319 //----- Build Outer Bounds ---------
321 vec3_t v1, v2, v3, v5, v6, v7;
322 VectorCopy( min, v1 );
323 VectorCopy( min, v2 );
324 VectorCopy( min, v3 );
325 VectorCopy( max, v5 );
326 VectorCopy( max, v6 );
327 VectorCopy( max, v7 );
335 //----------------------------------
337 //----- Add Six Cube Faces ---------
339 if ( bUseFaces[0] ) {
340 pB->AddFace( v1, v2, v3, textureName, false );
342 if ( bUseFaces[1] ) {
343 pB->AddFace( v1, v3, v6, textureName, false );
345 if ( bUseFaces[2] ) {
346 pB->AddFace( v1, v7, v2, textureName, false );
349 if ( bUseFaces[3] ) {
350 pB->AddFace( v5, v6, v3, textureName, false );
352 if ( bUseFaces[4] ) {
353 pB->AddFace( v5, v2, v7, textureName, false );
355 if ( bUseFaces[5] ) {
356 pB->AddFace( v5, v7, v6, textureName, false );
359 //----------------------------------
364 bool DShape::BuildPit( vec3_t min, vec3_t max ){
365 if ( ( max[2] - min[2] ) < 196 ) {
369 srand( time( NULL ) );
372 VectorAdd( min, max, centre );
373 VectorScale( centre, 0.5f, centre );
377 int team = ( rand() % 10000 ) + 5000;
379 // ************* SPEAKER ***************
380 sprintf( buffer, "t%i_1", team );
382 // trigger for speaker
383 vec3_t triggerVoiceBtm;
384 VectorCopy( min, triggerVoiceBtm );
385 triggerVoiceBtm[2] = max[2] - 16;
387 DEntity* triggerVoice = m_Container.AddEntity( "trigger_multiple" );
388 GetBoundingCube( triggerVoiceBtm, max, "textures/common/trigger", triggerVoice );
389 triggerVoice->AddEPair( "target", buffer );
390 //--------------------
392 // target for speaker
394 VectorCopy( centre, voiceOrigin );
395 voiceOrigin[2] = max[2] + 16;
398 DEntity* targetVoice = m_Container.AddEntity( "target_speaker" );
399 targetVoice->AddEPair( "targetname", buffer );
401 sprintf( buffer, "%f %f %f", voiceOrigin[0], voiceOrigin[1], voiceOrigin[2] );
402 targetVoice->AddEPair( "origin", buffer );
403 targetVoice->AddEPair( "spawnflags", "8" );
404 targetVoice->AddEPair( "noise", "*falling1.wav" );
405 //--------------------
407 // *********** END SPEAKER *************
409 // ********* POWERUP REMOVAL ***********
410 sprintf( buffer, "t%i_2", team );
412 // trigger for powerup removal
413 vec3_t triggerPwrRmvTop, triggerPwrRmvBtm;
414 VectorCopy( min, triggerPwrRmvBtm );
415 VectorCopy( max, triggerPwrRmvTop );
417 triggerPwrRmvTop[2] = triggerVoiceBtm[2] - 64;
418 triggerPwrRmvBtm[2] = triggerPwrRmvTop[2] - 16;
420 DEntity* triggerPwrRmv = m_Container.AddEntity( "trigger_multiple" );
421 GetBoundingCube( triggerPwrRmvBtm, triggerPwrRmvTop, "textures/common/trigger", triggerPwrRmv );
422 triggerPwrRmv->AddEPair( "target", buffer );
423 //--------------------
425 // target for powerup removal
427 VectorCopy( centre, pwrRmvOrigin );
428 pwrRmvOrigin[2] = triggerPwrRmvTop[2] + 16;
430 DEntity* targetPwrRmv = m_Container.AddEntity( "target_remove_powerups" );
431 targetPwrRmv->AddEPair( "targetname", buffer );
433 sprintf( buffer, "%f %f %f", pwrRmvOrigin[0], pwrRmvOrigin[1], pwrRmvOrigin[2] );
434 targetPwrRmv->AddEPair( "origin", buffer );
435 //--------------------
437 // ****** END POWERUP REMOVAL ********
439 // ********* DAMAGE ***********
441 // trigger for damage
442 vec3_t triggerDmgTop, triggerDmgBtm;
443 VectorCopy( min, triggerDmgBtm );
444 VectorCopy( max, triggerDmgTop );
446 triggerDmgBtm[2] = min[2] + 64;
447 triggerDmgTop[2] = triggerDmgBtm[2] + 16;
449 DEntity* triggerDmg = m_Container.AddEntity( "trigger_hurt" );
450 GetBoundingCube( triggerDmgBtm, triggerDmgTop, "textures/common/trigger", triggerDmg );
451 triggerDmg->AddEPair( "dmg", "9999" );
452 triggerDmg->AddEPair( "spawnflags", "12" );
453 //--------------------
455 // ****** END DAMAGE ********
457 // ********* NODROP ***********
460 VectorCopy( max, nodropTop );
462 nodropTop[2] = min[2] + 64;
464 GetBoundingCube( min, nodropTop, "textures/common/nodrop" );
466 // ****** END NODROP ********