projects
/
perl-landing-airplanes.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b090627
)
cleanup path to curve
author
Dobrica Pavlinusic
<dpavlin@rot13.org>
Wed, 19 May 2010 18:09:42 +0000
(20:09 +0200)
committer
Dobrica Pavlinusic
<dpavlin@rot13.org>
Wed, 19 May 2010 18:09:42 +0000
(20:09 +0200)
trace-path.pl
patch
|
blob
|
history
diff --git
a/trace-path.pl
b/trace-path.pl
index
c3fae62
..
e58fe4f
100755
(executable)
--- a/
trace-path.pl
+++ b/
trace-path.pl
@@
-45,15
+45,21
@@
our $black = SDL::Color->new( 0x00, 0x00, 0x00 );
my ( $last_x, $last_y ) = ( 0,0 );
our @path;
my ( $last_x, $last_y ) = ( 0,0 );
our @path;
+sub reset_path { @path = () }
sub curve {
sub curve {
- return unless $#path > 4;
- my $curve = Math::CatmullRom->new( splice @path, 0, $#path + $#path / 2 );
+ if ( $#path < ( 4 * 2 - 1 ) ) { # less than 4 points
+ warn "path too short ", dump @path;
+ reset_path;
+ return;
+ }
+
+ my $curve = Math::CatmullRom->new( @path );
my @curve = $curve->curve( $mouse_trashold * 10 );
debug 'curve' => @curve;
my $i = 0;
my @curve = $curve->curve( $mouse_trashold * 10 );
debug 'curve' => @curve;
my $i = 0;
- while ( $i < $#curve ) {
+ while ( $i < $#curve
- 4
) {
my $from_x = int($curve[$i++]);
my $from_y = int($curve[$i++]);
my $to_x = int($curve[$i++]);
my $from_x = int($curve[$i++]);
my $from_y = int($curve[$i++]);
my $to_x = int($curve[$i++]);
@@
-67,6
+73,7
@@
sub curve {
);
}
$app->sync;
);
}
$app->sync;
+ reset_path;
}
sub handle_events {
}
sub handle_events {
@@
-90,7
+97,7
@@
sub handle_events {
if ( $key eq 's' ) { # XXX draw curve
curve;
} elsif ( $key eq 'backspace' ) { # XXX clean screen
if ( $key eq 's' ) { # XXX draw curve
curve;
} elsif ( $key eq 'backspace' ) { # XXX clean screen
-
@path = ()
;
+
reset_path
;
my $rect = SDL::Rect->new( -x => 0, -y => 0, -w => $w, -h => $h );
$app->fill( $rect, $black );
$app->update( $rect );
my $rect = SDL::Rect->new( -x => 0, -y => 0, -w => $w, -h => $h );
$app->fill( $rect, $black );
$app->update( $rect );