void UpdatePoses (ThalmicMyo thalmicMyo) {
		if (thalmicMyo.pose != _lastPose && thalmicMyo.pose != Pose.Unknown) {
			
			_lastPose = thalmicMyo.pose;
			
			if (thalmicMyo.pose == Pose.Rest) {
				return;
			}
			
			// Give feedback
			//thalmicMyo.Vibrate (VibrationType.Short);
			
			if (thalmicMyo.pose == Pose.Fist) {
				print("Fist detected");
				
			} else if (thalmicMyo.pose == Pose.WaveIn) {
				if (thalmicMyo.arm == Thalmic.Myo.Arm.Left) {
					print("Wave RIGHT detected (left arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					CM.Reverse ();
					
				} else if (thalmicMyo.arm == Thalmic.Myo.Arm.Right) {
					print("Wave LEFT detected (right arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					CM.Advance ();
				}
				
			} else if (thalmicMyo.pose == Pose.WaveOut) {
				if (thalmicMyo.arm == Thalmic.Myo.Arm.Left) {
					print("Wave LEFT detected (left arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					CM.Advance ();
					
				} else if (thalmicMyo.arm == Thalmic.Myo.Arm.Right) {
					print("Wave RIGHT detected (right arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					CM.Reverse ();
				}
				
			} else if (thalmicMyo.pose == Pose.ThumbToPinky) {
				print("Thumb to Pinky detected");
				
			} else if (thalmicMyo.pose == Pose.FingersSpread) {
				print("Fingers Spread detected");

			}
		}
	}
Example #2
0
 // Update is called once per frame
 void Update()
 {
     thalmicMyo = myo.GetComponent<ThalmicMyo>();
     if (split.splitted)
     {
         Debug.Log("splitted");
         thalmicMyo.Vibrate(VibrationType.Long);
         vib.vibe = true;
     }
 }
Example #3
0
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                //renderer.material = waveInMaterial;
                Debug.Log("WaveIn");

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                //renderer.material = waveOutMaterial;
                Debug.Log("WaveOut");


                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                //renderer.material = doubleTapMaterial;
                Debug.Log("DoubleTap");
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }
    }
Example #4
0
    float Myo_Normal_High = 0;     // (low value here)

    // Use this for initialization
    void Start()
    {
        GameObject Myo_go = GameObject.Find("Myo1");

        Myo_script = Myo_go.GetComponent <ThalmicMyo>();

        if (Myo_script)
        {
            if (Myo_script.isPaired)
            {
                Myo_Paired = true;
                Myo_script.Vibrate(Thalmic.Myo.VibrationType.Short);
            }
        }

        MyoForceData_Player1 = GameObject.Find("MyoForceData_Player1");
    }
    //private InputMapping;
    // Use this for initialization
    void Start()
    {
        hub = ThalmicHub.instance;
        //myo = GameObject.FindGameObjectWithTag("Player");
        if (myo == null) {
            myo = this.gameObject;
        }

        // Access the ThalmicMyo script attached to the Myo object.
        thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        if (thalmicMyo.isPaired) {
            thalmicMyo.Vibrate(Thalmic.Myo.VibrationType.Short);
        }
        Debug.Log (thalmicMyo);
        Debug.Log (myo);
    }
Example #6
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log("it works");
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();
        Vector3    zeroRoll   = computeZeroRollVector(myo.transform.forward);
        float      roll       = rollFromZero(zeroRoll, myo.transform.forward, myo.transform.up);

        if ((Time.time % bps < 0.5) && !(roll < 0))
        {
            sprit.enabled = true;
            thalmicMyo.Vibrate(VibrationType.Medium);
        }
        else
        {
            sprit.enabled = false;
        }
    }
Example #7
0
    // Update is called once per frame.
    void Update()
    {
        // First we take care up updating the position of the origin in case the player moved
        if (hasPinned)
        {
            offset = this.transform.position - origin;
        }

        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose   = thalmicMyo.pose;
            rotateLeft  = false;
            rotateRight = false;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                rotateLeft = true;
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                rotateRight = true;
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }
    }
Example #8
0
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);
                renderer.material = fistMaterial;

                // Change material when wave in, wave out or twist in poses are made.
            }
            else if (thalmicMyo.pose == Pose.Rest)
            {
                renderer.material = restMaterial;
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                renderer.material = waveInMaterial;
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                renderer.material = waveOutMaterial;
            }
            else if (thalmicMyo.pose == Pose.TwistIn)
            {
                renderer.material = twistInMaterial;
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                renderer.material = fingersspreadMaterial;
            }
        }
    }
Example #9
0
    private void OnTriggerStay(Collider other)
    {
        if (other.tag == "Ground")
        {
            // Access the ThalmicMyo component attached to the Myo game object.
            ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

            if (thalmicMyo.pose != _lastPose)
            {
                _lastPose = thalmicMyo.pose;

                if (thalmicMyo.pose == Pose.Fist)
                {
                    thalmicMyo.Vibrate(VibrationType.Medium);
                    //recuperez point de contact
                    Vector3 positionTP = other.ClosestPointOnBounds(transform.position);
                    //dash
                    fd.DoDashWithTranslation(positionTP);
                }
            }
        }
    }
