summaryrefslogtreecommitdiff
path: root/hammer/createarch.cpp
blob: 6e4e2c072ebc8250d19bccabdb69c8438f338aa2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//


#include "stdafx.h"
#include "OPTGeneral.h"
#include "Options.h"
#include "hammer_mathlib.h"
#include "MapFace.h"
#include "MapGroup.h"
#include "MapSolid.h"
#include "hammer.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

//-----------------------------------------------------------------------------
// Purpose: Create a segment using two polygons and a start and end position in
//			those polygons.
// Input  : fZMin - 
//			fZMax - 
//			fOuterPoints - 
//			fInnerPoints - 
//			iStart - 
//			iEnd - 
//			bCreateSouthFace - 
// Output : 
//-----------------------------------------------------------------------------
static CMapSolid *CreateSegment(float fZMin, float fZMax, float fOuterPoints[][2], float fInnerPoints[][2], int iStart, int iEnd, BOOL bCreateSouthFace)
{
	CMapFace Face;
	Vector points[4];	// all sides have four vertices

	CMapSolid *pSolid = new CMapSolid;

	int iNorthSouthPoints = 3 + (bCreateSouthFace ? 1 : 0);

	// create top face
	points[0][0] = fOuterPoints[iStart][0];
	points[0][1] = fOuterPoints[iStart][1];
	points[0][2] = fZMin;

	points[1][0] = fOuterPoints[iEnd][0];
	points[1][1] = fOuterPoints[iEnd][1];
	points[1][2] = fZMin;

	points[2][0] = fInnerPoints[iEnd][0];
	points[2][1] = fInnerPoints[iEnd][1];
	points[2][2] = fZMin;

	points[3][0] = fInnerPoints[iStart][0];
	points[3][1] = fInnerPoints[iStart][1];
	points[3][2] = fZMin;

	Face.CreateFace(points, iNorthSouthPoints);
	pSolid->AddFace(&Face);

	// bottom face - set other z value and reverse order
	for (int i = 0; i < 4; i++)
	{
		points[i][2] = fZMax;
	}

	Face.CreateFace(points, -iNorthSouthPoints);
	pSolid->AddFace(&Face);

	// left side
	points[0][0] = fOuterPoints[iStart][0];
	points[0][1] = fOuterPoints[iStart][1];
	points[0][2] = fZMax;

	points[1][0] = fOuterPoints[iStart][0];
	points[1][1] = fOuterPoints[iStart][1];
	points[1][2] = fZMin;

	points[2][0] = fInnerPoints[iStart][0];
	points[2][1] = fInnerPoints[iStart][1];
	points[2][2] = fZMin;

	points[3][0] = fInnerPoints[iStart][0];
	points[3][1] = fInnerPoints[iStart][1];
	points[3][2] = fZMax;

	Face.CreateFace(points, 4);
	pSolid->AddFace(&Face);

	// right side
	points[0][0] = fOuterPoints[iEnd][0];
	points[0][1] = fOuterPoints[iEnd][1];
	points[0][2] = fZMin;

	points[1][0] = fOuterPoints[iEnd][0];
	points[1][1] = fOuterPoints[iEnd][1];
	points[1][2] = fZMax;

	points[2][0] = fInnerPoints[iEnd][0];
	points[2][1] = fInnerPoints[iEnd][1];
	points[2][2] = fZMax;

	points[3][0] = fInnerPoints[iEnd][0];
	points[3][1] = fInnerPoints[iEnd][1];
	points[3][2] = fZMin;

	Face.CreateFace(points, 4);
	pSolid->AddFace(&Face);

	// north face
	points[0][0] = fOuterPoints[iEnd][0];
	points[0][1] = fOuterPoints[iEnd][1];
	points[0][2] = fZMin;

	points[1][0] = fOuterPoints[iStart][0];
	points[1][1] = fOuterPoints[iStart][1];
	points[1][2] = fZMin;

	points[2][0] = fOuterPoints[iStart][0];
	points[2][1] = fOuterPoints[iStart][1];
	points[2][2] = fZMax;

	points[3][0] = fOuterPoints[iEnd][0];
	points[3][1] = fOuterPoints[iEnd][1];
	points[3][2] = fZMax;

	Face.CreateFace(points, 4);
	pSolid->AddFace(&Face);

	// south face
	if (bCreateSouthFace)
	{
		points[0][0] = fInnerPoints[iStart][0];
		points[0][1] = fInnerPoints[iStart][1];
		points[0][2] = fZMin;

		points[1][0] = fInnerPoints[iEnd][0];
		points[1][1] = fInnerPoints[iEnd][1];
		points[1][2] = fZMin;

		points[2][0] = fInnerPoints[iEnd][0];
		points[2][1] = fInnerPoints[iEnd][1];
		points[2][2] = fZMax;

		points[3][0] = fInnerPoints[iStart][0];
		points[3][1] = fInnerPoints[iStart][1];
		points[3][2] = fZMax;

		Face.CreateFace(points, 4);
		pSolid->AddFace(&Face);
	}

	pSolid->InitializeTextureAxes(Options.GetTextureAlignment(), INIT_TEXTURE_ALL | INIT_TEXTURE_FORCE);

	return(pSolid);
}


