00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLPolygon.h"
00028
00029 #include "OSDLSurface.h"
00030 #include "OSDLPoint2D.h"
00031 #include "OSDLVideo.h"
00032
00033
00034 #ifdef OSDL_USES_CONFIG_H
00035 #include "OSDLConfig.h"
00036 #endif // OSDL_USES_CONFIG_H
00037
00038 #if OSDL_ARCH_NINTENDO_DS
00039 #include "OSDLConfigForNintendoDS.h"
00040 #endif // OSDL_ARCH_NINTENDO_DS
00041
00042
00043 #if OSDL_USES_SDL_GFX
00044 #include "SDL_gfxPrimitives.h"
00045 #endif // OSDL_USES_SDL_GFX
00046
00047
00048
00049
00050 using std::string ;
00051 using std::list ;
00052
00053 using namespace Ceylan::Maths ;
00054 using namespace OSDL::Video ;
00055
00056
00057 using Ceylan::Maths::Real ;
00058
00059
00060
00061
00062
00063
00064
00065
00066 bool TwoDimensional::drawPie( Surface & targetSurface,
00067 Coordinate xCenter, Coordinate yCenter, Length radius,
00068 Ceylan::Maths::AngleInDegrees angleStart,
00069 Ceylan::Maths::AngleInDegrees angleStop,
00070 Pixels::ColorElement red, Pixels::ColorElement green,
00071 Pixels::ColorElement blue, Pixels::ColorElement alpha )
00072 {
00073
00074 #if OSDL_USES_SDL_GFX
00075
00076 return ( ::filledPieRGBA( & targetSurface.getSDLSurface(),
00077 xCenter, yCenter, radius, static_cast<Coordinate>( angleStart ),
00078 static_cast<Coordinate>( angleStop ), red, green, blue, alpha ) == 0 ) ;
00079
00080 #else // OSDL_USES_SDL_GFX
00081
00082 return false ;
00083
00084 #endif // OSDL_USES_SDL_GFX
00085
00086 }
00087
00088
00089
00090 bool TwoDimensional::drawPie( Surface & targetSurface,
00091 Coordinate xCenter, Coordinate yCenter, Length radius,
00092 Ceylan::Maths::AngleInDegrees angleStart,
00093 Ceylan::Maths::AngleInDegrees angleStop,
00094 Pixels::ColorDefinition colorDef )
00095 {
00096
00097 #if OSDL_USES_SDL_GFX
00098
00099 return ( ::filledPieColor( & targetSurface.getSDLSurface(),
00100 xCenter, yCenter, radius,
00101 static_cast<Coordinate>( angleStart ),
00102 static_cast<Coordinate>( angleStop ),
00103 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) ) == 0 ) ;
00104
00105 #else // OSDL_USES_SDL_GFX
00106
00107 return false ;
00108
00109 #endif // OSDL_USES_SDL_GFX
00110
00111 }
00112
00113
00114
00115 bool TwoDimensional::drawTriangle( Surface & targetSurface,
00116 Coordinate x1, Coordinate y1,
00117 Coordinate x2, Coordinate y2,
00118 Coordinate x3, Coordinate y3,
00119 Pixels::ColorElement red, Pixels::ColorElement green,
00120 Pixels::ColorElement blue, Pixels::ColorElement alpha, bool filled )
00121 {
00122
00123 #if OSDL_USES_SDL_GFX
00124
00125 if ( filled )
00126 {
00127
00128 return ( ::filledTrigonRGBA( & targetSurface.getSDLSurface(),
00129 x1, y1, x2, y2, x3, y3, red, green, blue, alpha ) == 0 ) ;
00130
00131 }
00132 else
00133 {
00134
00135 if ( VideoModule::GetAntiAliasingState() )
00136 {
00137 return ( ::aatrigonRGBA( & targetSurface.getSDLSurface(),
00138 x1, y1, x2, y2, x3, y3, red, green, blue, alpha ) == 0 ) ;
00139
00140 }
00141 else
00142 {
00143 return ( ::trigonRGBA( & targetSurface.getSDLSurface(),
00144 x1, y1, x2, y2, x3, y3, red, green, blue, alpha ) == 0 ) ;
00145
00146 }
00147
00148 }
00149
00150 #else // OSDL_USES_SDL_GFX
00151
00152 return false ;
00153
00154 #endif // OSDL_USES_SDL_GFX
00155
00156 }
00157
00158
00159
00160 bool TwoDimensional::drawTriangle( Surface & targetSurface,
00161 Coordinate x1, Coordinate y1,
00162 Coordinate x2, Coordinate y2,
00163 Coordinate x3, Coordinate y3,
00164 Pixels::ColorDefinition colorDef, bool filled )
00165 {
00166
00167 #if OSDL_USES_SDL_GFX
00168
00169 if ( filled )
00170 {
00171
00172 return ( ::filledTrigonColor( & targetSurface.getSDLSurface(),
00173 x1, y1, x2, y2, x3, y3,
00174 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) ) == 0 ) ;
00175
00176 }
00177 else
00178 {
00179
00180 if ( VideoModule::GetAntiAliasingState() )
00181 {
00182
00183 return ( ::aatrigonColor( & targetSurface.getSDLSurface(),
00184 x1, y1, x2, y2, x3, y3,
00185 Pixels::convertColorDefinitionToRawPixelColor( colorDef )
00186 ) == 0 ) ;
00187
00188 }
00189 else
00190 {
00191
00192 return ( ::trigonColor( & targetSurface.getSDLSurface(),
00193 x1, y1, x2, y2, x3, y3,
00194 Pixels::convertColorDefinitionToRawPixelColor( colorDef )
00195 ) == 0 ) ;
00196
00197 }
00198
00199 }
00200
00201 #else // OSDL_USES_SDL_GFX
00202
00203 return false ;
00204
00205 #endif // OSDL_USES_SDL_GFX
00206
00207 }
00208
00209
00210
00211 bool TwoDimensional::drawTriangle( Surface & targetSurface,
00212 const Point2D & p1, const Point2D & p2, const Point2D & p3,
00213 Pixels::ColorElement red, Pixels::ColorElement green,
00214 Pixels::ColorElement blue, Pixels::ColorElement alpha,
00215 bool filled )
00216 {
00217
00218 #if OSDL_USES_SDL_GFX
00219
00220 if ( filled )
00221 {
00222
00223 return ( ::filledTrigonRGBA( & targetSurface.getSDLSurface(),
00224 p1.getX(), p1.getY(),p2.getX(),p2.getY(), p3.getX(),p3.getY(),
00225 red, green, blue, alpha ) == 0 ) ;
00226
00227 }
00228 else
00229 {
00230
00231 if ( VideoModule::GetAntiAliasingState() )
00232 {
00233 return ( ::aatrigonRGBA( & targetSurface.getSDLSurface(),
00234 p1.getX(), p1.getY(),p2.getX(),p2.getY(), p3.getX(),p3.getY(),
00235 red, green, blue, alpha ) == 0 ) ;
00236
00237 }
00238 else
00239 {
00240 return ( ::trigonRGBA( & targetSurface.getSDLSurface(),
00241 p1.getX(), p1.getY(),p2.getX(),p2.getY(), p3.getX(),p3.getY(),
00242 red, green, blue, alpha ) == 0 ) ;
00243
00244 }
00245
00246 }
00247
00248 #else // OSDL_USES_SDL_GFX
00249
00250 return false ;
00251
00252 #endif // OSDL_USES_SDL_GFX
00253
00254 }
00255
00256
00257
00258 bool TwoDimensional::drawTriangle( Surface & targetSurface,
00259 const Point2D & p1, const Point2D & p2, const Point2D & p3,
00260 Pixels::ColorDefinition colorDef, bool filled )
00261 {
00262
00263 #if OSDL_USES_SDL_GFX
00264
00265 if ( filled )
00266 {
00267
00268 return ( ::filledTrigonColor( & targetSurface.getSDLSurface(),
00269 p1.getX(), p1.getY(),p2.getX(),p2.getY(), p3.getX(),p3.getY(),
00270 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00271 == 0 ) ;
00272
00273 }
00274 else
00275 {
00276
00277 if ( VideoModule::GetAntiAliasingState() )
00278 {
00279
00280 return ( ::aatrigonColor( & targetSurface.getSDLSurface(),
00281 p1.getX(), p1.getY(),p2.getX(),p2.getY(), p3.getX(),p3.getY(),
00282 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00283 == 0 ) ;
00284
00285 }
00286 else
00287 {
00288
00289 return ( ::trigonColor( & targetSurface.getSDLSurface(),
00290 p1.getX(), p1.getY(),p2.getX(),p2.getY(), p3.getX(),p3.getY(),
00291 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) )
00292 == 0 ) ;
00293
00294 }
00295
00296 }
00297
00298 #else // OSDL_USES_SDL_GFX
00299
00300 return false ;
00301
00302 #endif // OSDL_USES_SDL_GFX
00303
00304 }
00305
00306
00307
00308 bool TwoDimensional::drawPolygon( Surface & targetSurface,
00309 const listPoint2D & summits, Coordinate x, Coordinate y,
00310 Pixels::ColorElement red, Pixels::ColorElement green,
00311 Pixels::ColorElement blue, Pixels::ColorElement alpha, bool filled )
00312 {
00313
00314
00315 #if OSDL_USES_SDL_GFX
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 Ceylan::System::Size vertexCount = summits.size() ;
00326
00327 Coordinate * abscissaArray = new Coordinate[ vertexCount ] ;
00328 Coordinate * ordinateArray = new Coordinate[ vertexCount ] ;
00329
00330 vertexCount = 0 ;
00331
00332 for ( listPoint2D::const_iterator it = summits.begin();
00333 it != summits.end(); it++ )
00334 {
00335
00336 abscissaArray[ vertexCount ] = (*it)->getX() + x ;
00337 ordinateArray[ vertexCount ] = (*it)->getY() + y ;
00338
00339 vertexCount++ ;
00340
00341 }
00342
00343
00344
00345
00346 if ( filled )
00347 {
00348
00349 int res = ::filledPolygonRGBA( & targetSurface.getSDLSurface(),
00350 abscissaArray, ordinateArray, static_cast<int>( vertexCount ),
00351 red, green, blue, alpha ) ;
00352
00353 delete [] abscissaArray ;
00354 delete [] ordinateArray ;
00355
00356 return ( res == 0 ) ;
00357
00358 }
00359 else
00360 {
00361
00362 if ( VideoModule::GetAntiAliasingState() )
00363 {
00364
00365 int res = ::aapolygonRGBA( & targetSurface.getSDLSurface(),
00366 abscissaArray, ordinateArray, static_cast<int>( vertexCount ),
00367 red, green, blue, alpha ) ;
00368
00369 delete [] abscissaArray ;
00370 delete [] ordinateArray ;
00371
00372 return ( res == 0 ) ;
00373
00374 }
00375 else
00376 {
00377
00378 int res = ::polygonRGBA( & targetSurface.getSDLSurface(),
00379 abscissaArray, ordinateArray, static_cast<int>( vertexCount ),
00380 red, green, blue, alpha ) ;
00381
00382 return ( res == 0 ) ;
00383
00384 }
00385
00386 }
00387
00388 #else // OSDL_USES_SDL_GFX
00389
00390 return false ;
00391
00392 #endif // OSDL_USES_SDL_GFX
00393
00394 }
00395
00396
00397
00398 bool TwoDimensional::drawPolygon( Surface & targetSurface,
00399 const listPoint2D & summits, Coordinate x, Coordinate y,
00400 Pixels::ColorDefinition colorDef, bool filled )
00401 {
00402
00403
00404 #if OSDL_USES_SDL_GFX
00405
00406
00407
00408
00409
00410
00411 Ceylan::System::Size vertexCount = summits.size() ;
00412
00413 Coordinate * abscissaArray = new Coordinate[ vertexCount ] ;
00414 Coordinate * ordinateArray = new Coordinate[ vertexCount ] ;
00415
00416 vertexCount = 0 ;
00417
00418 for ( listPoint2D::const_iterator it = summits.begin();
00419 it != summits.end(); it++ )
00420 {
00421
00422 abscissaArray[ vertexCount ] = (*it)->getX() + x ;
00423 ordinateArray[ vertexCount ] = (*it)->getY() + y ;
00424
00425 vertexCount++ ;
00426
00427 }
00428
00429
00430
00431
00432 if ( filled )
00433 {
00434
00435 int res = ::filledPolygonColor( & targetSurface.getSDLSurface(),
00436 abscissaArray, ordinateArray, static_cast<int>( vertexCount ),
00437 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) ) ;
00438
00439 delete [] abscissaArray ;
00440 delete [] ordinateArray ;
00441
00442 return ( res == 0 ) ;
00443
00444 }
00445 else
00446 {
00447
00448 if ( VideoModule::GetAntiAliasingState() )
00449 {
00450
00451 int res = ::aapolygonColor( & targetSurface.getSDLSurface(),
00452 abscissaArray, ordinateArray, static_cast<int>( vertexCount ),
00453 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) ) ;
00454
00455 delete [] abscissaArray ;
00456 delete [] ordinateArray ;
00457
00458 return ( res == 0 ) ;
00459
00460 }
00461 else
00462 {
00463
00464 int res = ::polygonColor( & targetSurface.getSDLSurface(),
00465 abscissaArray, ordinateArray, static_cast<int>( vertexCount ),
00466 Pixels::convertColorDefinitionToRawPixelColor( colorDef ) ) ;
00467
00468 delete [] abscissaArray ;
00469 delete [] ordinateArray ;
00470
00471 return ( res == 0 ) ;
00472
00473 }
00474
00475 }
00476
00477 #else // OSDL_USES_SDL_GFX
00478
00479 return false ;
00480
00481 #endif // OSDL_USES_SDL_GFX
00482
00483 }
00484
00485
00486
00487
00488
00489 using namespace OSDL::Video::TwoDimensional ;
00490
00491
00492
00493 Polygon::Polygon( listPoint2D & summits, bool listOwner ) :
00494 Locatable2D(),
00495 _summits( & summits ),
00496 _listOwner( listOwner )
00497 {
00498
00499 }
00500
00501
00502
00503 Polygon::~Polygon() throw()
00504 {
00505
00506 if ( _summits != 0 )
00507 {
00508
00509 if ( _listOwner )
00510 {
00511
00512 for ( listPoint2D::iterator it = _summits->begin();
00513 it != _summits->end(); it++ )
00514 {
00515 delete *it ;
00516 }
00517
00518
00519
00520
00521
00522
00523 delete _summits ;
00524
00525 }
00526
00527
00528 }
00529
00530 }
00531
00532
00533
00534 bool Polygon::draw( Surface & targetSurface,
00535 Pixels::ColorDefinition colorDef, bool filled ) const
00536 {
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 listPoint2D * vertices = & Duplicate( *_summits ) ;
00550 Apply( getLocalMatrix(), * vertices ) ;
00551
00552
00553
00554
00555
00556
00557
00558 return drawPolygon( targetSurface, * vertices, 0, 0, colorDef, filled ) ;
00559
00560 }
00561
00562
00563
00564 listPoint2D & Polygon::getPoints() const
00565 {
00566
00567 return * _summits ;
00568
00569 }
00570
00571
00572
00573 void Polygon::setPoints( listPoint2D & newList )
00574 {
00575
00576 if ( _listOwner )
00577 {
00578
00579 if ( _summits != 0 )
00580 Delete( * _summits ) ;
00581
00582 }
00583
00584 _summits = & newList ;
00585
00586 }
00587
00588
00589
00590 bool Polygon::isListOwner() const
00591 {
00592
00593 return _listOwner ;
00594
00595 }
00596
00597
00598
00599 const string Polygon::toString( Ceylan::VerbosityLevels level ) const
00600 {
00601
00602 string res ;
00603
00604 if ( _summits && ! _summits->empty() )
00605 {
00606
00607 res = "Polygon defined by "
00608 + Ceylan::toString(
00609 static_cast<Ceylan::Uint32>( _summits->size() ) )
00610 + " summits" ;
00611
00612 if ( level == Ceylan::low )
00613 return res ;
00614
00615 res += ". Its summits are: " ;
00616
00617 list<string> summitsCoordinates ;
00618
00619 Ceylan::Uint32 count = 0 ;
00620
00621 for ( listPoint2D::const_iterator it = _summits->begin();
00622 it != _summits->end(); it++ )
00623 {
00624
00625 count++ ;
00626 summitsCoordinates.push_back( "summit #"
00627 + Ceylan::toString( count ) + ": "
00628 + (*it)->toString( level ) ) ;
00629 }
00630
00631 res += Ceylan::formatStringList( summitsCoordinates ) ;
00632
00633 return res + "This polygon has for referential: "
00634 + Locatable2D::toString( level ) ;
00635
00636 }
00637
00638 return "Void polygon (no summit registered)" ;
00639
00640 }
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650 TwoDimensional::Polygon & Polygon::CreateFlakeBranch(
00651 Length length, Length thickness,
00652 AngleInDegrees childAngle, Ratio branchingHeightRatio, Ratio scale )
00653 {
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 AngleInRadians realAngle = Ceylan::Maths::DegreeToRadian( childAngle ) ;
00673
00674
00675
00676 Point2D * alpha = & Point2D::CreateFrom( 0, length ) ;
00677 Point2D * beta = & Point2D::CreateFrom( thickness / 2.0f, length ) ;
00678
00679 Point2D * nu = & Point2D::CreateFrom( thickness / 2.0f, 0 ) ;
00680 Point2D * mu = & Point2D::CreateFrom( thickness / 2.0f,
00681 length * branchingHeightRatio ) ;
00682
00683 Point2D * omicron = & Point2D::CreateFrom( 0, 0 ) ;
00684
00685
00686 Point2D * gamma = & Point2D::CreateFrom( thickness / 2.0f,
00687 length * branchingHeightRatio + thickness * scale / Sin( realAngle ) ) ;
00688
00689
00690 Point2D * epsilon = & Point2D::CreateFrom(
00691 thickness / 2 + length * scale * Sin( realAngle ),
00692 length * branchingHeightRatio + scale * length * Cos( realAngle ) ) ;
00693
00694
00695 Point2D * delta = & Point2D::CreateFrom(
00696 epsilon->getX() - thickness * scale * Cos( realAngle ),
00697 epsilon->getY() + thickness * scale * Sin( realAngle ) ) ;
00698
00699 listPoint2D * summits = new listPoint2D ;
00700
00701 summits->push_back( alpha ) ;
00702 summits->push_back( beta ) ;
00703 summits->push_back( gamma ) ;
00704 summits->push_back( delta ) ;
00705 summits->push_back( epsilon ) ;
00706 summits->push_back( mu ) ;
00707 summits->push_back( nu ) ;
00708 summits->push_back( omicron ) ;
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730 Point2D * alpha1 = new Point2D( * alpha ) ;
00731 alpha1->flipX() ;
00732
00733 Point2D * beta1 = new Point2D( * beta ) ;
00734 beta1->flipX() ;
00735
00736 Point2D * gamma1 = new Point2D( * gamma ) ;
00737 gamma1->flipX() ;
00738
00739 Point2D * delta1 = new Point2D( * delta ) ;
00740 delta1->flipX() ;
00741
00742 Point2D * epsilon1 = new Point2D( * epsilon ) ;
00743 epsilon1->flipX() ;
00744
00745 Point2D * mu1 = new Point2D( * mu ) ;
00746 mu1->flipX() ;
00747
00748 Point2D * nu1 = new Point2D( * nu ) ;
00749 nu1->flipX() ;
00750
00751
00752
00753
00754
00755
00756 Point2D * omicron1 = new Point2D( * omicron ) ;
00757
00758 summits->push_back( alpha1 ) ;
00759 summits->push_back( beta1 ) ;
00760 summits->push_back( gamma1 ) ;
00761 summits->push_back( delta1 ) ;
00762 summits->push_back( epsilon1 ) ;
00763 summits->push_back( mu1 ) ;
00764 summits->push_back( nu1 ) ;
00765 summits->push_back( omicron1 ) ;
00766
00767
00768 return * new Polygon( * summits, false ) ;
00769
00770 }
00771
00772
00773
00774 listPoint2D & Polygon::Duplicate( const listPoint2D & source )
00775 {
00776
00777 listPoint2D * newList = new listPoint2D ;
00778
00779 for ( listPoint2D::const_iterator it = source.begin();
00780 it != source.end(); it++ )
00781 {
00782
00783 newList->push_back( new Point2D( * (*it) ) ) ;
00784
00785 }
00786
00787 return * newList ;
00788
00789 }
00790
00791
00792
00793 void Polygon::Delete( listPoint2D & listToBeDeleted )
00794 {
00795
00796 for ( listPoint2D::iterator it = listToBeDeleted.begin();
00797 it != listToBeDeleted.end(); it++ )
00798 {
00799
00800 delete (*it) ;
00801
00802 }
00803
00804 delete & listToBeDeleted ;
00805
00806 }
00807
00808
00809
00810 listPoint2D & Polygon::Append( listPoint2D & toBeAugmented,
00811 const listPoint2D & toAppend )
00812 {
00813
00814 for ( listPoint2D::const_iterator it = toAppend.begin();
00815 it != toAppend.end(); it++ )
00816 {
00817
00818 toBeAugmented.push_back( (*it) ) ;
00819
00820 }
00821
00822
00823
00824 return toBeAugmented ;
00825
00826 }
00827
00828
00829
00830 listPoint2D & Polygon::Apply(
00831 const Linear::HomogeneousMatrix3 & transformation,
00832 listPoint2D & sourceList )
00833 {
00834
00835 for ( listPoint2D::iterator it = sourceList.begin();
00836 it != sourceList.end(); it++ )
00837 {
00838
00839
00840
00841
00842
00843
00844 Linear::Vector2 temp( static_cast<Real>( (*it)->getX()),
00845 static_cast<Real>( (*it)->getY()) ) ;
00846 (*it)->setFrom( transformation * temp ) ;
00847
00848 }
00849
00850
00851
00852 return sourceList ;
00853
00854 }
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864 PolygonSet::PolygonSet( bool listOwner ):
00865 Locatable2D(),
00866 _polygonList( 0 ),
00867 _listOwner( listOwner )
00868 {
00869
00870 }
00871
00872
00873
00874 PolygonSet::PolygonSet( std::list<listPoint2D *> & polygonList,
00875 bool listOwner ):
00876 Locatable2D(),
00877 _polygonList( & polygonList ),
00878 _listOwner( listOwner )
00879 {
00880
00881 }
00882
00883
00884
00885 PolygonSet::~PolygonSet() throw()
00886 {
00887
00888 if ( _polygonList != 0 )
00889 {
00890
00891 if ( _listOwner )
00892 {
00893
00894
00895 for ( list<listPoint2D *>::iterator it = _polygonList->begin();
00896 it != _polygonList->end(); it++ )
00897 {
00898
00899 Polygon::Delete( * (*it) ) ;
00900
00901 }
00902
00903 delete _polygonList ;
00904
00905 }
00906
00907 }
00908
00909 }
00910
00911
00912
00913 void PolygonSet::addPointsOf( TwoDimensional::Polygon & newPolygon )
00914 {
00915
00916 if ( newPolygon.isListOwner() )
00917 Ceylan::emergencyShutdown( "PolygonSet::addPointsOf: "
00918 "added polygon should not own its points." ) ;
00919
00920 addPointList( newPolygon.getPoints() ) ;
00921
00922 }
00923
00924
00925
00926 void PolygonSet::addPointList( listPoint2D & listToAdd )
00927 {
00928
00929 if ( _polygonList == 0 )
00930 _polygonList = new list<listPoint2D *> ;
00931
00932 _polygonList->push_back( & listToAdd ) ;
00933
00934 }
00935
00936
00937
00938 bool PolygonSet::draw( Surface & targetSurface, Coordinate x, Coordinate y,
00939 Pixels::ColorDefinition colorDef, bool filled ) const
00940 {
00941
00942 bool result = true ;
00943
00944 for ( list<listPoint2D *>::const_iterator it = _polygonList->begin();
00945 it != _polygonList->end(); it++ )
00946 {
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956 if ( drawPolygon( targetSurface, * (*it), x, y, colorDef, filled )
00957 == false )
00958 result = false ;
00959
00960 }
00961
00962 return result ;
00963
00964 }
00965
00966
00967
00968 const string PolygonSet::toString( Ceylan::VerbosityLevels level ) const
00969 {
00970
00971 string res ;
00972
00973 if ( _polygonList && ( ! _polygonList->empty() ) )
00974 {
00975
00976 res = "Polygon set made of "
00977 + Ceylan::toString(
00978 static_cast<Ceylan::Uint32>( _polygonList->size() ) )
00979 + " separate polygons" ;
00980
00981 if ( level == Ceylan::low )
00982 return res ;
00983
00984 res += ". Its polygons are: " ;
00985
00986 list<string> summitsCoordinates ;
00987
00988 Ceylan::Uint32 polygonCount = 0 ;
00989 Ceylan::Uint32 summitCount ;
00990
00991 for ( list<listPoint2D *>::const_iterator itPolygonList
00992 = _polygonList->begin();
00993 itPolygonList != _polygonList->end(); itPolygonList++ )
00994 {
00995
00996 polygonCount++ ;
00997
00998 res += "For polygon #"
00999 + Ceylan::toString( polygonCount ) + ": " ;
01000
01001 summitCount = 0 ;
01002 summitsCoordinates.clear() ;
01003
01004 for ( listPoint2D::iterator it = (*itPolygonList)->begin();
01005 it != (*itPolygonList)->end(); it++ )
01006 {
01007
01008 summitCount++ ;
01009 summitsCoordinates.push_back( "summit #"
01010 + Ceylan::toString( summitCount ) + ": "
01011 + (*it)->toString( level ) ) ;
01012
01013 }
01014
01015 res += Ceylan::formatStringList( summitsCoordinates ) ;
01016
01017 }
01018
01019 return res + "This polygon set has for referential: "
01020 + Locatable2D::toString( level ) ;
01021 }
01022
01023 return "Void set of polygons (no polygon registered)" ;
01024
01025 }
01026
01027
01028
01029 PolygonSet & PolygonSet::CreateFlake(
01030 Ceylan::Uint8 branchCount, Length length, Length thickness,
01031 Ceylan::Maths::AngleInDegrees childAngle, Ratio branchingHeightRatio,
01032 Ratio scale )
01033 {
01034
01035 if ( branchCount == 0 )
01036 Ceylan::emergencyShutdown( "PolygonSet::CreateFlake: "
01037 "snow flakes should have at least one branch." ) ;
01038
01039
01040 Polygon & modelBranch = Polygon::CreateFlakeBranch( length,
01041 thickness, childAngle, branchingHeightRatio, scale ) ;
01042
01043
01044
01045
01046
01047
01048 PolygonSet & result = * new PolygonSet( true ) ;
01049
01050
01051
01052
01053
01054
01055
01056 Linear::HomogeneousMatrix3 transformation( 360.0f / branchCount,
01057 Linear::Vector2( 0, 0 ) ) ;
01058
01059
01060 listPoint2D * lastlyCreatedBranchPoints = & modelBranch.getPoints() ;
01061 result.addPointList( * lastlyCreatedBranchPoints ) ;
01062
01063 listPoint2D * newlyCreatedBranchPoints ;
01064
01065
01066
01067
01068
01069
01070 for ( Ceylan::Uint8 count = 1; count < branchCount; count++ )
01071 {
01072
01073 newlyCreatedBranchPoints = & Polygon::Apply( transformation,
01074 Polygon::Duplicate( * lastlyCreatedBranchPoints ) ) ;
01075
01076 result.addPointList( * newlyCreatedBranchPoints ) ;
01077 lastlyCreatedBranchPoints = newlyCreatedBranchPoints ;
01078
01079 }
01080
01081 delete & modelBranch ;
01082
01083
01084
01085
01086
01087
01088
01089 return result ;
01090
01091 }
01092