Example #10
0
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose) {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist) {
                thalmicMyo.Vibrate (VibrationType.Medium);

                ExtendUnlockAndNotifyUserAction (thalmicMyo);

            // Change material when wave in, wave out or double tap poses are made.
            } else if (thalmicMyo.pose == Pose.WaveIn) {
                GetComponent<Renderer>().material = waveInMaterial;

                GameObject arms = GameObject.FindGameObjectWithTag("ARMS");
                Instantiate (arms);

                ExtendUnlockAndNotifyUserAction (thalmicMyo);
            } else if (thalmicMyo.pose == Pose.WaveOut) {
                GetComponent<Renderer>().material = waveOutMaterial;

                ExtendUnlockAndNotifyUserAction (thalmicMyo);
            } else if (thalmicMyo.pose == Pose.DoubleTap) {
                GetComponent<Renderer>().material = doubleTapMaterial;

                ExtendUnlockAndNotifyUserAction (thalmicMyo);
            }
        }
    }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);

                //GameObject.Find("Directional light (1)").GetComponent("Light") = GameObject.Find("Directional light (1)").GetComponent("Light").ena
                //Light l = GameObject.Find("Directional light (1)").GetComponent("Light");
                mylight.enabled = !mylight.enabled;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
            }
        }
    }
    void FixedUpdate()
    {
        //Myo rotation logic
        //float myoRotX = myo.transform.localRotation.eulerAngles.x;
        //float myoRotY = myo.transform.localRotation.eulerAngles.y;

        // Move closer to Destination
        Vector2 p = Vector2.MoveTowards(transform.position, dest, speed);

        GetComponent <Rigidbody2D>().MovePosition(p);

        ThalmicMyo thalmicMyo = myoGameObject.GetComponent <ThalmicMyo>();


        // Check for Input if not moving
        if ((Vector2)transform.position == dest)
        {
            if (thalmicMyo.pose != _lastPose)
            {
                _lastPose = thalmicMyo.pose;

                // Vibrate the Myo armband when a fist is made.
                if (thalmicMyo.pose == Pose.WaveOut)
                {
                    thalmicMyo.Vibrate(VibrationType.Short);
                    new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.RIGHT);// Movement handled by the event system mapped with the MYO
                    ExtendUnlockAndNotifyUserAction(thalmicMyo);
                }
                if (thalmicMyo.pose == Pose.WaveIn)
                {
                    thalmicMyo.Vibrate(VibrationType.Short);
                    new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.LEFT);// Movement handled by the event system mapped with the MYO
                    ExtendUnlockAndNotifyUserAction(thalmicMyo);
                }

                //if (myoGameObject.transform.rotation.z > 60)
                if (thalmicMyo.pose == Pose.Fist)
                {
                    thalmicMyo.Vibrate(VibrationType.Short);
                    new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.UP);// Movement handled by the event system mapped with the MYO
                    ExtendUnlockAndNotifyUserAction(thalmicMyo);
                }
                //if (myoGameObject.transform.rotation.z < 20)
                if (thalmicMyo.pose == Pose.FingersSpread)
                {
                    thalmicMyo.Vibrate(VibrationType.Short);
                    new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.DOWN);// Movement handled by the event system mapped with the MYO
                    ExtendUnlockAndNotifyUserAction(thalmicMyo);
                }
            }
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            dest = (Vector2)transform.position + Vector2.up;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            dest = (Vector2)transform.position + Vector2.right;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            dest = (Vector2)transform.position - Vector2.up;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            dest = (Vector2)transform.position - Vector2.right;
        }

        // Animation Parameters
        Vector2 dir = dest - (Vector2)transform.position;

        GetComponent <Animator>().SetFloat("DirX", dir.x);
        GetComponent <Animator>().SetFloat("DirY", dir.y);
    }
    // Update is called once per frame
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            if ((GameObject.Find("FPSController").transform.position.x >= -1.5) && (GameObject.Find("FPSController").transform.position.x <= 0))
            {
                if ((GameObject.Find("FPSController").transform.position.z <= 0) && (GameObject.Find("FPSController").transform.position.z >= -1))
                {
                    //if ((GameObject.Find("FPSController").transform.position.z >= -90))
                    //{
                    _lastPose = thalmicMyo.pose;

                    // Vibrate the Myo armband when a fist is made.
                    if (thalmicMyo.pose == Pose.Fist)
                    {
                        thalmicMyo.Vibrate(VibrationType.Medium);

                        //float translation = speed;
                        //translation *= Time.deltaTime;
                        //transform.Translate(translation, 0,0 );

                        Vector3 movement = new Vector3(-30f, 0.0f, 0.0f);

                        rb.AddForce(movement * speed);

                        ExtendUnlockAndNotifyUserAction(thalmicMyo);

                        // Change material when wave in, wave out or double tap poses are made.
                    }
                    //else if (thalmicMyo.pose == Pose.WaveIn)
                    //{
                    //GetComponent<Renderer>().material = waveInMaterial;

                    //Vector3 movement = new Vector3(10f, 0.0f, 0.0f);

                    //rb.AddForce(movement * speed);

                    //float translation = speed;
                    //translation *= Time.deltaTime;
                    //transform.Translate(0, 0, translation);

                    //ExtendUnlockAndNotifyUserAction(thalmicMyo);
                    //}
                    //else if (thalmicMyo.pose == Pose.WaveOut)
                    //{
                    //GetComponent<Renderer>().material = waveOutMaterial;

                    //Vector3 movement = new Vector3(-10f, 0.0f, 0.0f);

                    //rb.AddForce(movement * speed);

                    //float translation = speed;
                    //translation *= Time.deltaTime;
                    //transform.Translate(0, 0, (-1 * translation));

                    //ExtendUnlockAndNotifyUserAction(thalmicMyo);
                    //}
                    //else if (thalmicMyo.pose == Pose.DoubleTap)
                    //{
                    //GetComponent<Renderer>().material = doubleTapMaterial;

                    // ExtendUnlockAndNotifyUserAction(thalmicMyo);
                    //}
                    //}
                }
            }
        }
    }
