3 <h3 id="TOP">Index</h3>
5 <ul><li><a href="#NAME">NAME</a></li>
6 <li><a href="#CATEGORY">CATEGORY</a></li>
7 <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8 <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
9 <li><a href="#METHODS">METHODS</a>
10 <ul><li><a href="#set_acceleration">set_acceleration</a></li>
11 <li><a href="#attach">attach</a></li>
12 <li><a href="#current">current</a></li>
13 <li><a href="#previous">previous</a></li>
14 <li><a href="#detach">detach</a></li>
17 <li><a href="#OTHER_METHODS">OTHER METHODS</a>
18 <ul><li><a href="#acceleration">acceleration</a></li>
19 <li><a href="#interpolate">interpolate</a></li>
20 <li><a href="#evaluate">evaluate</a></li>
21 <li><a href="#update">update</a></li>
24 <li><a href="#AUTHORS">AUTHORS</a>
29 <h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
30 <div id="NAME_CONTENT">
31 <p>SDLx::Controller::Interface - Interface Physics and Rendering with the Controller with callbacks</p>
34 <h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
35 <div id="CATEGORY_CONTENT">
36 <p>Extension, Controller</p>
39 <h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
40 <div id="SYNOPSIS_CONTENT">
43 use SDLx::Controller::Interface;
45 #SDLx::App is a controller
46 my $app = SDLx::App->new(width => 200, height => 200 );
48 my $ball = SDLx::Controller::Interface->new( x=> 10, y => 50, v_x => 10, v_y=> 20 );
49 #Set the initial state of the ball's physics, this is optional
51 $ball->set_acceleration(
53 my ($time, $current_state) = @_;
54 return( 0, -10, 0 ); # Return accelerations (x,y,rotation)
58 my $ball_render = sub {
61 $app->draw_rect( undef, 0 );
62 $app->draw_rect( [$state->x, $state->y, 10,10], [255,0,0,255] );
69 $ball->attach( $app, $ball_render, @params );
73 $ball->detach(); #can be called at anytime (for example when ball 'dies')
78 <h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
79 <div id="DESCRIPTION_CONTENT">
82 <h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
83 <div id="METHODS_CONTENT">
86 <h2 id="set_acceleration">set_acceleration</h2>
87 <div id="set_acceleration_CONTENT">
88 <p>Allows you to set the acceleration callback for defining the inferface's
89 behaviour in terms of x,y and rotation.</p>
90 <pre> $interface->set_acceleration (
92 my ($time, $current_state) = @_;
94 return ( $accel_x, $accel_y, $torque );
99 <p>These accelerations are arbitary and can be set to any frame of reference.
100 Your render callback will handle how to interpret it.</p>
101 <p>The callback will receive the time and the current state as a
102 <code>SDLx::Controller::State</code> element.</p>
105 <h2 id="attach">attach</h2>
106 <div id="attach_CONTENT">
107 <p>Attaches the interface to a controller with a render callback</p>
108 <pre> $interface->attach( $controller, $render, @params );
111 <p>Where $render is a callback that receives the interpolated
112 <code>SDLx::Controller::State</code>.</p>
113 <pre> my $render = sub {
114 my ($state, @params) = @_;
115 # draw the current $state.
119 <p>The @params are any extra parameters you would like to pass to the $render
123 <h2 id="current">current</h2>
124 <div id="current_CONTENT">
125 <pre> my $current_state = $interface->current();
128 <p>Returns the current state of the interface as a <code>SDLx::Controller::State</code>.</p>
131 <h2 id="previous">previous</h2>
132 <div id="previous_CONTENT">
133 <pre> my $previous_state = $interface->previous();
136 <p>Returns the previous state of the interface as a <code>SDLx::Controller::State</code>.</p>
139 <h2 id="detach">detach</h2>
140 <div id="detach_CONTENT">
141 <pre> $interface->detach();
144 <p>If $interface has been <code>attach()</code>'ed to any controller it will be detached now.</p>
147 <h1 id="OTHER_METHODS">OTHER METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
148 <div id="OTHER_METHODS_CONTENT">
149 <p>Don't use these unless you really really want to.</p>
152 <h2 id="acceleration">acceleration</h2>
153 <div id="acceleration_CONTENT">
154 <p>Call the acceleration callback once.</p>
157 <h2 id="interpolate">interpolate</h2>
158 <div id="interpolate_CONTENT">
159 <p>Interpolate the current state</p>
162 <h2 id="evaluate">evaluate</h2>
163 <div id="evaluate_CONTENT">
164 <p>Evaluate the new currrent and previous state.</p>
167 <h2 id="update">update</h2>
168 <div id="update_CONTENT">
169 <p>Update the states by integrating with time.</p>
172 <h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
173 <div id="AUTHORS_CONTENT">
174 <p>See <a href="/SDL.html#AUTHORS">/SDL.html#AUTHORS</a>.</p>