//-----------------------------------------------------------------------------
// Purpose: Create a segment using two polygons and a start and end position in
//			those polygons.
// Input  : fZMin - 
//			fZMax - 
//			fOuterPoints - 
//			fInnerPoints - 
//			iStart - 
//			iEnd - 
//			bCreateSouthFace - 
// Output : 
//-----------------------------------------------------------------------------
static CMapSolid *CreateSegment(float fStartOuterPoints[][3], float fStartInnerPoints[][3],
								float fEndOuterPoints[][3], float fEndInnerPoints[][3],
								int iStart, int iEnd, BOOL bCreateSouthFace)
{
	CMapFace Face;
	Vector points[4];	// all sides have four vertices

	CMapSolid *pSolid = new CMapSolid;

	// create top face
	points[0][0] = fStartOuterPoints[iStart][0];
	points[0][1] = fStartOuterPoints[iStart][1];
	points[0][2] = fStartOuterPoints[iStart][2];

	points[1][0] = fStartOuterPoints[iEnd][0];
	points[1][1] = fStartOuterPoints[iEnd][1];
	points[1][2] = fStartOuterPoints[iEnd][2];

	points[2][0] = fStartInnerPoints[iEnd][0];
	points[2][1] = fStartInnerPoints[iEnd][1];
	points[2][2] = fStartInnerPoints[iEnd][2];

	points[3][0] = fStartInnerPoints[iStart][0];
	points[3][1] = fStartInnerPoints[iStart][1];
	points[3][2] = fStartInnerPoints[iStart][2];

	Face.CreateFace(points, -4);
	pSolid->AddFace(&Face);

	// bottom face - set other z value and reverse order
	points[0][0] = fEndOuterPoints[iStart][0];
	points[0][1] = fEndOuterPoints[iStart][1];
	points[0][2] = fEndOuterPoints[iStart][2];

	points[1][0] = fEndOuterPoints[iEnd][0];
	points[1][1] = fEndOuterPoints[iEnd][1];
	points[1][2] = fEndOuterPoints[iEnd][2];

	points[2][0] = fEndInnerPoints[iEnd][0];
	points[2][1] = fEndInnerPoints[iEnd][1];
	points[2][2] = fEndInnerPoints[iEnd][2];

	points[3][0] = fEndInnerPoints[iStart][0];
	points[3][1] = fEndInnerPoints[iStart][1];
	points[3][2] = fEndInnerPoints[iStart][2];

	Face.CreateFace(points, 4);
	pSolid->AddFace(&Face);

	// left side
	points[0][0] = fEndOuterPoints[iStart][0];
	points[0][1] = fEndOuterPoints[iStart][1];
	points[0][2] = fEndOuterPoints[iStart][2];

	points[1][0] = fStartOuterPoints[iStart][0];
	points[1][1] = fStartOuterPoints[iStart][1];
	points[1][2] = fStartOuterPoints[iStart][2];

	points[2][0] = fStartInnerPoints[iStart][0];
	points[2][1] = fStartInnerPoints[iStart][1];
	points[2][2] = fStartInnerPoints[iStart][2];

	points[3][0] = fEndInnerPoints[iStart][0];
	points[3][1] = fEndInnerPoints[iStart][1];
	points[3][2] = fEndInnerPoints[iStart][2];

	Face.CreateFace(points, -4);
	pSolid->AddFace(&Face);

	// right side
	points[0][0] = fStartOuterPoints[iEnd][0];
	points[0][1] = fStartOuterPoints[iEnd][1];
	points[0][2] = fStartOuterPoints[iEnd][2];

	points[1][0] = fEndOuterPoints[iEnd][0];
	points[1][1] = fEndOuterPoints[iEnd][1];
	points[1][2] = fEndOuterPoints[iEnd][2];

	points[2][0] = fEndInnerPoints[iEnd][0];
	points[2][1] = fEndInnerPoints[iEnd][1];
	points[2][2] = fEndInnerPoints[iEnd][2];

	points[3][0] = fStartInnerPoints[iEnd][0];
	points[3][1] = fStartInnerPoints[iEnd][1];
	points[3][2] = fStartInnerPoints[iEnd][2];

	Face.CreateFace(points, -4);
	pSolid->AddFace(&Face);

	// north face
	points[0][0] = fStartOuterPoints[iEnd][0];
	points[0][1] = fStartOuterPoints[iEnd][1];
	points[0][2] = fStartOuterPoints[iEnd][2];

	points[1][0] = fStartOuterPoints[iStart][0];
	points[1][1] = fStartOuterPoints[iStart][1];
	points[1][2] = fStartOuterPoints[iStart][2];

	points[2][0] = fEndOuterPoints[iStart][0];
	points[2][1] = fEndOuterPoints[iStart][1];
	points[2][2] = fEndOuterPoints[iStart][2];

	points[3][0] = fEndOuterPoints[iEnd][0];
	points[3][1] = fEndOuterPoints[iEnd][1];
	points[3][2] = fEndOuterPoints[iEnd][2];

	Face.CreateFace(points, -4);
	pSolid->AddFace(&Face);

	// south face
	if (bCreateSouthFace)
	{
		points[0][0] = fStartInnerPoints[iStart][0];
		points[0][1] = fStartInnerPoints[iStart][1];
		points[0][2] = fStartInnerPoints[iStart][2];

		points[1][0] = fStartInnerPoints[iEnd][0];
		points[1][1] = fStartInnerPoints[iEnd][1];
		points[1][2] = fStartInnerPoints[iEnd][2];

		points[2][0] = fEndInnerPoints[iEnd][0];
		points[2][1] = fEndInnerPoints[iEnd][1];
		points[2][2] = fEndInnerPoints[iEnd][2];

		points[3][0] = fEndInnerPoints[iStart][0];
		points[3][1] = fEndInnerPoints[iStart][1];
		points[3][2] = fEndInnerPoints[iStart][2];

		Face.CreateFace(points, -4);
		pSolid->AddFace(&Face);
	}

	pSolid->InitializeTextureAxes(Options.GetTextureAlignment(), INIT_TEXTURE_ALL | INIT_TEXTURE_FORCE);

	return(pSolid);
}


