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 //////////////////////////////////////////////////////////////////////
27 //#include "dialogs-gtk.h"
32 //////////////////////////////////////////////////////////////////////
33 // Construction/Destruction
34 //////////////////////////////////////////////////////////////////////
36 bool bFacesAll[6] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};
46 void DShape::BuildRegularPrism( vec3_t min, vec3_t max, int nSides, bool bAlignTop ){
47 vec3_t vc[MAX_POLYGON_FACES + 2], vd[MAX_POLYGON_FACES + 2];
52 VectorSubtract( max, min, radius );
53 VectorScale( radius, 0.5f, radius );
54 // calc 3d radius and origin
55 VectorAdd( max, min, origin );
56 VectorScale( origin, 0.5f, origin );
61 phase = -( Q_PI / nSides );
62 VectorScale( radius, static_cast< float >( 1 / cos( phase ) ), radius );
65 //----- Build Polygon Vertices -----
68 for ( i = 0; i < nSides; i++ )
70 VectorCopy( origin, vc[i] );
71 VectorCopy( origin, vd[i] );
76 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
77 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
83 VectorCopy( vc[0], vc[nSides] );
84 VectorCopy( vd[0], vd[nSides] );
85 VectorCopy( vc[1], vc[nSides + 1] );
86 VectorCopy( vd[1], vd[nSides + 1] );
88 //----------------------------------
90 DBrush* pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ );
92 for ( i = 1; i <= nSides; i++ )
93 pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), FALSE );
95 pB->AddFace( vc[2], vc[1], vc[0], "textures/common/caulk", FALSE );
96 pB->AddFace( vd[0], vd[1], vd[2], "textures/common/caulk", FALSE );
99 void DShape::Commit(){
100 m_Container.GetWorldSpawn()->FixBrushes( FALSE );
101 m_Container.BuildInRadiant( TRUE );
104 void DShape::BuildInversePrism( vec3_t min, vec3_t max, int nSides, bool bAlignTop ){
105 vec3_t va[MAX_POLYGON_FACES + 1], vb[MAX_POLYGON_FACES + 1];
109 VectorSubtract( max, min, radius );
110 VectorScale( radius, 0.5f, radius );
111 // calc 3d radius and origin
112 VectorAdd( max, min, origin );
113 VectorScale( origin, 0.5f, origin );
118 phase = -( Q_PI / nSides );
119 VectorScale( radius, static_cast< float >( 1 / cos( phase ) ), radius );
122 //----- Build Polygon Vertices -----
125 for ( i = 0; i < nSides; i++ )
127 VectorCopy( origin, va[i] );
128 VectorCopy( origin, vb[i] );
133 va[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
134 va[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
140 VectorCopy( va[0], va[nSides] );
141 VectorCopy( vb[0], vb[nSides] );
143 //----------------------------------
145 for ( i = 1; i <= nSides; i++ )
147 DBrush* pB = GetBoundingCube( min, max, "textures/common/caulk" );
150 VectorCopy( va[i - 1], top );
151 VectorCopy( va[i], bottom );
153 if ( va[i - 1][1] > va[i][1] ) {
157 else // flip direction of plane on crossover
163 if ( top[1] != bottom[1] ) { // internal line is flat already if true
164 pB->AddFace( va[i - 1], top, vb[i - 1], "textures/common/caulk", FALSE );
165 pB->AddFace( va[i], vb[i], bottom, "textures/common/caulk", FALSE );
166 } // add cut-off planes
168 pB->AddFace( va[i - 1], vb[i - 1], vb[i], GetCurrentTexture(), FALSE );
169 // add internal polygon plane
173 void DShape::BuildBorderedPrism( vec3_t min, vec3_t max, int nSides, int nBorder, bool bAlignTop ){
174 vec3_t va[MAX_POLYGON_FACES + 2], vb[MAX_POLYGON_FACES + 2];
175 vec3_t vc[MAX_POLYGON_FACES + 2], vd[MAX_POLYGON_FACES + 2];
180 VectorSubtract( max, min, radius );
181 VectorScale( radius, 0.5f, radius );
182 // calc 3d radius and origin
183 VectorAdd( max, min, origin );
184 VectorScale( origin, 0.5f, origin );
186 if ( nBorder >= Min( radius[0], radius[1] ) ) {
187 // DoMessageBox("Border is too large", "Error", MB_OK);
194 phase = -( Q_PI / nSides );
195 VectorScale( radius, static_cast< float >( 1 / cos( phase ) ), radius );
198 //----- Build Polygon Vertices -----
201 for ( i = 0; i < nSides; i++ )
203 VectorCopy( origin, va[i] );
204 VectorCopy( origin, vb[i] );
205 VectorCopy( origin, vc[i] );
206 VectorCopy( origin, vd[i] );
211 va[i][0] += ( radius[0] - nBorder ) * sinf( ( 2 * Q_PI * i / nSides ) + phase );
212 va[i][1] += ( radius[1] - nBorder ) * cosf( ( 2 * Q_PI * i / nSides ) + phase );
222 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
223 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
229 VectorCopy( va[0], va[nSides] );
230 VectorCopy( vb[0], vb[nSides] );
231 VectorCopy( va[1], va[nSides + 1] );
232 VectorCopy( vb[1], vb[nSides + 1] );
234 VectorCopy( vc[0], vc[nSides] );
235 VectorCopy( vd[0], vd[nSides] );
236 VectorCopy( vc[1], vc[nSides + 1] );
237 VectorCopy( vd[1], vd[nSides + 1] );
239 //----------------------------------
241 for ( i = 1; i <= nSides; i++ )
243 DBrush* pB = GetBoundingCube( min, max, "textures/common/caulk" );
245 pB->AddFace( origin, vc[i - 1], vd[i - 1], "textures/common/caulk", FALSE );
246 pB->AddFace( origin, vd[i], vc[i], "textures/common/caulk", FALSE );
248 pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), FALSE );
249 pB->AddFace( vb[i], va[i], va[i - 1], GetCurrentTexture(), FALSE );
253 DBrush* DShape::GetBoundingCube_Ext( vec3_t min, vec3_t max, const char *textureName, bool* bUseFaces, bool detail ){
254 DBrush* pB = new DBrush;
255 //----- Build Outer Bounds ---------
257 vec3_t v1, v2, v3, v5, v6, v7;
258 VectorCopy( min, v1 );
259 VectorCopy( min, v2 );
260 VectorCopy( min, v3 );
261 VectorCopy( max, v5 );
262 VectorCopy( max, v6 );
263 VectorCopy( max, v7 );
271 //----------------------------------
273 //----- Add Six Cube Faces ---------
275 if ( bUseFaces[0] ) {
276 pB->AddFace( v1, v2, v3, textureName, detail );
278 if ( bUseFaces[1] ) {
279 pB->AddFace( v1, v3, v6, textureName, detail );
281 if ( bUseFaces[2] ) {
282 pB->AddFace( v1, v7, v2, textureName, detail );
285 if ( bUseFaces[3] ) {
286 pB->AddFace( v5, v6, v3, textureName, detail );
288 if ( bUseFaces[4] ) {
289 pB->AddFace( v5, v2, v7, textureName, detail );
291 if ( bUseFaces[5] ) {
292 pB->AddFace( v5, v7, v6, textureName, detail );
295 //----------------------------------
300 DBrush* DShape::GetBoundingCube( vec3_t min, vec3_t max, const char *textureName, DEntity* ent, bool* bUseFaces ){
303 pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ );
306 pB = ent->NewBrush( m_nNextBrush++ );
309 //----- Build Outer Bounds ---------
311 vec3_t v1, v2, v3, v5, v6, v7;
312 VectorCopy( min, v1 );
313 VectorCopy( min, v2 );
314 VectorCopy( min, v3 );
315 VectorCopy( max, v5 );
316 VectorCopy( max, v6 );
317 VectorCopy( max, v7 );
325 //----------------------------------
327 //----- Add Six Cube Faces ---------
329 if ( bUseFaces[0] ) {
330 pB->AddFace( v1, v2, v3, textureName, FALSE );
332 if ( bUseFaces[1] ) {
333 pB->AddFace( v1, v3, v6, textureName, FALSE );
335 if ( bUseFaces[2] ) {
336 pB->AddFace( v1, v7, v2, textureName, FALSE );
339 if ( bUseFaces[3] ) {
340 pB->AddFace( v5, v6, v3, textureName, FALSE );
342 if ( bUseFaces[4] ) {
343 pB->AddFace( v5, v2, v7, textureName, FALSE );
345 if ( bUseFaces[5] ) {
346 pB->AddFace( v5, v7, v6, textureName, FALSE );
349 //----------------------------------
354 bool DShape::BuildPit( vec3_t min, vec3_t max ){
355 if ( ( max[2] - min[2] ) < 196 ) {
359 srand( time( NULL ) );
362 VectorAdd( min, max, centre );
363 VectorScale( centre, 0.5f, centre );
367 int team = ( rand() % 10000 ) + 5000;
369 // ************* SPEAKER ***************
370 sprintf( buffer, "t%i_1", team );
372 // trigger for speaker
373 vec3_t triggerVoiceBtm;
374 VectorCopy( min, triggerVoiceBtm );
375 triggerVoiceBtm[2] = max[2] - 16;
377 DEntity* triggerVoice = m_Container.AddEntity( "trigger_multiple" );
378 GetBoundingCube( triggerVoiceBtm, max, "textures/common/trigger", triggerVoice );
379 triggerVoice->AddEPair( "target", buffer );
380 //--------------------
382 // target for speaker
384 VectorCopy( centre, voiceOrigin );
385 voiceOrigin[2] = max[2] + 16;
388 DEntity* targetVoice = m_Container.AddEntity( "target_speaker" );
389 targetVoice->AddEPair( "targetname", buffer );
391 sprintf( buffer, "%f %f %f", voiceOrigin[0], voiceOrigin[1], voiceOrigin[2] );
392 targetVoice->AddEPair( "origin", buffer );
393 targetVoice->AddEPair( "spawnflags", "8" );
394 targetVoice->AddEPair( "noise", "*falling1.wav" );
395 //--------------------
397 // *********** END SPEAKER *************
399 // ********* POWERUP REMOVAL ***********
400 sprintf( buffer, "t%i_2", team );
402 // trigger for powerup removal
403 vec3_t triggerPwrRmvTop, triggerPwrRmvBtm;
404 VectorCopy( min, triggerPwrRmvBtm );
405 VectorCopy( max, triggerPwrRmvTop );
407 triggerPwrRmvTop[2] = triggerVoiceBtm[2] - 64;
408 triggerPwrRmvBtm[2] = triggerPwrRmvTop[2] - 16;
410 DEntity* triggerPwrRmv = m_Container.AddEntity( "trigger_multiple" );
411 GetBoundingCube( triggerPwrRmvBtm, triggerPwrRmvTop, "textures/common/trigger", triggerPwrRmv );
412 triggerPwrRmv->AddEPair( "target", buffer );
413 //--------------------
415 // target for powerup removal
417 VectorCopy( centre, pwrRmvOrigin );
418 pwrRmvOrigin[2] = triggerPwrRmvTop[2] + 16;
420 DEntity* targetPwrRmv = m_Container.AddEntity( "target_remove_powerups" );
421 targetPwrRmv->AddEPair( "targetname", buffer );
423 sprintf( buffer, "%f %f %f", pwrRmvOrigin[0], pwrRmvOrigin[1], pwrRmvOrigin[2] );
424 targetPwrRmv->AddEPair( "origin", buffer );
425 //--------------------
427 // ****** END POWERUP REMOVAL ********
429 // ********* DAMAGE ***********
431 // trigger for damage
432 vec3_t triggerDmgTop, triggerDmgBtm;
433 VectorCopy( min, triggerDmgBtm );
434 VectorCopy( max, triggerDmgTop );
436 triggerDmgBtm[2] = min[2] + 64;
437 triggerDmgTop[2] = triggerDmgBtm[2] + 16;
439 DEntity* triggerDmg = m_Container.AddEntity( "trigger_hurt" );
440 GetBoundingCube( triggerDmgBtm, triggerDmgTop, "textures/common/trigger", triggerDmg );
441 triggerDmg->AddEPair( "dmg", "9999" );
442 triggerDmg->AddEPair( "spawnflags", "12" );
443 //--------------------
445 // ****** END DAMAGE ********
447 // ********* NODROP ***********
450 VectorCopy( max, nodropTop );
452 nodropTop[2] = min[2] + 64;
454 GetBoundingCube( min, nodropTop, "textures/common/nodrop" );
456 // ****** END NODROP ********