Example #14
0
    void Update()
    {
        if (testMode)
        {
            if (Input.GetKey(up) && transform.position.y < boundarytop)
            {
                transform.Translate(Vector3.up * Time.deltaTime * speed);
            }
            //down is positive
            else if (Input.GetKey(down) && transform.position.y > boundarybot)
            {
                transform.Translate(Vector3.down * Time.deltaTime * speed);
            }
            if (Input.GetKeyDown(shootButton))
            {
                spawnMissile();
            }
        }
        else
        {
            if (Input.GetKeyDown("r"))
            {
                _antiYaw = Quaternion.FromToRotation(
                    new Vector3(myo.transform.forward.x, 0, myo.transform.forward.z),
                    new Vector3(0, 0, 1)
                    );

                /*
                 * Vector3 referenceZeroRoll = computeZeroRollVector (myo.transform.forward);
                 * _referenceRoll = rollFromZero (referenceZeroRoll, myo.transform.forward, myo.transform.up);
                 */
            }

            Vector3    zeroRoll     = computeZeroRollVector(myo.transform.forward);
            float      roll         = rollFromZero(zeroRoll, myo.transform.forward, myo.transform.up);
            float      relativeRoll = normalizeAngle(roll - _referenceRoll);
            Quaternion antiRoll     = Quaternion.AngleAxis(relativeRoll, myo.transform.forward);
            Quaternion movement     = _antiYaw * antiRoll * Quaternion.LookRotation(myo.transform.forward);

            if (Input.GetKeyDown(inverter))
            {
                inverted = !inverted;
            }
            if (!inverted)
            {
                if (movement.x < movelimitup && transform.position.y < boundarytop)
                {
                    transform.Translate(Vector3.up * Time.deltaTime * speed);
                }
                else if (movement.x > movelimitdown && transform.position.y > boundarybot)
                {
                    transform.Translate(Vector3.down * Time.deltaTime * speed);
                }
            }
            else
            {
                if (movement.x > movelimitdown && transform.position.y < boundarytop)
                {
                    transform.Translate(Vector3.up * Time.deltaTime * speed);
                }
                else if (movement.x < movelimitup && transform.position.y > boundarybot)
                {
                    transform.Translate(Vector3.down * Time.deltaTime * speed);
                }
            }

            ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();
            if (thalmicMyo.pose != lastPose)
            {
                lastPose = thalmicMyo.pose;

                // Vibrate the Myo armband when a fist is made.
                if (thalmicMyo.pose == Pose.Fist)
                {
                    thalmicMyo.Vibrate(VibrationType.Medium);
                    spawnMissile();
                    //ExtendUnlockAndNotifyUserAction (thalmicMyo);
                }
            }
        }
    }
Example #15
0
    // Update is called once per frame
    void Update()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;


            if (thalmicMyo.pose == Pose.WaveOut)
            {
                transform.position += new Vector3(-1, 0, 0);
                if (!ValidMove())
                {
                    transform.position -= new Vector3(-1, 0, 0);
                }
                Debug.Log("WaveIn");

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                transform.position += new Vector3(1, 0, 0);
                if (!ValidMove())
                {
                    transform.position -= new Vector3(1, 0, 0);
                }
                Debug.Log("WaveOut");

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                transform.RotateAround(transform.TransformPoint(rotationPoint), new Vector3(0, 0, 1), 90);
                if (!ValidMove())
                {
                    transform.RotateAround(transform.TransformPoint(rotationPoint), new Vector3(0, 0, 1), -90);
                }
                Debug.Log("DoubleTap");

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }

            // Vibrate the Myo armband when a fist is made.
            else if (thalmicMyo.pose == Pose.Fist)
            {
                transform.position += new Vector3(0, -1, 0);
                if (!ValidMove())
                {
                    transform.position -= new Vector3(0, -1, 0);
                    AddToGrid();
                    CheckForLines();
                    this.enabled = false;
                }
                previousTime = Time.time;
                thalmicMyo.Vibrate(VibrationType.Medium);
                Debug.Log("Fist");
                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
            }
        }
    }
Example #16
0
 public void Vibrate(Thalmic.Myo.VibrationType vibrationType)
 {
     thalmicMyo.Vibrate(vibrationType);
 }
Example #17
0
    void FixedUpdate()
    {
        if (myo == null)
        {
            myo = new GameObject();
        }
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Update references when the pose becomes fingers spread or the q key is pressed.
        bool updateReference = false;

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);
                //rb.AddForce (new Vector3(0, 0, 10) * speed);
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.FingersSpread || Input.GetKeyDown("r"))
            {
                updateReference = true;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }

        // Update references. This anchors the joint on-screen such that it faces forward away
        // from the viewer when the Myo armband is oriented the way it is when these references are taken.
        if (updateReference)
        {
            // _antiYaw represents a rotation of the Myo armband about the Y axis (up) which aligns the forward
            // vector of the rotation with Z = 1 when the wearer's arm is pointing in the reference direction.
            _antiYaw = Quaternion.FromToRotation(
                new Vector3(myo.transform.forward.x, 0, myo.transform.forward.z),
                new Vector3(0, 0, 1)
                );

            // _referenceRoll represents how many degrees the Myo armband is rotated clockwise
            // about its forward axis (when looking down the wearer's arm towards their hand) from the reference zero
            // roll direction. This direction is calculated and explained below. When this reference is
            // taken, the joint will be rotated about its forward axis such that it faces upwards when
            // the roll value matches the reference.
            Vector3 referenceZeroRoll = computeZeroRollVector(myo.transform.forward);
            _referenceRoll = rollFromZero(referenceZeroRoll, myo.transform.forward, myo.transform.up);
        }

        // Current zero roll vector and roll value.
        Vector3 zeroRoll = computeZeroRollVector(myo.transform.forward);
        float   roll     = rollFromZero(zeroRoll, myo.transform.forward, myo.transform.up);

        // The relative roll is simply how much the current roll has changed relative to the reference roll.
        // adjustAngle simply keeps the resultant value within -180 to 180 degrees.
        float relativeRoll = normalizeAngle(roll - _referenceRoll);

        // antiRoll represents a rotation about the myo Armband's forward axis adjusting for reference roll.
        Quaternion antiRoll = Quaternion.AngleAxis(relativeRoll, myo.transform.forward);

        // Here the anti-roll and yaw rotations are applied to the myo Armband's forward direction to yield
        // the orientation of the joint.
        transform.rotation = _antiYaw * antiRoll * Quaternion.LookRotation(myo.transform.forward);

        // The above calculations were done assuming the Myo armbands's +x direction, in its own coordinate system,
        // was facing toward the wearer's elbow. If the Myo armband is worn with its +x direction facing the other way,
        // the rotation needs to be updated to compensate.
        if (thalmicMyo.xDirection == Thalmic.Myo.XDirection.TowardWrist)
        {
            // Mirror the rotation around the XZ plane in Unity's coordinate system (XY plane in Myo's coordinate
            // system). This makes the rotation reflect the arm's orientation, rather than that of the Myo armband.
            transform.rotation = new Quaternion(transform.localRotation.x,
                                                -transform.localRotation.y,
                                                transform.localRotation.z,
                                                -transform.localRotation.w);
        }

        Vector3 rotation = FromQ2(transform.rotation);
        Vector3 movement = getMovementFromRotation(rotation);

        rb.AddForce(movement * speed);
        addToCache(rotation);

        float v = variance(movementCache);

        if (v < threshold)
        {
            addToVariances(v);
        }

        interpretVariances();
    }