//-----------------------------------------------------------------------------
// Make a 2d arc
//-----------------------------------------------------------------------------
void MakeArcCenterRadius(float xCenter, float yCenter, float xrad, float yrad, int npoints, float start_ang, float fArc, float points[][2])
{
    int point;
    float angle = start_ang;
	float angle_delta;

	angle_delta = fArc / (float)npoints;

	// Add an additional points if we are not doing a full circle
	if (fArc != 360.0)
	{
		++npoints;
	}
	
    for( point = 0; point < npoints; point++ )
    {
        if ( angle > 360 )
		{
           angle -= 360;
		}

        points[point][0] = V_rint(xCenter + (float)cos(DEG2RAD(angle)) * xrad);
        points[point][1] = V_rint(yCenter + (float)sin(DEG2RAD(angle)) * yrad);

		angle += angle_delta;
    }

	// Full circle, recopy the first point as the closing point.
	if (fArc == 360.0)
	{
	    points[point][0] = points[0][0];
		points[point][1] = points[0][1];
	}
}

void MakeArc(float x1, float y1, float x2, float y2, int npoints, float start_ang, float fArc, float points[][2])
{
    float xrad = (x2 - x1) / 2.0f;
	float yrad = (y2 - y1) / 2.0f;

	// make centerpoint for polygon:
    float xCenter = x1 + xrad;
    float yCenter = y1 + yrad;

	MakeArcCenterRadius( xCenter, yCenter, xrad, yrad, npoints, start_ang, fArc, points );
}

