none
Kinect Speech control 3D object rotate over time RRS feed

  • Question

  • Hello, I want to let the 3D object rotate over time when I say "Turn Left", my code is like this

            this.Dispatcher.Invoke(DispatcherPriority.Send, new Action<int>(this.HandleGameTimer), 0);
                }
            }
    
            private void HandleGameTimer(int param)
            {
                //3dObjectRotate.Angle += 1; (Uncomment this is the effect that I want, but I want control it by voice)
            }
    
            private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
            {
                switch (e.Verb)
                {
                    case SpeechRecognizer.Verbs.TurnLeft:
                        3dObjectlRotate.Angle += 1;
                        if (3dObjectRotate.Angle > 360) { this.3dObjectRotate.Angle -= 360; }
                        break;
                }
            }

    Now if I say "turn left", it only rotates 1 degree. How can I call the "HandleGameTimer" function in the "RecognizerSaidSomething" function or what to let the "3dObject" rotate overtime until I let it stop?

    Thanks very much!







    • Edited by Supreme0319 Sunday, September 1, 2013 7:22 AM
    Sunday, September 1, 2013 6:49 AM

Answers

  •         enum ROTATE_ACTION {NONE, LEFT, RIGHT, ...};
            ROTATE_ACTION m_action = NONE;
    
            private void HandleGameTimer(int param)
            {
                //3dObjectRotate.Angle += 1; (Uncomment this is the effect that I want, but I want control it by voice)
    
                switch (m_action)
                {
                    case LEFT:
                        3dObjectlRotate.Angle += 1;
                        break;
                    case RIGHT:
                        3dObjectlRotate.Angle -= 1;
                        break;
                }
    
                if (3dObjectlRotate.Angle < -360 || 3dObjectlRotate.Angle > 360)
                    3dObjectlRotate.Angle = 3dObjectlRotate.Angle % 360;
            }
    
            private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
            {
                switch (e.Verb)
                {
                    case SpeechRecognizer.Verbs.TurnLeft:
                        m_action = LEFT;
                        break;
                    case SpeechRecognizer.Verbs.TurnRight:
                        m_action = RIGHT;
                        break;
                    case SpeechRecognizer.Verbs.Stop:
                        m_action = NONE;
                        break;
                }
            }

    Hi, I'm not very familiar with C#, but I think I can still give you some hint. What you want is actually a kinda state machine. The game timer is the driving source and the voice recognizing method is the state changer.
    Monday, September 2, 2013 5:23 AM