.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "pods::SDLx::Controller::Interface 3pm" .TH pods::SDLx::Controller::Interface 3pm 2024-01-10 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME SDLx::Controller::Interface \- Interface Physics and Rendering with the Controller with callbacks .SH CATEGORY .IX Header "CATEGORY" Extension, Controller .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 3 \& use SDL; \& use SDLx::App; \& use SDLx::Controller::Interface; \& \& #SDLx::App is a controller \& my $app = SDLx::App\->new(width => 200, height => 200 ); \& \& my $ball = SDLx::Controller::Interface\->new( x=> 10, y => 50, v_x => 10, v_y=> 20 ); \& #Set the initial state of the ball\*(Aqs physics, this is optional \& \& $ball\->set_acceleration( \& sub { \& my ($time, $current_state) = @_; \& return( 0, \-10, 0 ); # Return accelerations (x,y,rotation) \& } \& ); \& \& my $ball_render = sub { \& my $state = shift; \& \& $app\->draw_rect( undef, 0 ); \& $app\->draw_rect( [$state\->x, $state\->y, 10,10], [255,0,0,255] ); \& $app\->update(); \& }; \& \& \& $ball\->attach( $app, $ball_render, @params ); \& \& $app\->run(); \& \& $ball\->detach(); #can be called at anytime (for example when ball \*(Aqdies\*(Aq) .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" .SH METHODS .IX Header "METHODS" .SS set_acceleration .IX Subsection "set_acceleration" Allows you to set the acceleration callback for defining the interface's behaviour in terms of x,y and rotation. .PP .Vb 3 \& $interface\->set_acceleration ( \& sub { \& my ($time, $current_state) = @_; \& \& return ( $accel_x, $accel_y, $torque ); \& } \& ); .Ve .PP These accelerations are arbitrary and can be set to any frame of reference. Your render callback will handle how to interpret it. .PP The callback will receive the time and the current state as a \&\f(CW\*(C`SDLx::Controller::State\*(C'\fR element. .SS attach .IX Subsection "attach" Attaches the interface to a controller with a render callback .PP .Vb 1 \& $interface\->attach( $controller, $render, @params ); .Ve .PP Where \f(CW$render\fR is a callback that receives the interpolated \&\f(CW\*(C`SDLx::Controller::State\*(C'\fR. .PP .Vb 4 \& my $render = sub { \& my ($state, @params) = @_; \& # draw the current $state. \& }; .Ve .PP The \f(CW@params\fR are any extra parameters you would like to pass to the \f(CW$render\fR callback. .SS current .IX Subsection "current" .Vb 1 \& my $current_state = $interface\->current(); .Ve .PP Returns the current state of the interface as a \f(CW\*(C`SDLx::Controller::State\*(C'\fR. .SS previous .IX Subsection "previous" .Vb 1 \& my $previous_state = $interface\->previous(); .Ve .PP Returns the previous state of the interface as a \f(CW\*(C`SDLx::Controller::State\*(C'\fR. .SS detach .IX Subsection "detach" .Vb 1 \& $interface\->detach(); .Ve .PP If \f(CW$interface\fR has been \f(CWattach()\fR'ed to any controller it will be detached now. .SH "OTHER METHODS" .IX Header "OTHER METHODS" Don't use these unless you really really want to. .SS acceleration .IX Subsection "acceleration" Call the acceleration callback once. .SS interpolate .IX Subsection "interpolate" Interpolate the current state .SS evaluate .IX Subsection "evaluate" Evaluate the new current and previous state. .SS update .IX Subsection "update" Update the states by integrating with time. .SH AUTHORS .IX Header "AUTHORS" See "AUTHORS" in SDL.