From a8d7e58705cae0a43cbbc3b996630a1877c81f26 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 21 May 2010 17:50:18 +0200 Subject: [PATCH] use Math::Bezier as alternative curve Math::Bezier seems to be better for airplanes (which require larger rounding distance) while Math::CatmullRom seems better for helicopters which can turn in place --- Makefile.PL | 5 +++-- artwork/world1/a-mask.png | Bin 3438 -> 3430 bytes trace-path.pl | 36 ++++++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index a98d5d1..6aeb0b4 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -2,8 +2,8 @@ use inc::Module::Install; use Module::AutoInstall; name 'LandingAirplanes'; -all_from 'lib/LandingAirplanes.pm'; -readme_from 'lib/LandingPairplanes.pm'; +#all_from 'lib/LandingAirplanes.pm'; +#readme_from 'lib/LandingPairplanes.pm'; license 'artistic'; requires 'SDL'; @@ -11,6 +11,7 @@ requires 'Carp'; requires 'Data::Dump'; requires 'Math::CatmullRom'; requires 'Algorithm::Line::Bresenham'; +requires 'Math::Bezier'; #requires ''; auto_include; diff --git a/artwork/world1/a-mask.png b/artwork/world1/a-mask.png index 22d5bfb413ddb57e5aee6ac67470a56a24ddd167..70ecd792b7c49c161334fea2070443c0eab252c9 100644 GIT binary patch delta 272 zcmaDS^-O9)p6O#x7srr_IdAVeu1Z!EaX47#`)%#IJNKF{oHYCsZz{IuP7mLw6Pv&P zV`g9o_)%TWz`*d}yTIl~_D!r}Gq1m8{IO>1wSBhC3?J%`Nt}Nx`5<=B z1LsYi@3CcKV2D4#J$WIc2=~0b-``3yFf_y;;@&)wy_r?)Cwr~5k?yU}2i^jG!{F)a K=d#Wzp$P!KvV1B4 delta 281 zcmaDR^-gL+p4n?p7srr_IdAVeX2}>bxE?H-QSEJ2`JCaS(~UEe->!?|{u8~sU83gh z_rL563=2Md|H8n)@W688M=@5>xaI6uu0?%+$;)uydXM3{%hC=Gq0CsV6g8OpPa~UH(8IJ+w}DphI`rPHdf}nohx1Z{?08MbF=Sj_tqxA z`+Ik5WnRv``?vP&-&k3n{rTUqXMfk8{msl!VXi+}kx@_K*{=7$zqDP6dcB{2-t7OP zztw-8z0Y=_xEIN85B|!zavx;RSo-@jFf_P-0K120=Ied$F9V&?(EfpGvmu8(>t+Q; dMnnew( @path ); my $points = $#path + 1 - 4; # remove start/end points - my @curve = $curve->curve( $points ); + return $curve->curve( $points ); +} + +sub curve_bezier { + my $curve = Math::Bezier->new( @path ); + return $curve->curve( $#path + 1 ); +} + +our $curve_type = 0; + +sub curve { + # add landing path points + push @path, lading_points( $path[-2], $path[-1] ) if $#path > 1; + + my $type = 1; + + my @curve = $curve_type ? curve_catmull_rom : curve_bezier; debug 'curve' => @curve; my $i = 0; @@ -147,24 +164,13 @@ sub curve_catmull_rom { sub { $app->pixel( @_, $path_color ) } ); } + $app->sync; + push @airplanes, Airplane->new( $app ); $airplanes[-1]->set_path( @path ); - $app->sync; reset_path; } -sub curve { - # add landing path points - push @path, lading_points( $path[-2], $path[-1] ) if $#path > 1; - - if ( 1 ) { - curve_catmull_rom; - } else { - - } - -} - sub clear_screen { my ( $mask ) = @_; reset_path; @@ -208,6 +214,8 @@ sub handle_events { $current_mask++; $current_mask = 0 if $current_mask > $#masks; clear_screen $current_mask; + } elsif ( $key eq 't' ) { # XXX curve type + $curve_type = ! $curve_type; } else { warn "unknown key $key"; } -- 2.20.1