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 program (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 the Wii Remote has been waved and displays the direction on the TV screen using an arrow.<br> <br> <font color="red"><B>Note: </B>Be sure to swing the Wii Remote so that its top surface (the side where A Button and others are located) remains parallel with the floor. The correct direction will not be recognized if the Wii Remote is swung at a tilted angle.</font>
22</p>
23
24<h3>Source File Organization</h3>
25<TABLE border="1" cellpadding="3" cellspacing="0.1">
26  <TBODY>
27    <TR>
28      <TD>swing.c</TD>
29      <TD>This source file contains the algorithm for detecting the direction of swing. It is possible to adjust the feel of recognition by editing the values of macro constants defined in this file.</TD>
30    </TR>
31    <TR>
32      <TD><code>graphic.h</code>, <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>, <code>kfont.c</code></TD>
37      <TD>The collection of subroutines that displays text and numerals onscreen.</TD>
38    </TR>
39  </TBODY>
40</TABLE>
41
42<h3>Description of swing.c</h3>
43<ul>
44<li>The <code>dir_nrm</code> variable is constantly updated to the value (in the acceleration coordinate system of the KPAD library) associated with the direction the Wii Remote is being swung. Applications can use this code to access <code>dir_nrm</code> at the instant <code>dir_nrm_pass_count</code> goes beyond a certain value.
45<li>Set the length of time until access depending on the application. Although quick access improves response, recognition precision may deteriorate. With the swing demo, the color of the arrow changes from red to yellow to blue depending on the time that has elapsed.
46<li><code>dir_nrm</code> is a 3D vector variable, where Z is constantly held at 0, because the swing demo is especially designed for 2D.
47</ul>
48
49<p>
50The following table gives a simple description of the functions defined in swing.c.
51</p>
52
53<TABLE border="1" cellpadding="3" cellspacing="0.1">
54  <TBODY>
55    <TR>
56      <TD><code>init_sample()</code></TD>
57      <TD>This function initializes settings for loading KPAD acceleration data.</TD>
58    </TR>
59    <TR>
60      <TD><code>work_sample()</code></TD>
61      <TD>This function is called once per frame to perform recognition.</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<p>
72<ul>
73<li>DPD information is not used during swing detection.
74<li>By default, parameters are adjusted so that the swing direction is not recognized unless the Wii Remote is swung with ample force. Although it is possible to make it recognize weak swings by increasing the value of the macro constant <code>DIR_VEC_DAMP</code> or reducing the value of <code>DIR_SPEED_MIN</code>, cases of misrecognition will increase. For your reference, the following table gives example parameter settings for detecting weak swings.
75<TABLE border="1" cellpadding="3" cellspacing="0.1">
76  <TBODY>
77    <TR>
78      <TD><code>DIR_VEC_DAMP</code></TD>
79      <TD>0.93f</TD>
80      <TD>Speed vector decay rate (0 to 1)</TD>
81    </TR>
82    <TR>
83      <TD><code>DIR_SPEED_MIN</code></TD>
84      <TD>1.00f</TD>
85      <TD>Minimum speed required for recognition</TD>
86    </TR>
87    <TR>
88      <TD><code>DIR_SPEED_DAMP</code></TD>
89      <TD>0.99f</TD>
90      <TD>Speed recording decay rate (0 to 1)</TD>
91    </TR>
92  </TBODY>
93</TABLE>
94<li>To improve the accuracy of recognition, look into increasing the value of the macro constant <code>DIR_SPEED_DAMP</code>. Note, however, that the time from one recognition to the next increases.
95</ul>
96</p>
97
98<h2>See Also</h2>
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>
106<P>CONFIDENTIAL</p>
107</BODY>
108</HTML>
109