#define ARC_MAX_POINTS 4096


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pBox - 
//			fStartAngle - 
//			iSides - 
//			fArc - 
//			iWallWidth - 
//			iAddHeight - 
//			bPreview - 
// Output : Returns a group containing the arch solids.
//-----------------------------------------------------------------------------
CMapClass *CreateArch(BoundBox *pBox, float fStartAngle, int iSides, float fArc, int iWallWidth, int iAddHeight, BOOL bPreview)
{
	float fOuterPoints[ARC_MAX_POINTS][2];
	float fInnerPoints[ARC_MAX_POINTS][2];

	//
	// create outer points
	//
	MakeArc(pBox->bmins[AXIS_X], pBox->bmins[AXIS_Y],
		pBox->bmaxs[AXIS_X], pBox->bmaxs[AXIS_Y], iSides,
		fStartAngle, fArc, fOuterPoints);

	//
	// create inner points
	//
	MakeArc(pBox->bmins[AXIS_X] + iWallWidth, 
		pBox->bmins[AXIS_Y] + iWallWidth, 
		pBox->bmaxs[AXIS_X] - iWallWidth, 
		pBox->bmaxs[AXIS_Y] - iWallWidth, iSides, 
		fStartAngle, fArc, fInnerPoints);


	//
	// check wall width - if it's half or more of the total,
	//  set the inner poinst to the center point of the box
	//  and turn off the CreateSouthFace flag
	//	
	BOOL bCreateSouthFace = TRUE;
	Vector Center;
	pBox->GetBoundsCenter(Center);
	if((iWallWidth*2+8) >= (pBox->bmaxs[AXIS_X] - pBox->bmins[AXIS_X]) ||
		(iWallWidth*2+8) >= (pBox->bmaxs[AXIS_Y] - pBox->bmins[AXIS_Y]))
	{
		for(int i = 0; i < ARC_MAX_POINTS; i++)
		{
			fInnerPoints[i][AXIS_X] = Center[AXIS_X];
			fInnerPoints[i][AXIS_Y] = Center[AXIS_Y];
		}
		bCreateSouthFace = FALSE;
	}

	// create group for segments
	CMapGroup *pGroup = new CMapGroup;

	Vector MoveAccum( 0.f, 0.f, 0.f );

	float fMinZ, fMaxZ;

	fMinZ = pBox->bmins[2];
	fMaxZ = pBox->bmaxs[2];

	if ((fMaxZ - fMinZ) < 1.0f)
		fMaxZ = fMinZ + 1.0f;

	for (int i = 0; i < iSides; i++)
	{
		int iNextPoint = i+1;
		if (iNextPoint >= iSides + 1)
			iNextPoint = 0;

		CMapSolid *pSolid = CreateSegment(
			fMinZ, fMaxZ,
			fOuterPoints, fInnerPoints,
			i, iNextPoint, bCreateSouthFace);

		pGroup->AddChild(pSolid);

		if (iAddHeight && i)	// don't move first segment
		{
			MoveAccum[2] += iAddHeight;
			pSolid->TransMove(MoveAccum);
		}
	}

	pGroup->CalcBounds(TRUE);
	if (Options.general.bStretchArches)
	{
		// make sure size of group's bounds are size of original bounds -
		//  if not, scale up. this can happen when we use rotation.
		Vector objsize, boundsize;
		pBox->GetBoundsSize(boundsize);
		pGroup->GetBoundsSize(objsize);

		if (boundsize[AXIS_X] > objsize[AXIS_X] || 
			boundsize[AXIS_Y] > objsize[AXIS_Y])
		{
			Vector scale;
			scale[AXIS_X] = boundsize[AXIS_X] / objsize[AXIS_X];
			scale[AXIS_Y] = boundsize[AXIS_Y] / objsize[AXIS_Y];
			scale[AXIS_Z] = 1.0f;  // xxxYWB scaling by 0 causes veneers, so I changed to 1.0
			Vector center;
			pBox->GetBoundsCenter(center);
			pGroup->TransScale(center, scale);
		}
	}

	return pGroup;
}


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pBox - 
//			fStartAngle - 
//			iSides - 
//			fArc - 
//			iWallWidth - 
//			iAddHeight - 
//			bPreview - 
// Output : Returns a group containing the arch solids.
//-----------------------------------------------------------------------------
typedef float TorusPointList_t[ARC_MAX_POINTS][3];

