Updated to 2.515
[sdlgit/SDL-Site.git] / pages / SDLx-Controller-Interface.html-inc
diff --git a/pages/SDLx-Controller-Interface.html-inc b/pages/SDLx-Controller-Interface.html-inc
new file mode 100644 (file)
index 0000000..160e069
--- /dev/null
@@ -0,0 +1,177 @@
+<div class="pod">
+<!-- INDEX START -->
+<h3 id="TOP">Index</h3>
+
+<ul><li><a href="#NAME">NAME</a></li>
+<li><a href="#CATEGORY">CATEGORY</a></li>
+<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
+<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
+<li><a href="#METHODS">METHODS</a>
+<ul><li><a href="#set_acceleration">set_acceleration</a></li>
+<li><a href="#attach">attach</a></li>
+<li><a href="#current">current</a></li>
+<li><a href="#previous">previous</a></li>
+<li><a href="#detach">detach</a></li>
+</ul>
+</li>
+<li><a href="#OTHER_METHODS">OTHER METHODS</a>
+<ul><li><a href="#acceleration">acceleration</a></li>
+<li><a href="#interpolate">interpolate</a></li>
+<li><a href="#evaluate">evaluate</a></li>
+<li><a href="#update">update</a></li>
+</ul>
+</li>
+<li><a href="#AUTHORS">AUTHORS</a>
+</li>
+</ul><hr />
+<!-- INDEX END -->
+
+<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="NAME_CONTENT">
+<p>SDLx::Controller::Interface - Interface Physics and Rendering with the Controller with callbacks</p>
+
+</div>
+<h1 id="CATEGORY">CATEGORY</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="CATEGORY_CONTENT">
+<p>Core, Extension</p>
+
+</div>
+<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="SYNOPSIS_CONTENT">
+<pre> use SDL;
+ use SDLx::App;
+ use SDLx::Controller::Interface;
+
+ #SDLx::App is a controller
+ my $app = SDLx::App-&gt;new(width =&gt; 200, height =&gt; 200 ); 
+
+ my $ball = SDLx::Controller::Interface-&gt;new( x=&gt; 10, y =&gt; 50, v_x =&gt; 10, v_y=&gt; 20 );
+ #Set the initial state of the ball's physics, this is optional
+
+ $ball-&gt;set_acceleration( 
+    sub { 
+              my ($time, $current_state) = @_;
+              return( 0, -10, 0 ); # Return accelerations (x,y,rotation)
+        }
+ );
+
+ my $ball_render = sub {
+       my $state = shift;
+
+       $app-&gt;draw_rect( undef, 0 );
+       $app-&gt;draw_rect( [$state-&gt;x, $state-&gt;y, 10,10], [255,0,0,255] );
+       $app-&gt;update();
+ };
+
+
+
+
+ $ball-&gt;attach( $app, $ball_render, @params ); 
+
+ $app-&gt;run();
+
+ $ball-&gt;detach(); #can be called at anytime (for example when ball 'dies')
+
+</pre>
+
+</div>
+<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="DESCRIPTION_CONTENT">
+
+</div>
+<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="METHODS_CONTENT">
+
+</div>
+<h2 id="set_acceleration">set_acceleration</h2>
+<div id="set_acceleration_CONTENT">
+<p>Allows you to set the acceleration callback for defining the inferface's
+behaviour in terms of x,y and rotation.</p>
+<pre>  $interface-&gt;set_acceleration ( 
+      sub {
+         my ($time, $current_state) = @_; 
+
+         return ( $accel_x, $accel_y, $torque );
+      }
+  );
+
+</pre>
+<p>These accelerations are arbitary and can be set to any frame of reference.
+Your render callback will handle how to interpret it.</p>
+<p>The callback will receive the time and the current state as a
+<code>SDLx::Controller::State</code> element.</p>
+
+</div>
+<h2 id="attach">attach</h2>
+<div id="attach_CONTENT">
+<p>Attaches the interface to a controller with a render callback</p>
+<pre>  $interface-&gt;attach( $controller, $render, @params );
+
+</pre>
+<p>Where $render is a callback that receives the interpolated
+<code>SDLx::Controller::State</code>.</p>
+<pre>  my $render = sub {
+        my ($state, @params) = @_; 
+        # draw the current $state.
+  };
+
+</pre>
+<p>The @params are any extra parameters you would like to pass to the $render
+callback.</p>
+
+</div>
+<h2 id="current">current</h2>
+<div id="current_CONTENT">
+<pre>  my $current_state = $interface-&gt;current();
+
+</pre>
+<p>Returns the current state of the interface as a <code>SDLx::Controller::State</code>.</p>
+
+</div>
+<h2 id="previous">previous</h2>
+<div id="previous_CONTENT">
+<pre>  my $previous_state = $interface-&gt;previous();
+
+</pre>
+<p>Returns the previous state of the interface as a <code>SDLx::Controller::State</code>.</p>
+
+</div>
+<h2 id="detach">detach</h2>
+<div id="detach_CONTENT">
+<pre>  $interface-&gt;detach();
+
+</pre>
+<p>If $interface has been <code>attach()</code>'ed to any controller it will be detached now.</p>
+
+</div>
+<h1 id="OTHER_METHODS">OTHER METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="OTHER_METHODS_CONTENT">
+<p>Don't use these unless you really really want to.</p>
+
+</div>
+<h2 id="acceleration">acceleration</h2>
+<div id="acceleration_CONTENT">
+<p>Call the acceleration callback once.</p>
+
+</div>
+<h2 id="interpolate">interpolate</h2>
+<div id="interpolate_CONTENT">
+<p>Interpolate the current state</p>
+
+</div>
+<h2 id="evaluate">evaluate</h2>
+<div id="evaluate_CONTENT">
+<p>Evaluate the new currrent and previous state.</p>
+
+</div>
+<h2 id="update">update</h2>
+<div id="update_CONTENT">
+<p>Update the states by integrating with time.</p>
+
+</div>
+<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
+<div id="AUTHORS_CONTENT">
+<p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
+
+</div>
+</div>
\ No newline at end of file