[WiiFlash] - Fluent square gesture.

Andreas D'Hollandere andreasdhollandere at gmail.com
Tue Jun 1 05:12:29 PDT 2010


Dear,


I've got a small question for the wiiflash community.
Is there anyone who knows how to build a fluent square gesture with 
wiiflash and the wiiremote.
I've been writing a gesture detection class which can track the seperate 
movements, but not a fluent gesture.

This is the code I have now:

         public function addValues( x:Number, y:Number, z:Number ):void{

             // basic check for motion
             if( Math.sqrt( x*x + y*y + z*z 
)<GestureDetection.MOTION_THERSHOLD ){
                 this._isInMotion = false;
                 _eventDispatcher.dispatchEvent( new 
GestureDetectEvent(GestureDetectEvent.IDLE));
                 return;
             }

             this._isInMotion = true;

             var xPeak:Number = _xPeakDetection.addValue( x );
             //var yPeak:Number = _yPeakDetection.addValue( y );
             var zPeak:Number = _zPeakDetection.addValue( z );


             // right down
             if( xPeak<0 && zPeak<0){
                 _hasXNegPeak = true;
                 _hasZNegPeak = true;
                 //_hasZPosPeak = true;
                 if( _hasXNegPeak && !_inMotion && _hasZNegPeak){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.RIGHT_DOWN ) );

                     points[motions] = "right_down";
                     motions++;
                 }
                 _peakSeperationTimer.start();

             }

             // right up
             if( xPeak<0 && zPeak>0){
                 _hasXNegPeak = true;
                 _hasZPosPeak = true;
                 if( _hasXNegPeak && !_inMotion && _hasZPosPeak){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.RIGHT_UP ) );

                     points[motions] = "right_up";
                     motions++;
                 }
                 _peakSeperationTimer.start();

             }

             // left down
             if( xPeak>0 && zPeak<0){
                 _hasXPosPeak = true;
                 _hasZNegPeak = true;
                 //_hasZPosPeak = true;
                 if( _hasXPosPeak && !_inMotion && _hasZNegPeak){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.LEFT_DOWN ) );

                     points[motions] = "left_down";
                     motions++;
                 }
                 _peakSeperationTimer.start();
             }

             // left up
             if( xPeak>0 && zPeak>0){
                 _hasXPosPeak = true;
                 _hasZPosPeak = true;
                 //_hasZPosPeak = true;
                 if( _hasXPosPeak && !_inMotion && _hasZPosPeak){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.LEFT_UP ) );

                     points[motions] = "left_up";
                     motions++;
                 }
                 _peakSeperationTimer.start();

             }

             // handle left
             if( xPeak>0 ){
                 _hasXPosPeak = true;
                 if( _hasXPosPeak && !_inMotion){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.LEFT ) );

                     points[motions] = "left";
                     motions++;
                 }
                 _peakSeperationTimer.start();

             }

             // handle right
             if( xPeak<0 ){
                 _hasXNegPeak = true;
                 if( _hasXNegPeak && !_inMotion ){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.RIGHT ) );

                     points[motions] = "right";
                     motions++;
                 }
                 _peakSeperationTimer.start();

             }

             // handle up
             if( zPeak>0 ){
                 _hasZPosPeak = true;
                 if( _hasZPosPeak && !_inMotion ){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.UP ) );

                     points[motions] = "up";
                     motions++;
                 }
                 _peakSeperationTimer.start();

             }

             // handle down
             if( zPeak<0 ){
                 _hasZNegPeak = true;
                 if( _hasZNegPeak && !_inMotion ){
                     _inMotion = true;
                     _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.DOWN ) );

                     points[motions] = "down";
                     motions++;

                 }
                 _peakSeperationTimer.start();

             }

             if(points.length == 3 && points[0]=="right_up" && 
points[1]=="right_down" && points[2]=="left")
             {
                 for(var i:int = 0; i < points.length; i++)
                 {
                 trace(points[i]);
                 }
                     if(points[0]=="right_up" && points[1]=="right_down" 
&& points[2]=="left")
                     {
                         _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.DRIEHOEK ) );
                         points = [];
                         motions = 0;
                     }else
                     {
                         trace('try again');
                         trace(points.length);
                         points = [];
                         motions = 0;
                         trace(points.length);
                     }
             }
             if(points.length == 4)
             {
                 for(var j:int = 0; j < points.length; j++)
                 {
                 trace(points[j]);
                 }
                     if(points[0]=="right" && points[1]=="up" && 
points[2]=="left" && points[3]=="down")
                     {
                         _eventDispatcher.dispatchEvent( new 
GestureDetectEvent( GestureDetectEvent.VIERKANT ) );
                         points = [];
                         motions = 0;
                     }else
                     {
                         trace('try again');
                         trace(points.length);
                         points = [];
                         motions = 0;
                         trace(points.length);
                     }
             }
         }


Thanks in advance
Andreas



More information about the WiiFlash mailing list