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 //////////////////////////////////////////////////////////////////////
26 #include "gtkr_list.h"
37 //#include "dialogs-gtk.h"
42 //////////////////////////////////////////////////////////////////////
43 // Construction/Destruction
44 //////////////////////////////////////////////////////////////////////
46 bool bFacesAll[6] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};
58 void DShape::BuildRegularPrism(vec3_t min, vec3_t max, int nSides, bool bAlignTop)
60 vec3_t vc[MAX_POLYGON_FACES+2], vd[MAX_POLYGON_FACES+2];
65 VectorSubtract(max, min, radius);
66 VectorScale(radius, 0.5f, radius);
67 // calc 3d radius and origin
68 VectorAdd(max, min, origin);
69 VectorScale(origin, 0.5f, origin);
75 phase = -(Q_PI/nSides);
76 VectorScale(radius, static_cast<float>(1.0 / cos(phase)), radius);
79 //----- Build Polygon Vertices -----
82 for(i = 0; i < nSides; i++)
84 VectorCopy(origin, vc[i]);
85 VectorCopy(origin, vd[i]);
90 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
91 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
97 VectorCopy(vc[0], vc[nSides]);
98 VectorCopy(vd[0], vd[nSides]);
99 VectorCopy(vc[1], vc[nSides+1]);
100 VectorCopy(vd[1], vd[nSides+1]);
102 //----------------------------------
104 DBrush* pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++);
106 for(i = 1; i <= nSides; i++)
107 pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE);
109 pB->AddFace(vc[2], vc[1], vc[0], "textures/common/caulk", FALSE);
110 pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", FALSE);
113 void DShape::Commit()
115 m_Container.GetWorldSpawn()->FixBrushes();
116 m_Container.BuildInRadiant(TRUE);
119 void DShape::BuildInversePrism(vec3_t min, vec3_t max, int nSides, bool bAlignTop)
121 vec3_t va[MAX_POLYGON_FACES+1], vb[MAX_POLYGON_FACES+1];
125 VectorSubtract(max, min, radius);
126 VectorScale(radius, 0.5f, radius);
127 // calc 3d radius and origin
128 VectorAdd(max, min, origin);
129 VectorScale(origin, 0.5f, origin);
135 phase = -(Q_PI/nSides);
136 VectorScale(radius, static_cast<float>(1.0 / cos(phase)), radius);
139 //----- Build Polygon Vertices -----
142 for(i = 0; i < nSides; i++)
144 VectorCopy(origin, va[i]);
145 VectorCopy(origin, vb[i]);
150 va[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
151 va[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
157 VectorCopy(va[0], va[nSides]);
158 VectorCopy(vb[0], vb[nSides]);
160 //----------------------------------
162 for(i = 1; i <= nSides; i++)
164 DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk");
167 VectorCopy(va[i-1], top);
168 VectorCopy(va[i], bottom);
170 if(va[i-1][1] > va[i][1])
175 else // flip direction of plane on crossover
181 if(top[1] != bottom[1]) // internal line is flat already if true
183 pB->AddFace(va[i-1], top, vb[i-1], "textures/common/caulk", FALSE);
184 pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", FALSE);
185 } // add cut-off planes
187 pB->AddFace(va[i-1], vb[i-1], vb[i], GetCurrentTexture(), FALSE);
188 // add internal polygon plane
192 void DShape::BuildBorderedPrism(vec3_t min, vec3_t max, int nSides, int nBorder, bool bAlignTop)
194 vec3_t va[MAX_POLYGON_FACES+2], vb[MAX_POLYGON_FACES+2];
195 vec3_t vc[MAX_POLYGON_FACES+2], vd[MAX_POLYGON_FACES+2];
200 VectorSubtract(max, min, radius);
201 VectorScale(radius, 0.5f, radius);
202 // calc 3d radius and origin
203 VectorAdd(max, min, origin);
204 VectorScale(origin, 0.5f, origin);
206 if(nBorder >= Min(radius[0], radius[1]))
208 // DoMessageBox("Border is too large", "Error", MB_OK);
216 phase = -(Q_PI/nSides);
217 VectorScale(radius, static_cast<float>(1.0 / cos(phase)), radius);
220 //----- Build Polygon Vertices -----
223 for(i = 0; i < nSides; i++)
225 VectorCopy(origin, va[i]);
226 VectorCopy(origin, vb[i]);
227 VectorCopy(origin, vc[i]);
228 VectorCopy(origin, vd[i]);
233 va[i][0] += (radius[0] - nBorder) * sinf( ( 2 * Q_PI * i / nSides ) + phase );
234 va[i][1] += (radius[1] - nBorder) * cosf( ( 2 * Q_PI * i / nSides ) + phase );
244 vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
245 vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );
251 VectorCopy(va[0], va[nSides]);
252 VectorCopy(vb[0], vb[nSides]);
253 VectorCopy(va[1], va[nSides+1]);
254 VectorCopy(vb[1], vb[nSides+1]);
256 VectorCopy(vc[0], vc[nSides]);
257 VectorCopy(vd[0], vd[nSides]);
258 VectorCopy(vc[1], vc[nSides+1]);
259 VectorCopy(vd[1], vd[nSides+1]);
261 //----------------------------------
263 for(i = 1; i <= nSides; i++)
265 DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk");
267 pB->AddFace(origin, vc[i-1], vd[i-1], "textures/common/caulk", FALSE);
268 pB->AddFace(origin, vd[i], vc[i], "textures/common/caulk", FALSE);
270 pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE);
271 pB->AddFace(vb[i], va[i], va[i-1], GetCurrentTexture(), FALSE);
275 DBrush* DShape::GetBoundingCube_Ext(vec3_t min, vec3_t max, const char *textureName, bool* bUseFaces, bool detail)
277 DBrush* pB = new DBrush;
278 //----- Build Outer Bounds ---------
280 vec3_t v1, v2, v3, v5, v6, v7;
294 //----------------------------------
296 //----- Add Six Cube Faces ---------
299 pB->AddFace(v1, v2, v3, textureName, detail);
301 pB->AddFace(v1, v3, v6, textureName, detail);
303 pB->AddFace(v1, v7, v2, textureName, detail);
306 pB->AddFace(v5, v6, v3, textureName, detail);
308 pB->AddFace(v5, v2, v7, textureName, detail);
310 pB->AddFace(v5, v7, v6, textureName, detail);
312 //----------------------------------
317 DBrush* DShape::GetBoundingCube(vec3_t min, vec3_t max, const char *textureName, DEntity* ent, bool* bUseFaces)
321 pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++);
323 pB = ent->NewBrush(m_nNextBrush++);
325 //----- Build Outer Bounds ---------
327 vec3_t v1, v2, v3, v5, v6, v7;
341 //----------------------------------
343 //----- Add Six Cube Faces ---------
346 pB->AddFace(v1, v2, v3, textureName, FALSE);
348 pB->AddFace(v1, v3, v6, textureName, FALSE);
350 pB->AddFace(v1, v7, v2, textureName, FALSE);
353 pB->AddFace(v5, v6, v3, textureName, FALSE);
355 pB->AddFace(v5, v2, v7, textureName, FALSE);
357 pB->AddFace(v5, v7, v6, textureName, FALSE);
359 //----------------------------------
364 bool DShape::BuildPit(vec3_t min, vec3_t max)
366 if((max[2] - min[2]) < 196)
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 ********