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:
1f7dbb7
)
detect landing point and rote over points
author
Dobrica Pavlinusic
<dpavlin@rot13.org>
Wed, 19 May 2010 22:14:25 +0000
(
00:14
+0200)
committer
Dobrica Pavlinusic
<dpavlin@rot13.org>
Wed, 19 May 2010 22:14:25 +0000
(
00:14
+0200)
trace-path.pl
patch
|
blob
|
history
diff --git
a/trace-path.pl
b/trace-path.pl
index
3fd2935
..
6239d13
100755
(executable)
--- a/
trace-path.pl
+++ b/
trace-path.pl
@@
-45,6
+45,8
@@
our $app = SDL::App->new(
our $app_rect = SDL::Rect->new( -x => 0, -y => 0, -width => $w, -height => $h );
$mask->blit( $mask->rect, $app, $app_rect );
our $app_rect = SDL::Rect->new( -x => 0, -y => 0, -width => $w, -height => $h );
$mask->blit( $mask->rect, $app, $app_rect );
+$app->sync;
+
my @landing;
my @landing;
@@
-70,10
+72,6
@@
foreach ( 0 .. $mask->height / $mask_step ) {
warn 'lading ',dump(@landing);
warn 'lading ',dump(@landing);
-exit;
-
-$app->sync;
-
our $event = SDL::Event->new;
our $mouse_down = 0;
our $event = SDL::Event->new;
our $mouse_down = 0;
@@
-84,6
+82,17
@@
our @path;
sub reset_path { @path = () }
sub curve {
sub reset_path { @path = () }
sub curve {
+
+ my $mask_col = $mask->pixel( $path[-2], $path[-1] );
+ my $mask_hex = sprintf '%02x%02x%02x', $mask_col->r, $mask_col->g, $mask_col->b;
+ warn "mask $path[-2] $path[1] $mask_hex\n";
+
+ if ( $mask_hex eq '000000' ) { # push landing point at path end
+ foreach ( 1 .. 6 ) {
+ push @path, $landing[$_]->[0], $landing[$_]->[1];
+ }
+ }
+
if ( $#path < ( 4 * 2 - 1 ) ) { # less than 4 points
warn "path too short ", dump @path;
reset_path;
if ( $#path < ( 4 * 2 - 1 ) ) { # less than 4 points
warn "path too short ", dump @path;
reset_path;
@@
-120,6
+129,7
@@
sub handle_events {
} elsif ( $type == SDL_MOUSEBUTTONUP() ) {
debug 'mouse up', $event->button_x, $event->button_y;
$mouse_down = 0;
} elsif ( $type == SDL_MOUSEBUTTONUP() ) {
debug 'mouse up', $event->button_x, $event->button_y;
$mouse_down = 0;
+
curve;
} elsif ( $type == SDL_QUIT() ) {
exit;
curve;
} elsif ( $type == SDL_QUIT() ) {
exit;
@@
-129,11
+139,12
@@
sub handle_events {
exit if $key =~ m/^[xq]$/;
if ( $key eq 's' ) { # XXX draw curve
curve;
exit if $key =~ m/^[xq]$/;
if ( $key eq 's' ) { # XXX draw curve
curve;
- } elsif ( $key eq 'backspace' ) { # XXX clean screen
+ } elsif ( $key eq 'backspace'
|| $key eq 'c'
) { # XXX clean screen
reset_path;
reset_path;
- my $rect = SDL::Rect->new( -x => 0, -y => 0, -w => $w, -h => $h );
- $app->fill( $rect, $black );
- $app->update( $rect );
+ $app->fill( $app->rect, $black );
+# $app->update( $rect );
+ $mask->blit( $mask->rect, $app, $app_rect );
+ $app->sync;
} elsif ( $key eq 'd' ) { # XXX toggle debug
$debug = ! $debug;
warn "debug $debug\n";
} elsif ( $key eq 'd' ) { # XXX toggle debug
$debug = ! $debug;
warn "debug $debug\n";