From: Dobrica Pavlinusic Date: Fri, 21 May 2010 15:50:18 +0000 (+0200) Subject: use Math::Bezier as alternative curve X-Git-Url: http://git.rot13.org/?p=perl-landing-airplanes.git;a=commitdiff_plain;h=a8d7e58705cae0a43cbbc3b996630a1877c81f26;hp=4361ed72f1bcfcd545354266c7b8fb3362d33a19 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 --- 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 22d5bfb..70ecd79 100644 Binary files a/artwork/world1/a-mask.png and b/artwork/world1/a-mask.png differ diff --git a/trace-path.pl b/trace-path.pl index 202f8ac..b97779c 100755 --- a/trace-path.pl +++ b/trace-path.pl @@ -10,6 +10,7 @@ use SDL::Constants; use SDL::Event; use Math::CatmullRom; use Algorithm::Line::Bresenham qw(line); +use Math::Bezier; use Carp qw(cluck); use Data::Dump qw(dump); @@ -134,7 +135,23 @@ sub curve_catmull_rom { my $curve = Math::CatmullRom->new( @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"; }