From: Dobrica Pavlinusic Date: Thu, 20 May 2010 14:57:15 +0000 (+0200) Subject: rotate airplane image X-Git-Url: http://git.rot13.org/?p=perl-landing-airplanes.git;a=commitdiff_plain;h=5192d201a22360e15b9fe6c9e02a8d004315adfa rotate airplane image --- diff --git a/Airplane.pm b/Airplane.pm index 775599c..0b49c85 100644 --- a/Airplane.pm +++ b/Airplane.pm @@ -3,6 +3,8 @@ package Airplane; use warnings; use strict; +use SDL::Tool::Graphic; + sub new { my ( $class, $app ) = @_; my $self = { @@ -22,7 +24,7 @@ sub set_path { $self->{tick} = $self->{app}->ticks + $self->{speed}; } -our $plane = SDL::Surface->new( -name => 'artwork/airplane.png' ); +my $tool = SDL::Tool::Graphic->new; sub draw { my $self = shift; @@ -38,8 +40,21 @@ sub draw { -x => $self->{path}[$pos], -y => $self->{path}[$pos+1], ); - $plane->blit( $plane->rect, $self->{app}, $to ); - warn $pos; +# $plane->blit( $plane->rect, $self->{app}, $to ); + + my $radian = atan2( + $self->{path}[$pos+1] - $self->{path}[$pos+3], + $self->{path}[$pos] - $self->{path}[$pos+2], + ); + my $deg = $radian / 3.1459265 * 180; + + $deg = -$deg + 90; # plain nose at 90 deg. + + my $plane = SDL::Surface->new( -name => 'artwork/airplane.png' ); + my $rotated = $tool->rotoZoom( $plane, $deg, 1, 1 ); + $rotated->blit( $rotated->rect, $self->{app}, $to ); + + warn "$pos $radian $deg ", $rotated->width, ' ', $rotated->height; $self->{tick} = $self->{app}->ticks + $self->{speed}; } }