Example #18
0
    //private int gesture = 0;
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();



        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                //GetComponent<Renderer> ().material.color = Color.green;
                GetComponent <Renderer> ().transform.position = new Vector3(GetComponent <Renderer>().transform.position.x, GetComponent <Renderer>().transform.position.y, GetComponent <Renderer>().transform.position.z - .2f);
                boxSecondary.transform.position = new Vector3(boxSecondary.transform.position.x, boxSecondary.transform.position.y, GetComponent <Renderer>().transform.position.z - .2f);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                //GetComponent<Renderer> ().material.color = Color.yellow;
                GetComponent <Renderer> ().transform.position = new Vector3(GetComponent <Renderer>().transform.position.x, GetComponent <Renderer>().transform.position.y, GetComponent <Renderer> ().transform.position.z + .2f);
                boxSecondary.transform.position = new Vector3(boxSecondary.transform.position.x, boxSecondary.transform.position.y, GetComponent <Renderer>().transform.position.z + .2f);


                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                //GetComponent<Renderer> ().material = doubleTapMaterial;
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }
        else
        {
            //it's the same pose
            if (thalmicMyo.pose == Pose.WaveIn)
            {
                //GetComponent<Renderer> ().material.color = Color.green;

                GetComponent <Renderer> ().transform.position = new Vector3(GetComponent <Renderer>().transform.position.x, GetComponent <Renderer>().transform.position.y, GetComponent <Renderer> ().transform.position.z - .2f);
                boxSecondary.transform.position = new Vector3(boxSecondary.transform.position.x, boxSecondary.transform.position.y, GetComponent <Renderer>().transform.position.z - .2f);



                ExtendUnlock(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                //GetComponent<Renderer> ().material.color = Color.yellow;
                GetComponent <Renderer> ().transform.position = new Vector3(GetComponent <Renderer>().transform.position.x, GetComponent <Renderer>().transform.position.y, GetComponent <Renderer>().transform.position.z + .2f);
                boxSecondary.transform.position = new Vector3(boxSecondary.transform.position.x, boxSecondary.transform.position.y, GetComponent <Renderer>().transform.position.z + .2f);


                ExtendUnlock(thalmicMyo);
            }
        }
    }
Example #19
0
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (thalmicMyo.pose == Pose.Rest || thalmicMyo.pose == Pose.Fist)
        {
            myoHandIsClosed = thalmicMyo.pose == Pose.Fist;
        }

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            Debug.Log(thalmicMyo.pose);
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Short);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
                //generator.generate();
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                //GetComponent<Renderer>().material = waveInMaterial;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                //GetComponent<Renderer>().material = waveOutMaterial;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                //GetComponent<Renderer>().material = doubleTapMaterial;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }

        // initialize voice to text input on hand rotation
        if (!myoHandIsClosed && Mathf.Abs(jointOrientation.getRelRoll()) > 45)
        {
            if (!currentlyRequesting)
            {
                thalmicMyo.Vibrate(VibrationType.Long);
                Debug.Log("initialize voice to text");
                currentlyRequesting = true;
                generator.launchSpeech();
            }
        }
        else
        {
            currentlyRequesting = false;
        }


        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        List <ulong> knownIds = new List <ulong>(_Bodies.Keys);

        // First delete untracked bodies
        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                BodyData bd = _Bodies[trackingId];
                Destroy(bd.gameObject);
                Destroy(bd.leftPointer);
                if (bd.rightHandObject != null)
                {
                    Destroy(bd.rightHandObject);
                }
                Destroy(bd.rightPointer);
                _Bodies.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                if (!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.Fist)
            {
                // Vibrate the Myo armband when a fist is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // down move
                gm.Move(MoveDirection.Down);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                // Vibrate the Myo armband when a FingersSpread is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // up move
                gm.Move(MoveDirection.Up);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                // Vibrate the Myo armband when a WaveIn is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // left move
                gm.Move(MoveDirection.Left);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                // Vibrate the Myo armband when a WaveOut is made.
                thalmicMyo.Vibrate(VibrationType.Short);
                // right move
                gm.Move(MoveDirection.Right);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                // Vibrate the Myo armband when a DoubleTap is made.
                thalmicMyo.Vibrate(VibrationType.Medium);
                // Restart Game
                // disable current hub,
                ThalmicHub hub = ThalmicHub.instance;
                DestroyImmediate(hub);
                gm.NewGameButtonHandler();
                //ExtendUnlockAndNotifyUserAction (thalmicMyo);
            }
        }
    }
