1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META http-equiv="Content-Style-Type" content="text/css">
6<LINK rel="stylesheet" type="text/css" href="../../CSS/revolution.css">
7<title>KPAD Sample Demo (swing)</title>
8</head>
9
10<body>
11
12<h1>swing</h1>
13
14<h2>Location</h2>
15<p>
16<code>$REVOLUTION_SDK_ROOT/build/demos/kpaddemo</code>
17</p>
18
19<H2>Description</H2>
20<p>
21In this demo, the program recognizes the direction in which the Wii Remote is swung and displays that direction as an arrow on the TV screen.<br><br> <font color="red"><STRONG>Note:</STRONG> Swing the Wii Remote in such a way that its top side (the side with the A Button) remains parallel to the floor. If you tilt the Wii Remote when you swing it, the program will not recognize the correct direction.</font>
22</p>
23
24<h3>Source File Composition</h3>
25<TABLE border="1" cellpadding="3" width="95%">
26  <TBODY>
27    <TR>
28<TD><CODE>swing.c</CODE></TD>
29<TD>This source file contains the algorithm for detecting the direction of swing. It is possible to adjust the &quot;feel&quot; of recognition by editing the values of macro constants defined in this file.</TD>
30    </TR>
31    <TR>
32<TD><CODE>graphic.h</CODE><BR><CODE>graphic.c</CODE></TD>
33<TD>The collection of subroutines for simple graphics drawing.</TD>
34    </TR>
35    <TR>
36<TD><CODE>kfont.h</CODE><BR><CODE>kfont.c</CODE></TD>
37<TD>The collection of subroutines that display text and values on the screen.</TD>
38    </TR>
39  </TBODY>
40</TABLE>
41
42<h3>Explanation of swing.c</h3>
43<ul>
44<li>The <code>dir_nrm</code> variable is continually refreshed with the value of the direction the Wii Remote is swung in (in the KPAD library's acceleration coordinate system). In an application, this is used by referencing <code>dir_nrm</code> the instant that <code>dir_nrm_pass_count</code> exceeds a certain value.
45<li>The length of time until referencing should vary depending on the application. Set it accordingly. Although quick referencing improves response, recognition precision may deteriorate. In the <CODE>swing</CODE> demo, the color of the arrows change from red to yellow to blue with elapsed time.
46<li>The <code>dir_nrm</code> variable is a 3D vector variable, but the <CODE>swing</CODE> demo is specialized for two dimensions and so in this demo Z is always 0.
47</ul>
48
49<p>
50The following table shows simple descriptions of the functions defined in <CODE>swing.c</CODE>.
51</p>
52
53<TABLE border="1" cellpadding="3" width="95%">
54  <TBODY>
55    <TR>
56<TD><code>init_sample()</code></TD>
57<TD>Function that initializes load settings and other settings for KPAD acceleration data</TD>
58    </TR>
59    <TR>
60<TD><code>work_sample()</code></TD>
61<TD>Function that is called once per game frame to perform recognition processing</TD>
62    </TR>
63    <TR>
64<TD><code>draw_sample()</code></TD>
65<TD>This function draws the result of recognition.</TD>
66    </TR>
67  </TBODY>
68</TABLE>
69
70<h3>Note</h3>
71<ul>
72<li>DPD information is not used to recognize the swinging motion.
73<li>(By default,) the Wii Remote parameters are calibrated in such a way that it must be swung with some speed in order for the direction of the swing to be recognized. By increasing the value of the macro constant <code>DIR_VEC_DAMP</code> or decreasing the value of <code>DIR_SPEED_MIN</code>, it is possible to recognize weak swings, but the number of false positives also increases. For your reference, the following table gives example parameter settings for detecting weak swings.
74<TABLE border="1" cellpadding="3" width="90%">
75  <TBODY>
76    <TR>
77<TD><code>DIR_VEC_DAMP</code></TD>
78<TD>0.93f</TD>
79<TD>Speed vector decay rate (0 to 1)</TD>
80    </TR>
81    <TR>
82<TD><code>DIR_SPEED_MIN</code></TD>
83<TD>1.00f</TD>
84<TD>Minimum speed required for recognition</TD>
85    </TR>
86    <TR>
87<TD><code>DIR_SPEED_DAMP</code></TD>
88<TD>0.99f</TD>
89<TD>Speed recording decay rate (0 to 1)</TD>
90    </TR>
91  </TBODY>
92</TABLE>
93<li>If you wish to improve recognition accuracy, try increasing the value of the macro constant <code>DIR_SPEED_DAMP</code>. Note, however, that the time from one recognition to the next increases.
94</ul>
95
96
97<h2>See Also</h2>
98<P>None.</P>
99
100<H2>Revision History</H2>
101<P>
1022007/04/11 Used red letters to emphasize the note giving conditions for correct recognition.<br>2007/03/05 Included example parameter settings for detecting weak swings.<br> 2007/03/02 Initial version.<br>
103</P>
104
105<hr><p>CONFIDENTIAL</p></body>
106</html>
107