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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
|
/*===========================================================================
Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved.
Component: RoadSegment
Description:
Authors: Travis Brown-John
Revisions Date Author Revision
2002/02/25 Tbrown-John Created
===========================================================================*/
#include <roads/road.h>
#include <roads/roadsegment.h>
#include <roads/roadsegmentdata.h>
RoadSegment::RoadSegment()
:
mRoad( NULL ),
mSegmentIndex( 0 )
{
}
RoadSegment::~RoadSegment( void )
{
}
/*
void RoadSegment::Init( RoadSegmentData* rsd, rmt::Matrix& hierarchy, float scaleAlongFacing )
{
////////////////////////////////////////////////////////////////
// Transform segment data based on given matrix & scale-along-facing
//
rmt::Vector vector;
// First, do the corners and the edgenormals
for( int i=0; i<4; i++ )
{
// transform the corner
vector = rsd->GetCorner( i );
vector.z *= scaleAlongFacing;
vector.Transform( hierarchy );
mCorners[ i ] = vector;
// transform the edge normals
vector = rsd->GetEdgeNormal( i );
vector.Rotate( hierarchy );
mEdgeNormals[ i ] = vector;
}
// Now, transform the segment normal
vector = rsd->GetSegmentNormal();
vector.Rotate( hierarchy );
mNormal = vector;
// Now, calculate and store segment length
rmt::Vector segStart = (mCorners[0] + mCorners[3]) * 0.5f;
rmt::Vector segEnd = (mCorners[1] + mCorners[2]) * 0.5f;
mfSegmentLength = (segEnd - segStart).Length(); // *** SQUARE ROOT! ***
// Now, calculate and store the bounding sphere
rmt::Box3D box;
GetBoundingBox( &box ); // find the box on the fly (based on extents of corners)
// compute & store the bounding sphere based on bbox
rmt::Vector vectorBetween;
vectorBetween = ( box.high - box.low ) * 0.5f;
mSphere.centre = box.low + vectorBetween;
mSphere.radius = vectorBetween.Magnitude(); // *** SQUARE ROOT! ***
//////////////////////////////
// TODO:
// This stuff is dubious. It won't be accurate given that we can no
// longer assume interior and exterior edges are parallel.
//
// Now, Calculate the width of the leading edge of the segment.
float fWidth = segStart.Magnitude();
mfLaneWidth = fWidth / (float)rsd->GetNumLanes();
// Calculate a turn radius.
//
float fCosTheta = mEdgeNormals[0].DotProduct( mEdgeNormals[1] );
if ( fCosTheta < 0.0f )
{
fCosTheta = 0.0f - fCosTheta;
}
if ( fCosTheta < 0.001f ) //Clamp me.
{
fCosTheta = 0.0f;
}
rmt::Vector temp;
temp.Sub( mCorners[0], mCorners[1] );
float fInteriorEdgeLength = temp.Magnitude( );
temp.Sub( mCorners[2], mCorners[3] );
float fExteriorEdgeLength = temp.Magnitude( );
if ( fCosTheta != 0.0f )
{
// take the shortest length.
float length = ( fInteriorEdgeLength < fExteriorEdgeLength )? fInteriorEdgeLength : fExteriorEdgeLength;
length = length / 2.0f;
mfRadius = length / fCosTheta;
mfAngle = rmt::PI_BY2 - rmt::ACos( fCosTheta );
//rmt::RadianToDeg( mfAngle );
}
else
{
// Not a curved segment.
//
mfRadius = 0.0f;
mfAngle = 0.0f;
}
}
*/
void RoadSegment::Init( RoadSegmentData* rsd, rmt::Matrix& hierarchy, float scaleAlongFacing )
{
////////////////////////////////////////////////////////////////
// Transform segment data based on given matrix & scale-along-facing
//
rmt::Vector vector;
// store the unmodified values
for( int i=0; i<4; i++ )
{
vector = rsd->GetCorner( i );
mCorners[ i ] = vector;
vector = rsd->GetEdgeNormal( i );
mEdgeNormals[ i ] = vector;
}
//////////////////////////////
// TODO:
// This stuff is dubious. It won't be accurate given that we can no
// longer assume interior and exterior edges are parallel. AND
// somehow it's able to work quite accurately from the corner
// and edgenormal values that have not yet been transformed. *shudder*
//
// Now, Calculate the width of the leading edge of the segment.
float fWidth = ((mCorners[0] + mCorners[3]) * 0.5f).Magnitude();
mfLaneWidth = fWidth / (float)rsd->GetNumLanes();
// Calculate a turn radius.
//
float fCosTheta = mEdgeNormals[0].DotProduct( mEdgeNormals[1] );
if ( fCosTheta < 0.0f )
{
fCosTheta = 0.0f - fCosTheta;
}
if ( fCosTheta < 0.001f ) //Clamp me.
{
fCosTheta = 0.0f;
}
rmt::Vector temp;
temp.Sub( mCorners[0], mCorners[1] );
float fInteriorEdgeLength = temp.Magnitude( );
temp.Sub( mCorners[2], mCorners[3] );
float fExteriorEdgeLength = temp.Magnitude( );
if ( fCosTheta != 0.0f )
{
// take the shortest length.
float length = ( fInteriorEdgeLength < fExteriorEdgeLength )? fInteriorEdgeLength : fExteriorEdgeLength;
length = length / 2.0f;
mfRadius = length / fCosTheta;
mfAngle = rmt::PI_BY2 - rmt::ACos( fCosTheta );
//rmt::RadianToDeg( mfAngle );
}
else
{
// Not a curved segment.
//
mfRadius = 0.0f;
mfAngle = 0.0f;
}
///////////////////////////////////////////
// Ok, so first, transform the corners and the edgenormals
for( int i=0; i<4; i++ )
{
// transform the corner
vector = rsd->GetCorner( i );
vector.z *= scaleAlongFacing;
vector.Transform( hierarchy );
mCorners[ i ] = vector;
// transform the edge normals
vector = rsd->GetEdgeNormal( i );
vector.Rotate( hierarchy );
mEdgeNormals[ i ] = vector;
}
// Now, transform the segment normal
vector = rsd->GetSegmentNormal();
vector.Rotate( hierarchy );
mNormal = vector;
// Now, calculate and store segment length
rmt::Vector segStart = (mCorners[0] + mCorners[3]) * 0.5f;
rmt::Vector segEnd = (mCorners[1] + mCorners[2]) * 0.5f;
mfSegmentLength = (segEnd - segStart).Length(); // *** SQUARE ROOT! ***
// Now, calculate and store the bounding sphere
rmt::Box3D box;
GetBoundingBox( &box ); // find the box on the fly (based on extents of corners)
// compute & store the bounding sphere based on bbox
rmt::Vector vectorBetween;
vectorBetween = ( box.high - box.low ) * 0.5f;
mSphere.centre = box.low + vectorBetween;
mSphere.radius = vectorBetween.Magnitude(); // *** SQUARE ROOT! ***
}
void RoadSegment::GetBoundingBox(rmt::Box3D* box)
{
// get axis-aligned bounding box from vertices...
unsigned int numVertices = 4;
rmt::Vector vertex;
unsigned int i = 0;
for ( i = 0; i < numVertices; i++ )
{
vertex = mCorners[i];
if ( 0 == i )
{
// This is the first time.
// Initialize to some value.
//
box->low = box->high = vertex;
}
else
{
if ( box->low.x > vertex.x )
{
box->low.x = vertex.x;
}
if ( box->low.y > vertex.y )
{
box->low.y = vertex.y;
}
if ( box->low.z > vertex.z )
{
box->low.z = vertex.z;
}
if ( box->high.x < vertex.x )
{
box->high.x = vertex.x;
}
if ( box->high.y < vertex.y )
{
box->high.y = vertex.y;
}
if ( box->high.z < vertex.z )
{
box->high.z = vertex.z;
}
}
}
}
void RoadSegment::GetBoundingSphere(rmt::Sphere* sphere)
{
*sphere = mSphere;
}
/*
==============================================================================
RoadSegment::CalculateUnitDistIntoRoadSegment
==============================================================================
Description: Adapted from GameGems Article by Steven Ranck. pp412-pp420.
Implements a fast and simple algm for determing where a point
in between the edges of a 2D quad (RoadSegment). The result
is a unit floting point number, where 0 indicates that the point
lies on the leading edge, and where 1 indicates that the point
lies on the opposite edge. The RoadSegment may be any 4 sided
2D convex shape.
Constraints: The RoadSegment must be convex and have 4 sides.
The RoadSegment must have a non zero area.
The point must lie within the sector. ***** What if it doesn't?
Parameters: ( float fPointX, float fPointZ )
Return: A scalar from 0 to 1.
0 if point lies on the leading edge.
1 if point lies on the trailing edge.
Smoothly interpolated value for all points in between.
=============================================================================
*/
float RoadSegment::CalculateUnitDistIntoRoadSegment( float fPointX, float fPointZ )
{
rmt::Vector VLP, VTP;
float fDotL, fDotT;
// Get and cache the leading edge top corner
// and the trailing edge bottom corner.
//
rmt::Vector vertices[ 2 ];
GetCorner( 0, vertices[ 0 ] );
GetCorner( 2, vertices[ 1 ] );
// Get and cache the leading edge normal
// and the trailing edge normal.
//
rmt::Vector unitNormals[ 2 ];
GetEdgeNormal( 0, unitNormals[ 0 ] );
GetEdgeNormal( 2, unitNormals[ 1 ] );
//for this to work, the normals must both point into
//the volume...
//so, I need to reverse the second edge normal
unitNormals[1] *= -1;
// Compute vector from point on Leading Edge to P:
//
VLP.x = fPointX - vertices[0].x;
VLP.y = 0.0f;
VLP.z = fPointZ - vertices[0].z;
// Compute vector from point on Trailing Edge to P:
//
VTP.x = fPointX - vertices[1].x;
VTP.y = 0.0f;
VTP.z = fPointZ - vertices[1].z;
// Compute (VLP dot Leading Edge Normal):
//
fDotL = VLP.x*unitNormals[0].x + VLP.z*unitNormals[0].z;
// Compute (VTP dot Trailing Edge Normal):
//
fDotT = VTP.x*unitNormals[1].x + VTP.z*unitNormals[1].z;
// Compute unit distance into sector and return it:
//
return ( fDotL / (fDotL + fDotT) );
}
float RoadSegment::CalculateUnitHeightInRoadSegment( float fPointX, float fPointZ )
{
rmt::Vector VLP, VTP;
float fDotL, fDotT;
// Get and cache the leading edge top corner
// and the trailing edge bottom corner.
//
rmt::Vector vertices[ 2 ];
GetCorner( 0, vertices[ 0 ] );
GetCorner( 2, vertices[ 1 ] );
// Get and cache the leading edge normal
// and the trailing edge normal.
//
rmt::Vector unitNormals[ 2 ];
GetEdgeNormal( 1, unitNormals[ 0 ] );
GetEdgeNormal( 3, unitNormals[ 1 ] );
// Compute vector from point on Leading Edge to P:
//
VLP.x = fPointX - vertices[0].x;
VLP.y = 0.0f;
VLP.z = fPointZ - vertices[0].z;
// Compute vector from point on Trailing Edge to P:
//
VTP.x = fPointX - vertices[1].x;
VTP.y = 0.0f;
VTP.z = fPointZ - vertices[1].z;
// Compute (VLP dot Leading Edge Normal):
//
fDotL = VLP.x*unitNormals[0].x + VLP.z*unitNormals[0].z;
// Compute (VTP dot Trailing Edge Normal):
//
fDotT = VTP.x*unitNormals[1].x + VTP.z*unitNormals[1].z;
// Compute unit distance into sector and return it:
//
return ( fDotL / (fDotL + fDotT) );
}
/*
float RoadSegment::CalculateYHeight( float fPointX, float fPointZ )
{
// Get and cache the leading edge top corner
// and the trailing edge bottom corner.
//
rmt::Vector vertices[ 2 ];
GetCorner( 0, vertices[ 0 ] );
GetCorner( 2, vertices[ 1 ] );
float fDistance = CalculateUnitDistIntoRoadSegment( fPointX, fPointZ );
float y = LERP( fDistance, vertices[ 0 ].y, vertices[ 1 ].y );
return y;
}
*/
void RoadSegment::GetPosition( float t, float w, rmt::Vector* pos )
{
// Get and cache the corners.
//
rmt::Vector vertices[ 4 ];
GetCorner( 0, vertices[ 0 ] );
GetCorner( 1, vertices[ 1 ] );
GetCorner( 2, vertices[ 2 ] );
GetCorner( 3, vertices[ 3 ] );
rmt::Vector position;
// Interpolate the Normal vector across the Segment.
//
rmt::Vector leadingEdge;
leadingEdge.Sub( vertices[ 3 ], vertices[ 0 ] );
rmt::Vector leadingPoint = leadingEdge;
leadingPoint.Scale( w );
leadingPoint.Add( vertices[ 0 ] );
rmt::Vector trailingEdge;
trailingEdge.Sub( vertices[ 2 ], vertices[ 1 ] );
rmt::Vector trailingPoint = trailingEdge;
trailingPoint.Scale( w );
trailingPoint.Add( vertices[ 1 ] );
position.Sub( trailingPoint, leadingPoint );
position.Scale( t );
position.Add( leadingPoint );
*pos = position;
}
void RoadSegment::GetLaneLocation( float t, int index, rmt::Vector& position, rmt::Vector& facing )
{
//
// Get the world space point and facing at time 't'.
//
// Interpolate the facing.
//
rmt::Vector facingNormals[ 2 ];
GetEdgeNormal( 0, facingNormals[ 0 ] );
GetEdgeNormal( 2, facingNormals[ 1 ] );
facing.x = LERP( t, facingNormals[ 0 ].x, facingNormals[ 1 ].x );
facing.y = LERP( t, facingNormals[ 0 ].y, facingNormals[ 1 ].y );
facing.z = LERP( t, facingNormals[ 0 ].z, facingNormals[ 1 ].z );
// [Dusit: July 6th, 2003]
// NOTE:
// This is the CORRECT way to produce the lane length value when
// the width of the roadsegment isn't guaranteed across its length.
// The only thing that it assumes (and is always correct) is that
// each lane is as wide as the other lanes at any given point along
// the length of the segment
//
float edgeT = ((float)(index<<1) + 1.0f) / ((float)(GetNumLanes()<<1));
// find start & end points of the lane
rmt::Vector vec0, vec1, vec2, vec3;
GetCorner( 0, vec0 );
GetCorner( 1, vec1 );
GetCorner( 2, vec2 );
GetCorner( 3, vec3 );
// lane indices go from 0 to n, right to left ( n <=== 0 )
rmt::Vector bottomEdgeDir = vec0 - vec3; // points frm 3 to 0
rmt::Vector topEdgeDir = vec1 - vec2; // points frm 2 to 1
// now we figure out the starting point and ending point of the
// lane segment
rmt::Vector start = vec3 + bottomEdgeDir * edgeT;
rmt::Vector end = vec2 + topEdgeDir * edgeT;
// now find the t position along the lane
rmt::Vector laneDir = end - start;
position = start + laneDir * t;
/*
// Get and cache the corners.
//
rmt::Vector vertices[ 4 ];
GetCorner( 0, vertices[ 0 ] );
GetCorner( 1, vertices[ 1 ] );
GetCorner( 2, vertices[ 2 ] );
GetCorner( 3, vertices[ 3 ] );
//There is an assumption here that the road does not get wider or thinner
//across its length...
// Scale unnormalized vector by normalized center of desired lane.
// ( ( index * fLaneWidth ) + ( fLaneWidth / 2.0f ) ) / roadWidth;
//
float fCentreOfLane = ( index * mfLaneWidth ) + ( mfLaneWidth / 2.0f );
//I call this parametric variable w;
float w = fCentreOfLane / GetRoadWidth();
// Interpolate the Normal vector across the Segment.
//
rmt::Vector leadingEdge;
leadingEdge.Sub( vertices[ 0 ], vertices[ 3 ] );
rmt::Vector leadingPoint = leadingEdge;
leadingPoint.Scale( w );
leadingPoint.Add( vertices[ 3 ] );
rmt::Vector trailingEdge;
trailingEdge.Sub( vertices[ 1 ], vertices[ 2 ] );
rmt::Vector trailingPoint = trailingEdge;
trailingPoint.Scale( w );
trailingPoint.Add( vertices[ 2 ] );
//This gives the point between the leading and trailing point by parameter t.
position.x = LERP( t, leadingPoint.x, trailingPoint.x );
position.y = LERP( t, leadingPoint.y, trailingPoint.y );
position.z = LERP( t, leadingPoint.z, trailingPoint.z );
*/
}
/*
//==============================================================================
//RoadSegment::GetJoinPoint
//==============================================================================
//Description: RoadSegmentData pieces are always joined at the left corner
// of the trailing edge. The normal of the leading edge of the
// new piece is always the inverse normal of the trailing edge
// of the previous piece.
//
// This function returns the join vertex and facing in world space.
//
//Parameters: ( rmt::Vector& position, rmt::Vector& facing )
//
//Return: void
//
//=============================================================================
void RoadSegment::GetJoinPoint( rmt::Vector& position, rmt::Vector& facing )
{
// All segments are joined at the left top corner.
//
position = GetRoadSegmentData( )->GetCorner( 1 );
facing = GetRoadSegmentData( )->GetEdgeNormal( 2 );
facing.Scale( -1.0f );
}
*/
void RoadSegment::GetCorner( int index, rmt::Vector& out )
{
rAssert( 0 <= index && index < 4 );
out = mCorners[ index ];
}
void RoadSegment::GetEdgeNormal( int index, rmt::Vector& out )
{
rAssert( 0 <= index && index < 4 );
out = mEdgeNormals[ index ];
}
void RoadSegment::GetSegmentNormal( rmt::Vector& out )
{
out = mNormal;
}
unsigned int RoadSegment::GetNumLanes( void )
{
return GetRoad()->GetNumLanes();
}
float RoadSegment::GetLaneLength( unsigned int lane )
{
// [Dusit: July 6th, 2003]
// NOTE:
// This is the CORRECT way to produce the lane length value when
// the width of the roadsegment isn't guaranteed across its length.
// The only thing that it assumes (and is always correct) is that
// each lane is as wide as the other lanes at any given point along
// the length of the segment
//
// The problem with using this is that it requires a Sqrt (because
// it's too late for us to rearrange the data so that we can avoid
// this). So we continue using the old way because we're never off
// by more than 5 centimeters anyway.
//
float edgeT = ((float)(lane<<1) + 1.0f) / ((float)(GetNumLanes()<<1));
// find start & end points of the lane
rmt::Vector vec0, vec1, vec2, vec3;
GetCorner( 0, vec0 );
GetCorner( 1, vec1 );
GetCorner( 2, vec2 );
GetCorner( 3, vec3 );
// lane indices go from 0 to n, right to left ( n <=== 0 )
rmt::Vector bottomEdgeDir = vec0 - vec3; // points frm 3 to 0
rmt::Vector topEdgeDir = vec1 - vec2; // points frm 2 to 1
rmt::Vector start = vec3 + bottomEdgeDir * edgeT;
rmt::Vector end = vec2 + topEdgeDir * edgeT;
float expectedLength = (end - start).Magnitude();
return expectedLength;
/*
float computedLength = 0.0f;
// TODO:
// Because we can't assume that a lane is constant-width, this
// code is totally bogus...
if ( mfAngle > 0.0f )
{
// 2*PI*r for a circle.
// Theta*r for arc of theta degrees.
//
float fLaneOffset = mfLaneWidth * lane + mfLaneWidth;
computedLength = 2.0f * mfAngle * ( mfRadius + fLaneOffset );
}
else
{
// it's not a curve, both edge lengths will be equal.
//
computedLength = mfSegmentLength;
}
//rAssert( rmt::Epsilon( computedLength, expectedLength, 0.01f ) );
return computedLength;
*/
}
float RoadSegment::GetRoadWidth()
{
return mRoad->GetNumLanes() * mfLaneWidth;
}
/*
/////////////////////////////////////////////////////////////////
// TransformRoadSegment
/////////////////////////////////////////////////////////////////
//
TransformRoadSegment::TransformRoadSegment() :
RoadSegment( NULL )
{
mTransform.Identity();
mfScaleAlongFacing = 0.0f;
}
TransformRoadSegment::TransformRoadSegment(
const RoadSegmentData* pRoadSegmentData,
rmt::Matrix& transform )
:
RoadSegment( pRoadSegmentData )
{
mTransform = transform;
}
TransformRoadSegment::TransformRoadSegment(
const RoadSegmentData* pRoadSegmentData,
rmt::Matrix& transform,
float fScaleAlongFacing )
:
RoadSegment( pRoadSegmentData ),
mfScaleAlongFacing( fScaleAlongFacing )
{
mTransform = transform;
}
TransformRoadSegment::TransformRoadSegment(
const RoadSegmentData* pRoadSegmentData,
const rmt::Vector& facing,
const rmt::Vector& position )
:
RoadSegment( pRoadSegmentData )
{
rmt::Vector sApproximateUp( 0.0f, 1.0f, 0.0f );
mTransform.Identity( );
mTransform.FillHeading( facing, sApproximateUp );
mTransform.FillTranslate( position );
}
TransformRoadSegment::TransformRoadSegment(
const RoadSegmentData* pRoadSegmentData,
const rmt::Vector& facing,
const rmt::Vector& position,
float fScaleAlongFacing )
:
RoadSegment( pRoadSegmentData ),
mfScaleAlongFacing( fScaleAlongFacing )
{
rmt::Vector sApproximateUp( 0.0f, 1.0f, 0.0f );
mTransform.Identity( );
mTransform.FillHeading( facing, sApproximateUp );
mTransform.FillTranslate( position );
}
void TransformRoadSegment::GetCorner( int index, rmt::Vector& out ) const
{
out = GetRoadSegmentData( )->GetCorner( index );
out.z *= mfScaleAlongFacing;
out.Transform( mTransform );
}
void TransformRoadSegment::GetEdgeNormal( int index, rmt::Vector& out ) const
{
out = GetRoadSegmentData( )->GetEdgeNormal( index );
out.Rotate( mTransform );
}
void TransformRoadSegment::GetSegmentNormal( rmt::Vector& out ) const
{
out = GetRoadSegmentData( )->GetSegmentNormal( );
out.Rotate( mTransform );
}
//==============================================================================
//TransformRoadSegment::GetJoinPoint
//==============================================================================
//Description: RoadSegmentData pieces are always joined at the left corner
// of the trailing edge. The normal of the leading edge of the
// new piece is always the inverse normal of the trailing edge
// of the previous piece.
//
// This function returns the join vertex and facing in world space.
//
//Parameters: ( rmt::Vector& position, rmt::Vector& facing )
//
//Return: void
//
//=============================================================================
void TransformRoadSegment::GetJoinPoint( rmt::Vector& position, rmt::Vector& facing ) const
{
// All segments are joined at the left top corner.
//
facing = GetRoadSegmentData( )->GetEdgeNormal( 2 );
facing.Scale( -1.0f );
facing.Rotate( mTransform );
position = GetRoadSegmentData( )->GetCorner( 1 );
position.z *= mfScaleAlongFacing;
position.Transform( mTransform );
}
void TransformRoadSegment::GetBoundingBox(rmt::Box3D* box)
{
GetRoadSegmentData()->GetBoundingBox( *box );
(*box).high.z *= mfScaleAlongFacing;
(*box).high.Transform( mTransform );
(*box).low.Transform( mTransform );
}
void TransformRoadSegment::GetBoundingSphere(rmt::Sphere* sphere)
{
GetRoadSegmentData( )->GetBoundingSphere( *sphere );
(*sphere).radius *= mfScaleAlongFacing;
(*sphere).centre.Transform( mTransform );
}
void TransformRoadSegment::GetBoundingBox( rmt::Box3D& out ) const
{
GetRoadSegmentData( )->GetBoundingBox( out );
out.high.z *= mfScaleAlongFacing;
out.high.Transform( mTransform );
out.low.Transform( mTransform );
}
void TransformRoadSegment::GetBoundingSphere( rmt::Sphere& out ) const
{
out = GetRoadSegmentData( )->GetBoundingSphere( );
out.radius *= mfScaleAlongFacing;
out.centre.Transform( mTransform );
}
void TransformRoadSegment::GetTransform( rmt::Matrix &out ) const
{
out = mTransform;
}
*/
|