Example #21
0
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (Input.GetKeyDown(KeyCode.I))
        {
            round++;
            //Global.iszero = false;

            for (int i = 0; i < 10; i++)
            {
                test = Instantiate(Resources.Load("pin") as GameObject) as GameObject;
                test.transform.SetParent(pin_manager.transform);
                test.GetComponent <Transform>().localPosition = new Vector3(pos_x[i], 0.0f, pos_z[i]);
                test.SetActive(true);
            }
            for (int i = 0; i < 11; i++)
            {
                Global.hitFlag[i] = false;
            }

            //test.GetComponent<RectTransform>().sizeDelta = new Vector2(320.0f, 100.0f);

            //test.GetComponent<RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f);
        }


        if (act.transform.position.z > 7.0f && isset == false)
        {
            isset = true;
            StartCoroutine(load());
        }

        /*if (already == true) {
         *  round++;
         *  already = false;
         *  for (int i = 0; i < 10; i++)
         *  {
         *      test = Instantiate(Resources.Load("pin") as GameObject) as GameObject;
         *      test.transform.SetParent(pin_manager.transform);
         *      test.GetComponent<Transform>().localPosition = new Vector3(pos_x[i], 0.0f, pos_z[i]);
         *
         *      test.SetActive(true);
         *  }
         * }*/

        //stateText.text = (thalmicMyo.accelerometer * 100).ToString();
        var a = joint.transform.FindChild("Sphere");

        //stateText.text = GameObject.Find("Box").transform.position.ToString() + "";
        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;


            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);

                rb.useGravity = true;
                if (!releaseBall)
                {
                    var temp = joint.transform.FindChild("Sphere");
                    temp.transform.parent = null;
                    releaseBall           = true;

                    Vector3 thisAcc = thalmicMyo.accelerometer;


                    Vector3 direction = temp.transform.position - lastBallPos;
                    stateText.text = direction.y.ToString() + "";
                    if (direction.y > 1)
                    {
                        direction.y = 0.5f;
                    }
                    Vector3 add;
                    add.x = 0.0f;
                    add.y = 0.0f;
                    add.z = 10.0f;
                    rb.AddForce(direction * 5000 + add * 10000);
                }


                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                GetComponent <Renderer>().material = waveInMaterial;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                GetComponent <Renderer>().material = waveOutMaterial;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                GetComponent <Renderer>().material = doubleTapMaterial;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }
        if (frameCount % 10 == 0)
        {
            lastBallPos = a.transform.position;
        }
        frameCount++;
        if (frameCount > 1000)
        {
            frameCount -= 1000;
        }
    }
    //0: left, 1: center, 2: right
    public void DetectWaveFinal(int dir)
    {
        if (_detectionLock)
        {
            //Check if you should unlock it yet.
            if (Time.time - _detectionLockWait > _detectionLockWaitTime)
            {
                _detectionLock = false;
            }
        }

        //If it's been unlocked, proceed.
        if (!_detectionLock)
        {
            //if (_nextArmVector.y > _yBound) {

            switch (dir)
            {
            case 0:
                Debug.Log("Wave left");
                if (_WaveLeft != null)
                {
                    _WaveLeft();
                }
                if (vibrateOnSuccess)
                {
                    _myoTM.Vibrate(Thalmic.Myo.VibrationType.Short);
                }
                _detectionLock     = true;
                _detectionLockWait = Time.time;
                recentWave         = 0;
                break;

            case 1:
                Debug.Log("Wave center");
                if (_WaveCenter != null)
                {
                    _WaveCenter();
                }
                if (vibrateOnSuccess)
                {
                    _myoTM.Vibrate(Thalmic.Myo.VibrationType.Short);
                }
                _detectionLock     = true;
                _detectionLockWait = Time.time;
                recentWave         = 1;
                break;

            case 2:
                Debug.Log("Wave right");
                if (_WaveRight != null)
                {
                    _WaveRight();
                }
                if (vibrateOnSuccess)
                {
                    _myoTM.Vibrate(Thalmic.Myo.VibrationType.Short);
                }
                _detectionLock     = true;
                _detectionLockWait = Time.time;
                recentWave         = 2;
                break;

            default:
                //recentWave = -1;
                break;
            }
            //}
        }
    }
Example #23
0
    // Update is called once per frame.
    void Update()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (thalmicMyo.pose == Pose.Fist && !rupturedBladder)
        {
            //thalmicMyo.Vibrate (VibrationType.Medium);
            GetComponent <ParticleSystem>().emissionRate = Mathf.Lerp(GetComponent <ParticleSystem>().emissionRate, 0, Time.deltaTime * 5);
            BladderPower       -= 0.4f;
            BladderSlider.value = BladderPower / 100;
            //ExtendUnlockAndNotifyUserAction (thalmicMyo);
        }
        else
        {
            //thalmicMyo.Vibrate (VibrationType.Medium);
            GetComponent <ParticleSystem>().emissionRate = _streamPower;
            if (BladderPower < 100)
            {
                BladderPower += 0.05f;
            }
            BladderSlider.value = BladderPower / 100;
            //ExtendUnlockAndNotifyUserAction (thalmicMyo);
        }

        if (BladderPower < 1 && !rupturedBladder)
        {
            rupturedBladder = true;
            BladderSlider.gameObject.SetActive(false);
            BladderImage.GetComponent <Image>().color = Color.red;
            BladderImage.transform.localScale        *= 1.3f;
            BladderImage.GetComponent <RectTransform>().localPosition = new Vector3(BladderImage.GetComponent <RectTransform>().localPosition.x + 1f, 0, 0);
            GetComponent <ParticleSystem>().startColor = BloodPiss;
        }

        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);
                //GetComponent<ParticleSystem>().startSpeed = Mathf.Lerp(GetComponent<ParticleSystem>().startSpeed, 0, Time.deltaTime);
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                //GetComponent<Renderer>().material = waveInMaterial;
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                //GetComponent<Renderer>().material = waveOutMaterial;
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap && Dead)
            {
                Application.LoadLevel(Application.loadedLevel);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                GetComponent <ParticleSystem>().Play();

                TapFingers.SetActive(false);
//				Debug.Log("Shake");
//				ExtendUnlockAndNotifyUserAction (thalmicMyo);
            }
        }

        if (Dead)
        {
            TapFingers.SetActive(true);
        }
    }
Example #24
0
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;
            flamethrow.SetActive(false);
            hitbox.SetActive(false);

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);
                if (flameON)
                {
                    flamethrow.SetActive(true);
                    hitbox.SetActive(true);
                }
                else if (gunON)
                {
                    //instantiate new bullet here
                    GameObject newBullet = Instantiate(bullet, bullet.transform.position, bullet.transform.rotation) as GameObject;
                    newBullet.SetActive(true);
                    newBullet.GetComponent <Rigidbody>().AddForce(bullet.transform.forward * 2000);
                    Physics.IgnoreCollision(transform.root.GetComponent <Collider>(), newBullet.GetComponent <Collider>(), true);
                    Destroy(newBullet, 2.0f);
                }

                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                GetComponent <Renderer>().material = waveInMaterial;
                flameON = false;
                gunON   = true;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                GetComponent <Renderer>().material = waveOutMaterial;
                gunON   = false;
                flameON = true;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                //GetComponent<Renderer> ().material = doubleTapMaterial;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                started = true;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }
    }