CMapClass *CreateTorus(BoundBox *pBox, float fStartAngle, int iSides, float fArc, int iWallWidth, float flCrossSectionalRadius,
	float fRotationStartAngle, int iRotationSides, float fRotationArc, int iAddHeight, BOOL bPreview)
{
	float xCenter = (pBox->bmaxs[AXIS_X] + pBox->bmins[AXIS_X]) * 0.5f;
	float yCenter = (pBox->bmaxs[AXIS_Y] + pBox->bmins[AXIS_Y]) * 0.5f;
	float xRad = (pBox->bmaxs[AXIS_X] - xCenter);
	float yRad = (pBox->bmaxs[AXIS_Y] - yCenter);
	if (xRad < 0.0f )
	{
		xRad = 0.0f;
	}

	if (yRad < 0.0f )
	{
		yRad = 0.0f;
	}

	if ( flCrossSectionalRadius > (xRad * 0.5f) )
	{
		flCrossSectionalRadius = (xRad * 0.5f);
	}
	if ( flCrossSectionalRadius > (yRad * 0.5f) )
	{
		flCrossSectionalRadius = (yRad * 0.5f);
	}

	if ( iWallWidth < flCrossSectionalRadius )
	{
		flCrossSectionalRadius -= iWallWidth;
	}
	else
	{
		iWallWidth = flCrossSectionalRadius;
		flCrossSectionalRadius = 0.0f;
	}

	float flCrossSectionHalfWidth = flCrossSectionalRadius + iWallWidth;
	xRad -= flCrossSectionHalfWidth;
	yRad -= flCrossSectionHalfWidth;

	float fOuterPoints[ARC_MAX_POINTS][2];
	float fInnerPoints[ARC_MAX_POINTS][2];

	// create outer points (unrotated)
	MakeArcCenterRadius(0.0f, 0.0f,
		flCrossSectionalRadius + iWallWidth, flCrossSectionalRadius + iWallWidth, 
		iSides, fStartAngle, fArc, fOuterPoints);

	BOOL bCreateSouthFace = TRUE;
	if ( flCrossSectionalRadius != 0.0f )
	{
		// create inner points (unrotated)
		MakeArcCenterRadius(0.0f, 0.0f, flCrossSectionalRadius, flCrossSectionalRadius, 
			iSides, fStartAngle, fArc, fInnerPoints);
	}
	else
	{
		for( int i = 0; i < iSides; i++)
		{
			fInnerPoints[i][0] = fInnerPoints[i][1] = 0.0f;
		}
		bCreateSouthFace = FALSE;
	}

	// create group for segments
	CMapGroup *pGroup = new CMapGroup;

	TorusPointList_t innerPoints[2];
	TorusPointList_t outerPoints[2];
	TorusPointList_t *pStartInnerPoints;
	TorusPointList_t *pStartOuterPoints;
	TorusPointList_t *pEndInnerPoints = &innerPoints[1];
	TorusPointList_t *pEndOuterPoints = &outerPoints[1];
	int nCurrIndex = 0;

	float flCurrentZ = pBox->bmins[AXIS_Z] + iWallWidth + flCrossSectionalRadius;
	float flDeltaZ = (float)iAddHeight / (float)(iRotationSides);

	float flRotationAngle = fRotationStartAngle;
	float flRotationDeltaAngle = fRotationArc / iRotationSides;

	bool bIsCircle = ( iAddHeight == 0.0f ) && ( fRotationArc == 360.0f );
	++iRotationSides;
	for ( int i = 0; i != iRotationSides; ++i )
	{
		// This eliminates a seam in circular toruses
		if ( bIsCircle && (i == iRotationSides - 1) )
		{
			flRotationAngle = fRotationStartAngle;
		}

		float xCurrCenter, yCurrCenter;

		float flCosAngle = cos( DEG2RAD(flRotationAngle) );
		float flSinAngle = sin( DEG2RAD(flRotationAngle) );
		xCurrCenter = xCenter + xRad * flCosAngle;
		yCurrCenter = yCenter + yRad * flSinAngle;

		// Update buffers
		pStartInnerPoints = pEndInnerPoints;
		pStartOuterPoints = pEndOuterPoints;
		pEndInnerPoints = &innerPoints[nCurrIndex];
		pEndOuterPoints = &outerPoints[nCurrIndex];
		nCurrIndex = 1 - nCurrIndex;

		// Transform points into actual space.
		int jPrevPoint = -1;
		int j = 0;
		do
		{
			// x original is transformed into x/y based on rotation
			// y original is transformed into z
			(*pEndInnerPoints)[j][0] = xCurrCenter + fInnerPoints[j][0] * flCosAngle;
			(*pEndInnerPoints)[j][1] = yCurrCenter + fInnerPoints[j][0] * flSinAngle;
			(*pEndInnerPoints)[j][2] = flCurrentZ + fInnerPoints[j][1];

			(*pEndOuterPoints)[j][0] = xCurrCenter + fOuterPoints[j][0] * flCosAngle;
			(*pEndOuterPoints)[j][1] = yCurrCenter + fOuterPoints[j][0] * flSinAngle;
			(*pEndOuterPoints)[j][2] = flCurrentZ + fOuterPoints[j][1];

			// We'll use the j == 0 data when iNextPoint = iSides - 1
			if (( i != 0 ) && ( jPrevPoint != -1 ))
			{
				CMapSolid *pSolid = CreateSegment(
					*pStartOuterPoints, *pStartInnerPoints,
					*pEndOuterPoints, *pEndInnerPoints,
					jPrevPoint, j, bCreateSouthFace);

				pGroup->AddChild(pSolid);
			}

			jPrevPoint = j;
			++j;
		} while( jPrevPoint != iSides );

		flRotationAngle += flRotationDeltaAngle;
		flCurrentZ += flDeltaZ;

		if ( flRotationAngle >= 360.0f )
		{
			flRotationAngle -= 360.0f;
		}
	}

	pGroup->CalcBounds(TRUE);

	if (Options.general.bStretchArches)
	{
		// make sure size of group's bounds are size of original bounds -
		//  if not, scale up. this can happen when we use rotation.
		Vector objsize, boundsize;
		pBox->GetBoundsSize(boundsize);
		pGroup->GetBoundsSize(objsize);

		if (boundsize[AXIS_X] > objsize[AXIS_X] || 
			boundsize[AXIS_Y] > objsize[AXIS_Y])
		{
			Vector scale;
			scale[AXIS_X] = boundsize[AXIS_X] / objsize[AXIS_X];
			scale[AXIS_Y] = boundsize[AXIS_Y] / objsize[AXIS_Y];
			scale[AXIS_Z] = 1.0f;  // xxxYWB scaling by 0 causes veneers, so I changed to 1.0
			Vector center;
			pBox->GetBoundsCenter(center);
			pGroup->TransScale(center, scale);
		}
	}

	return pGroup;
}