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};
48 void DShape::BuildRegularPrism(vec3_t min, vec3_t max, int nSides, bool bAlignTop)
50 vec3_t vc[MAX_POLYGON_FACES+2], vd[MAX_POLYGON_FACES+2];
55 VectorSubtract(max, min, radius);
56 VectorScale(radius, 0.5f, radius);
57 // calc 3d radius and origin
58 VectorAdd(max, min, origin);
59 VectorScale(origin, 0.5f, origin);
65 phase = -(Q_PI/nSides);
66 VectorScale(radius, static_cast< float >( 1/cos(phase) ), radius);
69 //----- Build Polygon Vertices -----
72 for(i = 0; i < nSides; i++)
74 VectorCopy(origin, vc[i]);
75 VectorCopy(origin, vd[i]);
80 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
81 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
87 VectorCopy(vc[0], vc[nSides]);
88 VectorCopy(vd[0], vd[nSides]);
89 VectorCopy(vc[1], vc[nSides+1]);
90 VectorCopy(vd[1], vd[nSides+1]);
92 //----------------------------------
94 DBrush* pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++);
96 for(i = 1; i <= nSides; i++)
97 pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE);
99 pB->AddFace(vc[2], vc[1], vc[0], "textures/common/caulk", FALSE);
100 pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", FALSE);
103 void DShape::Commit()
105 m_Container.GetWorldSpawn()->FixBrushes(FALSE);
106 m_Container.BuildInRadiant(TRUE);
109 void DShape::BuildInversePrism(vec3_t min, vec3_t max, int nSides, bool bAlignTop)
111 vec3_t va[MAX_POLYGON_FACES+1], vb[MAX_POLYGON_FACES+1];
115 VectorSubtract(max, min, radius);
116 VectorScale(radius, 0.5f, radius);
117 // calc 3d radius and origin
118 VectorAdd(max, min, origin);
119 VectorScale(origin, 0.5f, origin);
125 phase = -(Q_PI/nSides);
126 VectorScale(radius, static_cast< float >( 1/cos(phase) ), radius);
129 //----- Build Polygon Vertices -----
132 for(i = 0; i < nSides; i++)
134 VectorCopy(origin, va[i]);
135 VectorCopy(origin, vb[i]);
140 va[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
141 va[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
147 VectorCopy(va[0], va[nSides]);
148 VectorCopy(vb[0], vb[nSides]);
150 //----------------------------------
152 for(i = 1; i <= nSides; i++)
154 DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk");
157 VectorCopy(va[i-1], top);
158 VectorCopy(va[i], bottom);
160 if(va[i-1][1] > va[i][1])
165 else // flip direction of plane on crossover
171 if(top[1] != bottom[1]) // internal line is flat already if true
173 pB->AddFace(va[i-1], top, vb[i-1], "textures/common/caulk", FALSE);
174 pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", FALSE);
175 } // add cut-off planes
177 pB->AddFace(va[i-1], vb[i-1], vb[i], GetCurrentTexture(), FALSE);
178 // add internal polygon plane
182 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]))
198 // DoMessageBox("Border is too large", "Error", MB_OK);
206 phase = -(Q_PI/nSides);
207 VectorScale(radius, static_cast< float >( 1/cos(phase) ), radius);
210 //----- Build Polygon Vertices -----
213 for(i = 0; i < nSides; i++)
215 VectorCopy(origin, va[i]);
216 VectorCopy(origin, vb[i]);
217 VectorCopy(origin, vc[i]);
218 VectorCopy(origin, vd[i]);
223 va[i][0] += (radius[0] - nBorder) * sinf( ( 2 * Q_PI * i / nSides ) + phase );
224 va[i][1] += (radius[1] - nBorder) * cosf( ( 2 * Q_PI * i / nSides ) + phase );
234 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
235 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
241 VectorCopy(va[0], va[nSides]);
242 VectorCopy(vb[0], vb[nSides]);
243 VectorCopy(va[1], va[nSides+1]);
244 VectorCopy(vb[1], vb[nSides+1]);
246 VectorCopy(vc[0], vc[nSides]);
247 VectorCopy(vd[0], vd[nSides]);
248 VectorCopy(vc[1], vc[nSides+1]);
249 VectorCopy(vd[1], vd[nSides+1]);
251 //----------------------------------
253 for(i = 1; i <= nSides; i++)
255 DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk");
257 pB->AddFace(origin, vc[i-1], vd[i-1], "textures/common/caulk", FALSE);
258 pB->AddFace(origin, vd[i], vc[i], "textures/common/caulk", FALSE);
260 pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE);
261 pB->AddFace(vb[i], va[i], va[i-1], GetCurrentTexture(), FALSE);
265 DBrush* DShape::GetBoundingCube_Ext(vec3_t min, vec3_t max, const char *textureName, bool* bUseFaces, bool detail)
267 DBrush* pB = new DBrush;
268 //----- Build Outer Bounds ---------
270 vec3_t v1, v2, v3, v5, v6, v7;
284 //----------------------------------
286 //----- Add Six Cube Faces ---------
289 pB->AddFace(v1, v2, v3, textureName, detail);
291 pB->AddFace(v1, v3, v6, textureName, detail);
293 pB->AddFace(v1, v7, v2, textureName, detail);
296 pB->AddFace(v5, v6, v3, textureName, detail);
298 pB->AddFace(v5, v2, v7, textureName, detail);
300 pB->AddFace(v5, v7, v6, textureName, detail);
302 //----------------------------------
307 DBrush* DShape::GetBoundingCube(vec3_t min, vec3_t max, const char *textureName, DEntity* ent, bool* bUseFaces)
311 pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++);
313 pB = ent->NewBrush(m_nNextBrush++);
315 //----- Build Outer Bounds ---------
317 vec3_t v1, v2, v3, v5, v6, v7;
331 //----------------------------------
333 //----- Add Six Cube Faces ---------
336 pB->AddFace(v1, v2, v3, textureName, FALSE);
338 pB->AddFace(v1, v3, v6, textureName, FALSE);
340 pB->AddFace(v1, v7, v2, textureName, FALSE);
343 pB->AddFace(v5, v6, v3, textureName, FALSE);
345 pB->AddFace(v5, v2, v7, textureName, FALSE);
347 pB->AddFace(v5, v7, v6, textureName, FALSE);
349 //----------------------------------
354 bool DShape::BuildPit(vec3_t min, vec3_t max)
356 if((max[2] - min[2]) < 196)
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 ********