Example #25
0
    void Update()
    {
        //setInputs (Input.GetAxisRaw("Vertical"), Input.GetAxisRaw("Horizontal"));

        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);
                Debug.Log("fist");
                m_verticalInput = 4;
                isRunning       = true;
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                Debug.Log("wave in");
                m_horizontalInput = -3;
                left.canvasRenderer.SetAlpha(1.0f);
                right.canvasRenderer.SetAlpha(0.0f);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                Debug.Log("wave out");
                m_horizontalInput = 3;
                right.canvasRenderer.SetAlpha(1.0f);
                left.canvasRenderer.SetAlpha(0.0f);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                Debug.Log("double tap");
                m_verticalInput = 0;
                isRunning       = false;
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                Debug.Log("fingers spread");
                m_verticalInput = -3;
            }
            else
            {
                left.canvasRenderer.SetAlpha(0.0f);
                right.canvasRenderer.SetAlpha(0.0f);
                m_horizontalInput = 0;
            }
        }

        if (isRunning)
        {
            run.canvasRenderer.SetAlpha(1.0f);
            stop.canvasRenderer.SetAlpha(0.0f);
        }
        else
        {
            run.canvasRenderer.SetAlpha(0.0f);
            stop.canvasRenderer.SetAlpha(1.0f);
        }
    }
    void Update()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);
                Fist();
                ExtendUnlockAndNotifyUserAction(thalmicMyo);

                // Change material when wave in, wave out or double tap poses are made.
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                Pick();
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.Rest)
            {
                Idle();
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            Idle();
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            Point();
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            Gesture();
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            Open();
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            Fist();
        }
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            Pick();
        }
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            Grab();
        }
    }
Example #27
0
    void Update()
    {
        if (!inGame)
        {
            if (test)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    redRdy  = true;
                    blueRdy = true;
                }
            }
            else
            {
                ThalmicMyo thalmicMyoRed = redMyo.GetComponent <ThalmicMyo> ();
                if (thalmicMyoRed.pose != lastRedPose && !redRdy)
                {
                    lastRedPose = thalmicMyoRed.pose;

                    // Vibrate the Myo armband when a fist is made.
                    if (thalmicMyoRed.pose == Pose.DoubleTap)
                    {
                        redRdy           = true;
                        redRdyText.text  = "READY";
                        redRdyText.color = Color.red;
                        thalmicMyoRed.Vibrate(VibrationType.Medium);
                        //ExtendUnlockAndNotifyUserAction (thalmicMyo);
                    }
                }

                ThalmicMyo thalmicMyoBlue = blueMyo.GetComponent <ThalmicMyo> ();
                if (thalmicMyoBlue.pose != lastBluePose && !blueRdy)
                {
                    lastBluePose = thalmicMyoBlue.pose;

                    // Vibrate the Myo armband when a fist is made.
                    if (thalmicMyoBlue.pose == Pose.DoubleTap)
                    {
                        blueRdy           = true;
                        blueRdyText.text  = "READY";
                        blueRdyText.color = Color.blue;
                        thalmicMyoBlue.Vibrate(VibrationType.Medium);
                        //ExtendUnlockAndNotifyUserAction (thalmicMyo);
                    }
                }
            }
            if (blueRdy && redRdy)
            {
                blueRdyText.text = "";
                redRdyText.text  = "";
                inGame           = true;
                blueRdy          = false;
                redRdy           = false;
                spawnBall();
            }
        }


        if (detWinner && Input.GetKeyDown(KeyCode.Space))
        {
            detWinner = !detWinner;
            Vector3 padSize = new Vector3(0.5f, 2f, 1f);
            bluePad.transform.localScale = padSize;
            redPad.transform.localScale  = padSize;
            blueRdyText.text             = "Double Tap";
            blueRdyText.color            = Color.black;
            redRdyText.text  = "Double Tap";
            redRdyText.color = Color.black;
            winner.text      = "";
            red            = 3;
            blue           = 3;
            blueScore.text = "" + blue;
            redScore.text  = "" + red;
            inGame         = false;
        }
    }
Example #28
0
	void UpdatePoses (ThalmicMyo thalmicMyo) {
		if (thalmicMyo.pose != _lastPose && thalmicMyo.pose != Pose.Unknown) {

			_lastPose = thalmicMyo.pose;

			if (thalmicMyo.pose == Pose.Rest) {
				return;
			}

			// Give feedback
			// thalmicMyo.Vibrate (VibrationType.Short);

			if (thalmicMyo.pose == Pose.Fist) {
				print("Fist detected");
				if (grabEnabled) {
					if (_grab == null) {
						RaycastHit hit;
						if (Physics.Raycast (transform.position, transform.rotation * Vector3.forward, out hit, 100f)) {
							_grab = hit.collider.transform;
							_updateGrabReference = true;
							thalmicMyo.Vibrate (VibrationType.Short);
							print("Grabbed");
						}
					}
				}

			} else if (thalmicMyo.pose == Pose.WaveIn) {
				if (thalmicMyo.arm == Thalmic.Myo.Arm.Left) {
					print("Wave RIGHT detected (left arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					slideGen.Reverse ();

				} else if (thalmicMyo.arm == Thalmic.Myo.Arm.Right) {
					print("Wave LEFT detected (right arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					slideGen.Advance ();
				}

			} else if (thalmicMyo.pose == Pose.WaveOut) {
				if (thalmicMyo.arm == Thalmic.Myo.Arm.Left) {
					print("Wave LEFT detected (left arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					slideGen.Advance ();

				} else if (thalmicMyo.arm == Thalmic.Myo.Arm.Right) {
					print("Wave RIGHT detected (right arm)");
					thalmicMyo.Vibrate (VibrationType.Short);
					slideGen.Reverse ();
				}

			} else if (thalmicMyo.pose == Pose.ThumbToPinky) {
				print("Thumb to Pinky detected");
				//if (Mathf.Approximately (_referenceRoll, 0f)) {
				_updateReference = true;
				thalmicMyo.Vibrate (VibrationType.Short);
				print("Calibrated");
				//}

			} else if (thalmicMyo.pose == Pose.FingersSpread) {
				print("Fingers Spread detected");
				thalmicMyo.Vibrate (VibrationType.Short);
				if (_grab == null) {
					showPointer = !showPointer;
					print("Pointer " + showPointer.ToString());
				} else {
					_grab = null;
					print("Released");
				}
			}
		}
	}
    private void HandleInput()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;


            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);

                ExtendedUnlockAndNotifyUserAction(thalmicMyo);

                // Myo Gesture Fist will move the direction
                // of the snake up
            }
            else if (thalmicMyo.pose == Pose.Fist)
            {
                if (gridMoveDirection != Direction.Down)
                {
                    // i cannot move down if  i am already moving up
                    gridMoveDirection = Direction.Up;
                }
                ExtendedUnlockAndNotifyUserAction(thalmicMyo);
            }
            // Myo Gesture Double tap of fingers will move the direction
            // of the snake down
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                if (gridMoveDirection != Direction.Up)
                {
                    // i cannot move up if  i am already moving down
                    gridMoveDirection = Direction.Down;
                }
                ExtendedUnlockAndNotifyUserAction(thalmicMyo);
            }
            // Myo Gesture wave-in with your hand will move the direction
            // of the snake to the left
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                if (gridMoveDirection != Direction.Right)
                {
                    // i cannot move right if  i am already moving left
                    gridMoveDirection = Direction.Left;
                }
                ExtendedUnlockAndNotifyUserAction(thalmicMyo);
            }
            // Myo Gesture wave-out with your hand will move the direction
            // of the snake to the right
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                if (gridMoveDirection != Direction.Left)
                {
                    // i cannot move left if  i am already moving right
                    gridMoveDirection = Direction.Right;
                }
                ExtendedUnlockAndNotifyUserAction(thalmicMyo);
            }
        }
    }
                                                                                               void Update() 

                                                                                               {
                                                                                                   
 currentTime += Time.deltaTime; 

 Scene currentScene = SceneManager.GetActiveScene(); 
 string sceneName = currentScene.name; 
 // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo>();

        bool updateReference = true;

        Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));


        if (updateReference)

                                                                                                   {
                                                                                                       // _antiYaw represents a rotation of the Myo armband about the Y axis (up) which aligns the forward
                                                                                                       // vector of the rotation with Z = 1 when the wearer's arm is pointing in the reference direction.
                                                                                                       _antiYaw = Quaternion.FromToRotation(
                                                                                                           new Vector3(myo.transform.forward.x, 0, myo.transform.forward.z),
                                                                                                           new Vector3(0, 0, 1)
                                                                                                           );

                                                                                                       // _referenceRoll represents how many degrees the Myo armband is rotated clockwise
                                                                                                       // about its forward axis (when looking down the wearer's arm towards their hand) from the reference zero
                                                                                                       // roll direction. This direction is calculated and explained below. When this reference is
                                                                                                       // taken, the joint will be rotated about its forward axis such that it faces upwards when
                                                                                                       // the roll value matches the reference.
                                                                                                       Vector3 referenceZeroRoll = computeZeroRollVector(myo.transform.forward);

                                                                                                       _referenceRoll = rollFromZero(referenceZeroRoll, myo.transform.forward, myo.transform.up);
                                                                                                       //Debug.Log(_referenceRoll);
                                                                                                   }

                                                                                                   if (_referenceRoll > 75.0)
                                                                                                   {
                                                                                                       //Debug.Log("test");
                                                                                                       moveInput = new Vector2(-1, 0);
                                                                                                   }
                                                                                                   else if (_referenceRoll < 50.0)
                                                                                                   {
                                                                                                       moveInput = new Vector2(1, 0);
                                                                                                   }
                                                                                                   else
                                                                                                   {
                                                                                                       moveInput = new Vector2(0, 0);
                                                                                                   }

                                                                                                   moveV = moveInput * moveSpeed;

                                                                                                   // Check if the pose has changed since last update.
                                                                                                   // The ThalmicMyo component of a Myo game object has a pose property that is set to the
                                                                                                   // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
                                                                                                   // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
                                                                                                   // is not on a user's arm, pose will be set to Pose.Unknown.
                                                                                                   if (thalmicMyo.pose != _lastPose)
                                                                                                   {
                                                                                                       
        {
                                                                                                           
 _lastPose = thalmicMyo.pose; 

            if (sceneName == "Menu")

                                                                                                           {
                                                                                                               
            {
                                                                                                                   

                                             // Vibrate the Myo armband when a fist is made.
                if (thalmicMyo.pose == Pose.FingersSpread)
                {
                    Debug.Log("Menu fist Working");
                    thalmicMyo.Vibrate(VibrationType.Medium);
                    
                    Debug.Log(updateReference);
                    LoadScene("SampleScene");
                    
                    ExtendUnlockAndNotifyUserAction(thalmicMyo);

                }
                else if (thalmicMyo.pose == Pose.WaveIn)
                {
                    Debug.Log("Menu wave in Working");
                    LoadScene("Options");
 
                    ExtendUnlockAndNotifyUserAction(thalmicMyo);
                }
                else if (thalmicMyo.pose == Pose.DoubleTap)
                {
                    Debug.Log("Menu FrigerSpread works");
                    QuitGame();
                    ExtendUnlockAndNotifyUserAction(thalmicMyo);
                }
            }
            else if(sceneName == "SampleScene")
            {

                                                                                                                   if (thalmicMyo.pose == Pose.Fist)
                                                                                                                   {
                                                                                                                       
                {
                                                                                                                           

                                                                                                                           Debug.Log("level1 Shooting"); 


                                                                                                                           Shoot(); 


                                                                                                                           ExtendUnlockAndNotifyUserAction(thalmicMyo); 

                                                                                                                       }
                                                                                                                   }
                                                                                                                   

                                                                                                               }
                                                                                                           }
                                                                                                           
            else if (sceneName == "Options")
                                                                                                           {
                                                                                                               
            {
                                                                                                                   
                if (thalmicMyo.pose == Pose.FingersSpread)
                                                                                                                   {
                                                                                                                       
                {
                                                                                                                           
 Debug.Log("Options Working"); 
                    QuitGame(); 
                    ExtendUnlockAndNotifyUserAction(thalmicMyo); 

                                                                                                                       }
                                                                                                                   }
                                                                                                                   
                else if (thalmicMyo.pose == Pose.Fist)
                                                                                                                   {
                                                                                                                       
                {
                                                                                                                           
 Debug.Log("level1 Moving Right"); 
                    LoadScene("Menu"); 
                    ExtendUnlockAndNotifyUserAction(thalmicMyo); 

                                                                                                                       }
                                                                                                                   }
                                                                                                                   

                                                                                                               }
                                                                                                           }
                                                                                                           

                                                                                                       }
Example #31
0
    // Update is called once per frame.
    void Update()
    {
        ThalmicHub hub        = ThalmicHub.instance;
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        bool updateReference = false;

        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);
                FindObjectOfType <Tetramino>().RotateClockwise();
                LockingPolicyTime(thalmicMyo);
            }

            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);

                //transform.position += new UnityEngine.Vector3(-1, 0, 0);


                FindObjectOfType <Tetramino>().MoveLeftOnce();

                LockingPolicyTime(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);

                //transform.position += new UnityEngine.Vector3(1, 0, 0);


                FindObjectOfType <Tetramino>().MoveRightOnce();

                LockingPolicyTime(thalmicMyo);
            }

            else if (thalmicMyo.pose == Pose.Fist)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);
                FindObjectOfType <Tetramino>().RotateCounterClockwise();
                LockingPolicyTime(thalmicMyo);
            }


            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                updateReference = true;
                thalmicMyo.Vibrate(VibrationType.Medium);
                FindObjectOfType <Tetramino>().SpeedUp();
                LockingPolicyTime(thalmicMyo);
            }

            else if (thalmicMyo.pose == Pose.Unknown)
            {
                thalmicMyo.Vibrate(VibrationType.Long);
                updateReference = true;
                LockingPolicyTime(thalmicMyo);
            }
        }

        if (Input.GetKeyDown("r"))
        {
            updateReference = true;
        }

        if (updateReference)
        {
            //_antiYaw = Quaternion.FromToRotation(
            //new Vector3(myo.transform.forward.x, 0, myo.transform.forward.z),
            //new Vector3(0, 0, 1)

            //);
            //Vector3 referenceZeroRoll = computeZeroRollVector(myo.transform.forward);
            //_referenceRoll = rollFromZero(referenceZeroRoll, myo.transform.forward, myo.transform.up);
        }

        //Vector3 zeroRoll = computeZeroRollVector(myo.transform.forward);
        //float roll = rollFromZero(zeroRoll, myo.transform.forward, myo.transform.up);

        //float relativeRoll = normalizeAngle(roll - _referenceRoll);

        //// antiRoll represents a rotation about the myo Armband's forward axis adjusting for reference roll.
        //Quaternion antiRoll = Quaternion.AngleAxis(relativeRoll, myo.transform.forward);

        //// Here the anti-roll and yaw rotations are applied to the myo Armband's forward direction to yield
        //// the orientation of the joint.
        //transform.rotation = _antiYaw * antiRoll * Quaternion.LookRotation(myo.transform.forward);

        //if (thalmicMyo.xDirection == Thalmic.Myo.XDirection.TowardWrist)
        //{
        //    // Mirror the rotation around the XZ plane in Unity's coordinate system (XY plane in Myo's coordinate
        //    // system). This makes the rotation reflect the arm's orientation, rather than that of the Myo armband.
        //    transform.rotation = new Quaternion(transform.localRotation.x,
        //                                        -transform.localRotation.y,
        //                                        transform.localRotation.z,
        //                                        -transform.localRotation.w);
        //}
    }
Example #32
0
    // Update is called once per frame
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();

        // Check if the pose has changed since last update.
        // The ThalmicMyo component of a Myo game object has a pose property that is set to the
        // currently detected pose (e.g. Pose.Fist for the user making a fist). If no pose is currently
        // detected, pose will be set to Pose.Rest. If pose detection is unavailable, e.g. because Myo
        // is not on a user's arm, pose will be set to Pose.Unknown.
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);                     // vibration to notify the user that input has been taken
                new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.SPACE); // Simulate keyboard input handled by default by the event system
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            if (thalmicMyo.pose == Pose.WaveOut)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);                     // vibration to notify the user that input has been taken
                new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.RIGHT); // Simulate keyboard input handled by default by the event system
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            if (thalmicMyo.pose == Pose.WaveIn)
            {
                thalmicMyo.Vibrate(VibrationType.Medium);                    // vibration to notify the user that input has been taken
                new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.LEFT); // Simulate keyboard input handled by default by the event system
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            if (thalmicMyo.pose == Pose.DoubleTap)
            {
                ControlsPanel.SetActive(false);// deactivates controls panel
            }
        }

        /*
         * //float MYORotX = myo.transform.localRotation.eulerAngles.x;
         * float MYORotY = myo.transform.localRotation.eulerAngles.y;
         *
         * if (MYORotY >= 180f && MYORotY <= 360f)
         * {
         *  MYORotY -= 180f;
         * }
         *
         *
         * if (MYORotY < 19f)
         * {
         *  armPos = -1;// Down
         *  Debug.Log(armPos);
         * }
         * if (MYORotY < 60f && MYORotY > 20f)
         * {
         *  Debug.Log("Neutral");
         *  armPos = 0;
         *  onceCalled = false;
         * }
         * if (MYORotY > 80f)
         * {
         *  armPos = 1;// Up
         *  Debug.Log(armPos);
         * }
         *
         * if (armPos == -1)
         * {
         *  if(onceCalled == false)
         *  {
         *      new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.DOWN);
         *      Debug.Log("DOWN");
         *
         *      onceCalled = true;
         *  }
         * }
         * if (armPos == 1)
         * {
         *  if (onceCalled == false)
         *  {
         *      new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.UP);
         *      Debug.Log("UP");
         *
         *      onceCalled = true;
         *  }
         * }
         * //Debug.Log(MYORotY);
         */
    }