示例#1
0
    // Update is called once per frame.
    void Update ()
    {
        // Access the ThalmicMyo component attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        // Update references when the pose becomes fingers spread or the q key is pressed.
        bool updateReference = false;
        if (thalmicMyo.pose != _lastPose) {
            _lastPose = thalmicMyo.pose;

        }
		if (gameRunning) {
			if (gameRunning && !calibrated) {
				Initialize ();
				calibrated = true;
			}

			// 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.
			Debug.Log (myo.transform.eulerAngles.ToString());
			Vector3 rotation = myo.transform.eulerAngles - offset;
			transform.eulerAngles = rotation;
	}
		// Adjust vertically given horizontal rotation
		/*Vector3 newPosition = new Vector3 (transform.position.x,
		                                   transform.rotation.x*-8,
		                                   transform.position.z);
		transform.position = newPosition;*/
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (myo.pose != lastPose) {
            lastPose = myo.pose;
            if (myo.pose == Pose.WaveIn)
            {
                Vector3 push = new Vector3 (0, 0, 1 * Time.deltaTime);
                transform.Rotate(push * speed);
                //transform.Rotate (new Vector3 (15, 30, 45) * Time.deltaTime);
            }
            if (myo.pose == Pose.WaveOut) {
                Vector3 push = new Vector3 (1 * Time.deltaTime, 0, 0);
                transform.Rotate(push * speed);
            }

            if (myo.pose == Pose.FingersSpread)
            {
                Vector3 push = new Vector3 (-1, 0, 0);
                rb.AddForce(push * speed);
            }

            if (myo.pose == Pose.Fist)
            {
                Vector3 push = new Vector3 (1, 0, 0);
                rb.AddForce(push * speed);
            }

        }
    }
示例#3
0
	// Update is called once per frame
	void Update () {
		ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();
		if (thalmicMyo.pose != _lastPose) {
			_lastPose = thalmicMyo.pose;
			//Check if the Cancel button in Input Manager is down this frame (default is Escape key) and that game is not paused, and that we're not in main menu
			if (thalmicMyo.pose == Pose.WaveOut) {
				thalmicMyo.Vibrate (VibrationType.Medium);
				counter += 1;
				if(counter == 1){
					text.text = "You play as the red ball.";
				}
				else if(counter == 2) {
					text.text = "Pick up all the yellow cubes in a minimum of time.";
				}else if(counter == 3) {
					text.text = "Use your arm to move the ball.";
				}else if(counter == 4) {
					text.text = "Make a fist to pause the game.";
				}else{
					text.text = "";
					panel.SetActive(false);
					Time.timeScale = 1;
					isPaused = false;
				}
			} 
		}
	}
示例#4
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) {
				JointOrientation.gameRunning = true;
                thalmicMyo.Vibrate (VibrationType.Medium);

            // Change material when wave in, wave out or thumb to pinky poses are made.
            } else if (thalmicMyo.pose == Pose.WaveIn) {
                renderer.material = waveInMaterial;
            } else if (thalmicMyo.pose == Pose.WaveOut) {
                renderer.material = waveOutMaterial;
            } else if (thalmicMyo.pose == Pose.ThumbToPinky) {
                renderer.material = thumbToPinkyMaterial;
            }
        }
    }
示例#5
0
	// Update is called once per frame
	void Update () {
		ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();
		//Check if it is the last level
		/*if (Application.loadedLevel + 1 == null) {

		}*/
		if (thalmicMyo.pose != _lastPose) {
			_lastPose = thalmicMyo.pose;
			//Check if the Cancel button in Input Manager is down this frame (default is Escape key) and that game is not paused, and that we're not in main menu
			if (thalmicMyo.pose == Pose.DoubleTap && !isPaused) {
				thalmicMyo.Vibrate (VibrationType.Medium);
				//Call the DoPause function to pause the game
				DoPause ();
			} 
		//If the button is pressed and the game is paused and not in main menu
			else if (thalmicMyo.pose == Pose.Fist && isPaused) {
				thalmicMyo.Vibrate (VibrationType.Medium);
					//Call the UnPause function to unpause the game
				//Set isPaused to false
				isPaused = false;
				//Set time.timescale to 1, this will cause animations and physics to continue updating at regular speed
				Time.timeScale = 1;
			}
		}
	}
示例#6
0
	// Update is called once per frame
	void LateUpdate () {

		// Access the ThalmicMyo component attached to the Myo game object.
		ThalmicMyo rightThalmicMyo = rightMyo.GetComponent<ThalmicMyo> ();
		ThalmicMyo leftThalmicMyo = leftMyo.GetComponent<ThalmicMyo> ();

		if ((rightThalmicMyo.pose != _rightlastPose) | (leftThalmicMyo.pose != _leftlastPose)) {
			if ((rightThalmicMyo.pose == Pose.Fist) & (leftThalmicMyo.pose == Pose.Fist)) {
				Debug.Log ("PULL DOWN!\n");
				Debug.Log ("Right X Coord = " + rightThalmicMyo.transform.position.x);
				controlWall.Slam();
			}
			else if (rightThalmicMyo.pose != _rightlastPose) {
				if (rightThalmicMyo.pose == Pose.DoubleTap) {
					Debug.Log ("ROTATE RIGHT!\n");
					controlWall.RotatePlayer(1);
				} else if (rightThalmicMyo.pose == Pose.WaveOut) {
					Debug.Log ("MOVE RIGHT!\n");
					controlWall.UpdatePlayerHorizontally (-1);
				}
			}
			else {
				if (leftThalmicMyo.pose == Pose.DoubleTap) {
					Debug.Log ("ROTATE LEFT!\n");
					controlWall.RotatePlayer(-1);
				} else if (leftThalmicMyo.pose == Pose.WaveOut) {
					Debug.Log ("MOVE LEFT!\n");
					controlWall.UpdatePlayerHorizontally (1);
				}
			}
		}
		_leftlastPose = leftThalmicMyo.pose;
		_rightlastPose = rightThalmicMyo.pose;
	}
    // 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 = 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);
            }
        }
    }
    private void actions()
    {
        // Access the ThalmicMyo component attached to the Myo game object.
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        //Camera Direction setup
        //Transform cameraTransform = theCamera.transform;
        // forward of the camera on the x-z plane
        Vector3 cameraForward = theCamera.transform.TransformDirection(Vector3.forward);
        cameraForward.y = 0f;
        cameraForward = cameraForward.normalized;

        Vector3 cameraRight = new Vector3(cameraForward.z, 0.0f, -cameraForward.x);
        Vector3 cameraLeft = new Vector3(-cameraForward.z, 0.0f, cameraForward.x);

        if (slowed && Time.unscaledTime - timeStart > timeSlowed) {
            Time.timeScale = 1.0f;
            rb.velocity = timeMultiplier * rb.velocity;
            slowed = false;
            Debug.Log ("Time");
        }

        // 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) {
                rb.AddForce(cameraLeft * force);

            } else if (thalmicMyo.pose == Pose.WaveOut) {
                rb.AddForce(cameraRight * force);

                ExtendUnlockAndNotifyUserAction (thalmicMyo);
            } else if (thalmicMyo.pose == Pose.DoubleTap) {
                if(Time.timeScale == timeMultiplier){
                    Time.timeScale = 1.0f;
                    rb.velocity = timeMultiplier * rb.velocity;
                    slowed = false;
                }else{
                    Time.timeScale = timeMultiplier;
                    slowed = true;
                    timeStart = Time.unscaledTime;
                }
                //rb.AddForce (new Vector3(0.0f, force * 10, 0.0f));
                ExtendUnlockAndNotifyUserAction (thalmicMyo);
            }
        }
    }
示例#9
0
	void Update () {
		if (currentpose == Thalmic.Myo.Pose.Rest && (nextpose == Thalmic.Myo.Pose.Fist || nextpose == Thalmic.Myo.Pose.WaveIn) && !latch) {
			latch = true;
			StartCoroutine (playsound());
		}
		currentpose = nextpose;
		nextpose = thalmicMyo.pose;
	}
示例#10
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);
        }
    }
示例#11
0
 // Use this for initialization
 public MyoMovement(GameObject myo)
 {
     this.myo = myo;
     this.thalmicMyo = myo.GetComponent<ThalmicMyo> ();
     if (thalmicMyo.isPaired) {
         isMyo = true;
     }
     curPose = _lastPose;
 }
示例#12
0
	void Update () {
		// Access the ThalmicMyo component attached to the Myo game object.
		ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();
		LoadOnClick load = GetComponent<LoadOnClick>();
		// 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;
				buttons = FindObjectsOfType(typeof(Button)) as Button[];
				ColorBlock cb = new ColorBlock();

            
        // Vibrate the Myo armband when a fist is made.
        if (thalmicMyo.pose == Pose.Fist) {
					thalmicMyo.Vibrate (VibrationType.Medium);
					buttons[selected].onClick.Invoke();
				}
			 if (thalmicMyo.pose == Pose.WaveIn) {
						if (selected > 0) {

							cb = buttons[selected].colors;
							cb.normalColor = Color.white;
							buttons[selected].colors = cb;

							selected -= 1;

							cb = buttons[selected].colors;
							cb.normalColor = new Color32(220, 74, 59, 250);
              cb.highlightedColor = Color.green;
              buttons[selected].colors = cb;
						}

						ExtendUnlockAndNotifyUserAction (thalmicMyo);
				}
				 if (thalmicMyo.pose == Pose.WaveOut) {
						if (selected < buttons.Length - 1) {
							cb = buttons[selected].colors;
							cb.normalColor = Color.white;
							buttons[selected].colors = cb;

							selected += 1;

							cb = buttons[selected].colors;
							cb.normalColor = new Color32(220, 74, 59, 250);
              cb.highlightedColor = Color.green;
              buttons[selected].colors = cb;
						}

						ExtendUnlockAndNotifyUserAction (thalmicMyo);
				}
		}
	}
示例#13
0
文件: Main.cs 项目: Jorbay/robot-hand
    // Use this for initialization
    void Start()
    {
        pose = Thalmic.Myo.Pose.Rest;
        poseDuration = 0.0f;

        stream = new SerialPort(COM_PORT_NAME, BAUD_RATE);
        stream.WriteTimeout = 100;
        stream.Open();

        myoRef = null;
    }
示例#14
0
	void Update(){

		if (waitfornow == true) {
			if(timecount > 5f){
				waitfornow = false;
				timecount = 0f;
				renderer.material = basematerial;
			}else{
				renderer.material = stall;
				timecount += Time.deltaTime;
				return;
			}
		}

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

		if (transform.position.y > 2.5 && hasBall == true) {
			renderer.material = basematerial;
			Instantiate(ball, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
			hasBall = false;
			waitfornow = true;

			go = GameObject.Find("gm");
			go.GetComponent<gm> ().addBowl ();

		}

		if (thalmicMyo.pose != _lastPose) {
			_lastPose = thalmicMyo.pose;
			if(thalmicMyo.pose == Pose.FingersSpread && hasBall == true){
				renderer.material = basematerial;
				Instantiate(ball, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
				hasBall = false;
				waitfornow = true;

				go = GameObject.Find("gm");
				go.GetComponent<gm> ().addBowl ();

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

            // Change material when wave in, wave out or thumb to pinky poses are made.
            } else if (thalmicMyo.pose == Pose.WaveIn) {
                renderer.material = waveInMaterial;
            } else if (thalmicMyo.pose == Pose.WaveOut) {
                renderer.material = waveOutMaterial;
            } else if (thalmicMyo.pose == Pose.ThumbToPinky) {
                renderer.material = thumbToPinkyMaterial;
            }*/
		}
	}
示例#15
0
    // Update is called once per frame.
    void Update ()
    {
        // Access the ThalmicMyo component attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        // Update references when the pose becomes fingers spread or the q key is pressed.
        bool updateReference = false;
        if (thalmicMyo.pose != _lastPose) {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.FingersSpread) {
                updateReference = true;
            }
        }
        if (Input.GetKeyDown ("r")) {
            updateReference = true;
        }

        // 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);
    }
示例#16
0
 void Update() {
     lock (_lock) {
         if (_myoQuaternion != null) {
             transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
         }
         if (_myoAccelerometer != null) {
             accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
         }
         if (_myoGyroscope != null) {
             gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
         }
         pose = _myoPose;
     }
 }
	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");

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

        float horizontal = 0;
        float verticle = 0;
        float up = 0;
        // 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;

            // forward
            if (thalmicMyo.pose == Pose.FingersSpread) {
                verticle=1;

            //left
            } else if (thalmicMyo.pose == Pose.WaveIn) {
                horizontal=-1;

            }
            //right
            else if (thalmicMyo.pose == Pose.WaveOut) {
                horizontal=1;

            }
            //backwards
            else if (thalmicMyo.pose == Pose.Fist) {
                verticle=-1;

            }
            else if(thalmicMyo.pose == Pose.ThumbToPinky){
                up=1;

                rigidbody.AddForce (new Vector3 (horizontal, up, verticle)*speed*(Time.deltaTime+1));
                //transform.Translate (Vector3.up * 260 * Time.deltaTime, Space.World);
                return;
            }

            rigidbody.AddForce (new Vector3 (horizontal, up, verticle)*speed*(Time.deltaTime+1));

        }
        testText.text = thalmicMyo.pose.ToString ();
    }
示例#19
0
    // Update is called once per physics thing
    void FixedUpdate()
    {
        // Access the ThalmicMyo component attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        // Update references when the pose becomes fingers spread or the q key is pressed.
        bool updateReference = false;
        if (thalmicMyo.pose != _lastPose) {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.DoubleTap) {
                updateReference = true;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            if (thalmicMyo.pose == Pose.Fist && !isThrown){

                xPos =myoSphere.transform.position.x;
                yPos =myoSphere.transform.position.y;
                zPos =myoSphere.transform.position.z;
                Vector3 tempVect = new Vector3(xPos,yPos,zPos);

                rendeMyo = GetComponent<Renderer>();

                rendeMyo.enabled= false;
                rende.enabled=true;

                Sphere.transform.position = tempVect;

                Rigidbody rigidBody = this.GetComponent<Rigidbody> ();
                rigidBody.AddForce (new Vector3 (0, 700, 500));
                isThrown = true;

                camMain.GetComponent<Camera>().enabled = false;
                camFollow.GetComponent<Camera>().enabled = true;

            }
        }

        if(Sphere.transform.position.y < -2f){
            isThrown = false;
            camMain.GetComponent<Camera> ().enabled = true;
            camFollow.GetComponent<Camera> ().enabled = false;
            rende.enabled = false;
        }
    }
示例#20
0
 void Update() {
     lock (_lock) {
         armSynced = _myoArmSynced;
         arm = _myoArm;
         xDirection = _myoXDirection;
         if (_myoQuaternion != null) {
             transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
         }
         if (_myoAccelerometer != null) {
             accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
         }
         if (_myoGyroscope != null) {
             gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
         }
         pose = _myoPose;
         unlocked = _myoUnlocked;
     }
 }
示例#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> ();

		ThalmicHub hub = ThalmicHub.instance;
		if (JointOrientation.gameRunning == false && !thalmicMyo.armRecognized) {
						scoreText.GetComponent<TextMesh> ().text = "Do setup\r\ngesture";
				} else if(undone){
					scoreText.GetComponent<TextMesh> ().text = "Grab the\r\nlightsaber";
					undone = 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 || Input.GetKey ("p")) {
			_lastPose = thalmicMyo.pose;
			
			// Vibrate the Myo armband when a fist is made.
			if (!JointOrientation.gameRunning &&
				(thalmicMyo.pose == Pose.Fist || Input.GetKey("p"))) {
				thalmicMyo.Vibrate (VibrationType.Medium);
				state = 1;
				audio.Play ();
				JointOrientation.gameRunning = true;

			} 
		}
		if (JointOrientation.gameRunning) {
			gameTime -= Time.deltaTime;
			if(gameTime < 0 || hit == maxhits) {
				scoreText.text = (deflected).ToString() + " Blocks\r\n" + 
					(hit).ToString () + " Hits";
				JointOrientation.gameRunning = false;
			}
		}
		Extend ();
	}
示例#22
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);
                Instantiate(Spawn);
                ExtendUnlockAndNotifyUserAction (thalmicMyo);
            }
        }
    }
示例#23
0
    //sp.Write("1");
    void Update()
    {
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.DoubleTap)
            {
                if (a.isPlaying)
                {
                    a.Stop();
                }

                else
                {
                    a.Play();
                }



                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }


        if (flag == "1")
        {
            sp.Write(flag);
        }
        else if (flag == "2")
        {
            sp2.Write(flag);
        }
        else
        {
            sp.Write("0");
            sp2.Write("0");
        }
    }
示例#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;

            // 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;

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

            //    ExtendUnlockAndNotifyUserAction (thalmicMyo);
            //} else if (thalmicMyo.pose == Pose.DoubleTap) {
            //    renderer.material = doubleTapMaterial;

            //    ExtendUnlockAndNotifyUserAction (thalmicMyo);
            //}
        }
    }
示例#25
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);

                fire = new Fire();
                fire.fire(Box, selector);

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }

            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                // This is here just incase I need to change the selector.
                thalmicMyo.Vibrate(VibrationType.Short);

                if (selector == false)
                {
                    selector = true;
                }
                else
                {
                    selector = false;
                }

                Debug.Log(" Selector: " + selector);
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
        }
    }
示例#26
0
 void Update()
 {
     lock (_lock) {
         armSynced  = _myoArmSynced;
         arm        = _myoArm;
         xDirection = _myoXDirection;
         if (_myoQuaternion != null)
         {
             transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
         }
         if (_myoAccelerometer != null)
         {
             accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
             Data.Accel    = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
         }
         if (_myoGyroscope != null)
         {
             gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
         }
         pose     = _myoPose;
         unlocked = _myoUnlocked;
     }
 }
示例#27
0
        bool StopGestureOccured()
        {
            ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

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

                if (thalmicMyo.pose == Pose.FingersSpread)
                {
                    UnityEngine.Debug.Log("Stop gesture");
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
示例#28
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.
            }
        }
    }
示例#29
0
    /// <summary>
    /// Updates the current pose.
    /// </summary>
    public void Update()
    {
        if (isFirstUpdate)           //Called to fix offsets
        {
            xOffset       = myo.transform.rotation.x;
            yOffset       = myo.transform.rotation.y;
            zOffset       = myo.transform.rotation.z;
            isFirstUpdate = false;
        }         //End isFirstUpdate check

        //Update current values
        curX = myo.transform.rotation.x;
        curY = myo.transform.rotation.y;
        curZ = myo.transform.rotation.z;
        //End value update

        if (curPose != thalmicMyo.pose)           //Updates pose
        {
            falsifyOnce();
            _lastPose = curPose;
            curPose   = thalmicMyo.pose;
        }         //End update pose
    }
示例#30
0
    void didReceivePoseChange(string param)
    {
        Pose receivedPose = Pose.Unknown;

        for (int i = (int)Pose.Rest; i <= (int)Pose.Unknown; i++)
        {
            Pose currPose = (Pose)i;
            if (currPose.ToString().Equals(param))
            {
                receivedPose = currPose;
                break;
            }
        }
        //Update all myos for now because we don't have the myo id
        foreach (ThalmicMyo myo in ThalmicHub.instance._myos)
        {
            if (ThalmicHub.DidReceivePoseChange != null)
            {
                ThalmicHub.DidReceivePoseChange(null, receivedPose);
            }
            myo._myoPose = receivedPose;
        }
    }
示例#31
0
    public int[] Update()
    {
        // Line for mapping motion to avatar elbow
        ClientRoutine_Sitting.elbowMyo = GetComponent <Transform>().rotation; //Supinate z, Internal rotation y, Bicep x,

        lock (_lock) {                                                        // The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section.
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;
            if (_myoQuaternion != null)
            {
                transform.localRotation = new UnityEngine.Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
            }
            if (_myoAccelerometer != null)
            {
                accelerometer = new UnityEngine.Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null)
            {
                gyroscope = new UnityEngine.Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            if (isPaired && streamEmg == Thalmic.Myo.Result.Success)
            {
                emg = _myo.emgData;

                /*
                 * UnityEngine.Debug.Log("Size of raw emg array (ThalmicMyo): " + emg.Length);
                 * UnityEngine.Debug.Log("Timestamp: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                 * UnityEngine.Debug.Log("---------------------------------------------");
                 */
            }

            pose     = _myoPose;
            unlocked = _myoUnlocked;
        }
        return(emg);
    }
示例#32
0
    // Update is called once per frame
    void Update()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Resetting capabilities
        bool updateReference = false;

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

            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
                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);
        Quaternion antiRoll     = Quaternion.AngleAxis(relativeRoll, myo.transform.forward);

        transform.rotation = _antiYaw * antiRoll * Quaternion.LookRotation(myo.transform.forward);
    }
示例#33
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;

            if (thalmicMyo.pose == Pose.Fist)
            {
                Debug.Log("Fist");
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                Debug.Log("Wave in");
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                Debug.Log("Wave out");
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                Debug.Log("Double tap");
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                Debug.Log("Fingers spread");
            }
        }
    }
示例#34
0
文件: Main.cs 项目: Jorbay/robot-hand
    // Update is called once per frame
    void Update()
    {
        if (myoRef == null) {
            myoRef = FindObjectOfType<ThalmicMyo> ();
        } else {

            Thalmic.Myo.Pose overriddenPose = POSE_OVERRIDES[myoRef.pose];

            if (overriddenPose != pose && poseDuration > MIN_POSE_DURATION)
            {
                byte[] output = new byte[1];
                output[0] = ANGLE_OPEN;

                switch (overriddenPose)
                {
                    case Thalmic.Myo.Pose.Rest:
                        output[0] = ANGLE_OPEN;
                        break;
                    case Thalmic.Myo.Pose.Fist:
                        output[0] = ANGLE_CLOSE;
                        break;
                }

                pose = overriddenPose;
                poseDuration = 0.0f;

                //send hand command
                Debug.Log("Pose: " + pose.ToString() + "\nActual: " + myoRef.pose.ToString() + "\nAngle: " + output[0]);
                stream.Write(output, 0, 1);
            }
            else
            {
                poseDuration += Time.deltaTime;
            }
        }
    }
    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();
        }
    }
示例#36
0
    // Update is called once per frame
    void Update()
    {
        //------------------------
        Debug.Log("lastFall: " + fallSpeed);
        //Text lf = levelT.text;
        //-------------------------
        // Fall

        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo>();
        bool       fist       = false;
        bool       wavein     = false;
        bool       waveout    = false;
        bool       doubletap  = false;

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

            if (thalmicMyo.pose == Pose.Fist)
            {
                fist = true;
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                wavein = true;
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                waveout = true;
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                doubletap = true;
            }
        }
        if (mov == true && name != "BarraZ" && name != "CuadroA" && name != "LderechaM" && name != "LizquierdaC" && name != "SR" && name != "TV" && name != "ZN" && name != "Hub - 1 Myo")
        {
            // Mover hacia la izquierda
            if (Input.GetKeyDown(KeyCode.LeftArrow) || wavein)
            {
                // Modificar posición
                transform.position += new Vector3(-1, 0, 0);

                // Ver si es válido
                if (isValidMatrizPos())
                {
                    // Actualizar matriz
                    updateMatriz();
                }
                else
                {
                    // Si no es valido revertir movimiento
                    transform.position += new Vector3(1, 0, 0);
                }
            }

            // Mover hacia la derecha
            else if (Input.GetKeyDown(KeyCode.RightArrow) || waveout)
            {
                // Modificar posición
                transform.position += new Vector3(1, 0, 0);

                // Ver si es válido
                if (isValidMatrizPos())
                {
                    // Actualizar matriz
                    updateMatriz();
                }
                else
                {
                    // Si no es valido revertir movimiento
                    transform.position += new Vector3(-1, 0, 0);
                }
            }
            // Rotar
            else if (Input.GetKeyDown(KeyCode.UpArrow) || fist)
            //Input.GetMouseButtonDown(0) == true
            {
                transform.Rotate(0, 0, -90);

                // Ver si es válido
                if (isValidMatrizPos())
                {
                    // Actualizar matriz
                    updateMatriz();
                }
                else
                {
                    // Si no es valido revertir movimiento
                    transform.Rotate(0, 0, 90);
                }
            }

            else if (Input.GetKeyDown(KeyCode.DownArrow) || doubletap)
            {
                // Modificar posición
                transform.position += new Vector3(0, -1, 0);

                // Ver si es válido
                if (isValidMatrizPos())
                {
                    // Actualizar matriz
                    updateMatriz();
                }
                else
                {
                    // Si no es valido revertir movimiento
                    transform.position += new Vector3(0, 1, 0);

                    // Clear filled horizontal lines

                    scoreB = Matriz.deleteFullRows();
                    for (int i = 0; i < scoreB; i++)
                    {
                        string text = scoreT.text;
                        score       = int.Parse(text) + 10;
                        scoreT.text = score.ToString();
                        if ((score % 20) == 0)
                        {
                            string lev = levelT.text;
                            level       = int.Parse(lev) + 1;
                            levelT.text = level.ToString();
                        }
                        fallSpeed = fallSpeed + 2;
                    }

                    scoreB = 0;


                    // Spawn next Group
                    FindObjectOfType <Spawner>().spawnNext();


                    // Disable script
                    enabled = false;
                }
            }

            // Mover hacia abajo
            else if (Input.GetKeyDown(KeyCode.DownArrow) ||
                     Time.time - lastFall >= 0.8 || doubletap)
            {
                // Modificar posición
                transform.position += new Vector3(0, -1, 0);

                // Ver si es válido
                if (isValidMatrizPos())
                {
                    // Actualizar matriz
                    updateMatriz();
                }
                else
                {
                    // Si no es valido revertir movimiento
                    transform.position += new Vector3(0, 1, 0);

                    // Clear filled horizontal lines
                    scoreB = Matriz.deleteFullRows();
                    for (int i = 0; i < scoreB; i++)
                    {
                        string text      = scoreT.text;
                        int    lastScore = int.Parse(text);
                        score       = int.Parse(text) + 10;
                        scoreT.text = score.ToString();
                        if ((score % 20) == 0)
                        {
                            string lev = levelT.text;
                            level       = int.Parse(lev) + 1;
                            levelT.text = level.ToString();
                        }
                        fallSpeed = fallSpeed + 2;
                    }

                    scoreB = 0;


                    // Spawn next Group
                    FindObjectOfType <Spawner>().spawnNext();

                    // Disable script
                    enabled = false;
                }

                lastFall = Time.time;
            }
        }
    }
示例#37
0
	void Update() {
		lock (_lock) {
			armSynced = _myoArmSynced;
			arm = _myoArm;
			xDirection = _myoXDirection;
			if (_myoQuaternion != null) {
				transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
			}
			if (_myoAccelerometer != null) {
				accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
			}
			if (_myoGyroscope != null) {
				gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
			}
//			if (isPaired && streamEmg == Thalmic.Myo.Result.Success) {
//				emg = _myo.emgData;
//			}

			pose = _myoPose;
			unlocked = _myoUnlocked;
		}
	}
示例#38
0
    // Update is called once per frame
    void Update()
    {
        Pose pose = myo == null ? Pose.Unknown : myo.pose;

        if (pose == lastPose && updateOnChange)
        {
            return;
        }

        if (pose != lastPose)
        {
            Debug.LogError("Pose: " + pose.ToString());
        }
        lastPose = pose;

        switch (pose)
        {
        case Pose.DoubleTap:
            //onDoubleTap ();
            if (onDoubleTap != null)
            {
                onDoubleTap(this.gameObject);
            }
            break;

        case Pose.FingersSpread:
            if (onFingerSpread != null)
            {
                onFingerSpread(this.gameObject);
            }
            break;

        case Pose.Fist:
            if (onFist != null)
            {
                onFist(this.gameObject);
            }
            break;

        case Pose.Rest:
            if (onRest != null)
            {
                onRest(this.gameObject);
            }
            break;

        case Pose.Unknown:
            break;

        case Pose.WaveIn:
            if (onWaveIn != null)
            {
                onWaveIn(this.gameObject);
            }
            break;

        case Pose.WaveOut:
            if (onWaveOut != null)
            {
                onWaveOut(this.gameObject);
            }
            break;
        }
    }
示例#39
0
	void FixedUpdate ()
	{
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();
        LoadOnClick load = GetComponent<LoadOnClick>();
        // 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.WaveOut) {
                sameMovement = true;
            }
          }
        else {
          sameMovement = false;
        }



        var JointObject =  GameObject.Find("Stick");
        float x = JointObject.transform.rotation.eulerAngles.x;
        float y = JointObject.transform.rotation.eulerAngles.y;
        float z = JointObject.transform.rotation.eulerAngles.z;
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");
        float moveUp = 0;

        if (0 + xGap < x && x < 180)
        {
            moveVertical = 1;
        }
        else if (180  < x && x < 360 - xGap)
        {
            moveVertical = -1;
        }


        if (0 + yGap < y && y < 180)
        {
            moveHorizontal = 1;
        }
        else if (180  < y && y < 360 - yGap)
        {
            moveHorizontal = -1;
        }
        if (sameMovement) {
            moveUp = 30;
        }


        Vector3 movement = new Vector3 (moveHorizontal, moveUp, moveVertical);

		    rb.AddForce (movement * speed);
        if (transform.position.y < -100) {
        	SetLooseText();
        	movement = new Vector3 (0, 0, 0);
        }


        if (count < countVictory) {
			startTime += Time.deltaTime;
			setTimerText ();
		}
        if (count >= countVictory)
        {
          //Call pause function in PauseGame.cs
			pauseGame.DoPause();
			//var player =  GameObject.Find("player");
			//PauseGame pause = (PauseGame) player.GetComponent(typeof(PauseGame));
			//Debug.Log("GameObject : "+player);
			//Debug.Log (pause);
			//pause.DoPause();
		}

            if (transform.position.y < -100) {
              //Application.LoadLevel(Application.loadedLevel);
				//Call pause function in PauseGame.cs
				var player =  GameObject.Find("player");
				PauseGame pause = (PauseGame) player.GetComponent(typeof(PauseGame));
				Debug.Log("GameObject : "+player);
				Debug.Log (pause);
				pause.DoPause();
            }
        //}
    }
    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);
            }
        }
    }
    // 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);
            }
        }
    }
示例#42
0
 /// <summary>
 /// Gets the current pose.
 /// </summary>
 public Pose getCurrentPose()
 {
     curPose = thalmicMyo.pose;
     return(curPose);
 }
    // Update is called once per frame.
    void Update()
    {
        Frame frame = controller.Frame();
        //set rotation of hand to match myo
        HandList hands = frame.Hands;

        foreach (Hand hand in hands)
        {
            if (hand.IsValid)
            {
                if (isLeft == hand.IsLeft)
                {
                    // Access the ThalmicMyo component attached to the Myo object.
                    ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

                    // Update references when the pose becomes fingers spread or the q key is pressed.
                    bool updateReference = false;
                    if (thalmicMyo.pose != _lastPose)
                    {
                        _lastPose = thalmicMyo.pose;

                        if (thalmicMyo.pose == Pose.FingersSpread)
                        {
                            updateReference = true;

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

                    // 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);
                    }
                    //***insert here
                    //placeholders for key variables here. may need to edit leap motion hand script to get data?
                    Vector3 posW = new Vector3(0f, 0f, .7f);                  //hand.WristPosition.ToUnity();
                    Vector3 posS = GameObject.Find("RightShoulder").transform.position;
                    //Probably want to translate posS and posW here, according to the difference between the myo and LeapMotion values for posW. Want the two values of posW to coincide.
                    Vector3 dirLower = transform.rotation * new Vector3(0, 0, 1);                      //new Vector3 (0.0f, 0.0f, 0.0f);//I will assume both dirLower and dirUpper go toward the elbow.
                    Vector3 dirUpper = JointOrientationUpper.dirUpper;
                    dirLower = dirLower.normalized;
                    dirUpper = dirUpper.normalized;
                    Vector3 thirdSide   = posS - posW;
                    float   thetaS      = Mathf.PI - Mathf.Acos(Vector3.Dot(thirdSide, dirUpper) / (thirdSide.magnitude * dirUpper.magnitude));
                    float   thetaW      = Mathf.Acos(Vector3.Dot(thirdSide, dirLower) / (thirdSide.magnitude * dirLower.magnitude));
                    float   thetaT      = 2.0f * Mathf.PI - thetaS - thetaW;
                    float   lengthLower = Mathf.Sin(thetaS) * thirdSide.magnitude / Mathf.Sin(thetaT);
                    lengthUpper = Mathf.Sin(thetaW) * thirdSide.magnitude / Mathf.Sin(thetaT);
                    elbow       = posW + dirLower * lengthLower;
                    Vector3 center = (posW + elbow) / 2.0f;                                                            //this is the center of the lower arm
                    transform.position = center;
                    //transform.localScale = new Vector3(lengthLower, lengthLower, lengthLower);
                }
            }
        }
    }
示例#44
0
    // Update is called once per frame

    /*
     * Tamarin update za suriken :D
     * void Update () {
     *      count --;
     *      if (count == 0) {
     *              count = frameRate;
     *
     *              if (tMyo.pose == Pose.Fist) {
     *                      pathsColliders.SetActive(false);
     *                      Debug.Log ("STISNUTA");
     *                      vectors.Add (hand.transform.TransformPoint (Vector3.zero));
     *                      thrown = false;
     *                      if (lastPose != Pose.Fist )
     *                              vectors.Clear ();
     *                      //vectors.Clear ();
     *                      //frameRate = 1;
     *              } else {
     *                      //Debug.Log ("PUSTENA");
     *                      if (lastPose == Pose.Fist && thrown == false) {
     *                              Debug.Log ("BACANJE");
     *                              thrown = true;
     *                              lastPose = tMyo.pose;
     *                              if (vectors.Count >= 3) {
     *                                      while (vectors.Count>40)
     *                                              vectors.RemoveAt (0);
     *                                      calculateShurikenPath();
     *                                      //Koeficijenti.calculatePath (vectors.ToArray (), sphere, shuriken, false, pathsColliders);
     *                                      br++;
     *
     *                                      Debug.Log ("baca suriken " + br);
     *                              }
     *                              vectors.Clear ();
     *                              //int x = pathsColliders.transform.childCount;
     *                              //tangent(shuriken, pathsColliders.transform.GetChild(x-5).position, pathsColliders.transform.GetChild(x-2).position, 5f);
     *                              //frameRate = 4;
     *                              pathsColliders.SetActive(true);
     *                      }else{
     *                              vectors.Add(hand.transform.TransformPoint(Vector3.zero));
     *                              if (vectors.Count > 6){
     *                                      vectors.RemoveAt(0);
     *                              }
     *                              if (vectors.Count > 3){
     *                                      Koeficijenti.followPath(vectors.ToArray(), sphere, true, pathsColliders);
     *                              }
     *                      }
     *              }
     *              lastPose = tMyo.pose;
     *      }
     * }*/

    void Update()
    {
        count--;
        if (count == 0)
        {
            count = frameRate;

            vectors.Add(hand.transform.TransformPoint(Vector3.zero));
            if (vectors.Count > 10)
            {
                vectors.RemoveAt(0);
            }
            if (vectors.Count > 3)
            {
                Koeficijenti.followPath(vectors.ToArray(), sphere, true, pathsColliders);
            }

            if (tMyo.pose == Pose.Fist)
            {
                //pathsColliders.SetActive(false);
                count = 1;
                Debug.Log("STISNUTA");
                //vectors.Add (hand.transform.TransformPoint (Vector3.zero));
                thrown = false;
            }
            else
            {
                //Debug.Log ("PUSTENA");
                if (lastPose == Pose.Fist && thrown == false)
                {
                    Debug.Log("BACANJE");
                    thrown   = true;
                    lastPose = tMyo.pose;
                    if (vectors.Count >= 3)
                    {
                        while (vectors.Count > 40)
                        {
                            vectors.RemoveAt(0);
                        }
                        calculateShurikenPathRed();
                        //Koeficijenti.calculatePath (vectors.ToArray (), sphere, shuriken, false, pathsColliders);
                        br++;

                        Debug.Log("baca suriken " + br);
                    }
                    vectors.Clear();
                    //pathsColliders.SetActive(true);
                }
                else
                {
                    /*vectors.Add(hand.transform.TransformPoint(Vector3.zero));
                     * if (vectors.Count > 10){
                     *      vectors.RemoveAt(0);
                     * }
                     * if (vectors.Count > 3){
                     *      Koeficijenti.followPath(vectors.ToArray(), sphere, true, pathsColliders);
                     * }*/
                }
            }
            lastPose = tMyo.pose;
        }
    }
示例#45
0
    void Update()
    {
        lock (_lock) {
            armSynced  = _myoArmSynced;
            arm        = _myoArm;
            xDirection = _myoXDirection;
            if (_myoQuaternion != null)
            {
                transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
            }
            if (_myoAccelerometer != null)
            {
                accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
            }
            if (_myoGyroscope != null)
            {
                gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
            }
            if (isPaired && streamEmg == Thalmic.Myo.Result.Success)
            {
                emg = _myo.emgData;

                //print ("EMG stream received: " + emg.Length); // 8

                if (emg.Length == 8)
                {
                    //print (emg[0] + " " + emg[1] + " " + emg[2] + " " + emg[3] + " " + emg[4] + " " + emg[5] + " " + emg[6] + " " + emg[7]);
                    //Savecsv();

                    /*
                     *
                     * string filePath = @"Saved_data.csv";
                     * string delimiter = ",";
                     *
                     * string[][] output = new string[][]{
                     *      new string[]{emg[0].ToString()},
                     *      new string[]{emg[1].ToString()},
                     *      new string[]{emg[2].ToString()},
                     *      new string[]{emg[3].ToString()},
                     *      new string[]{emg[4].ToString()},
                     *      new string[]{emg[5].ToString()},
                     *      new string[]{emg[6].ToString()},
                     *      new string[]{emg[7].ToString()},
                     *      new string[]{"end"}
                     * };
                     * int length = output.GetLength(0);
                     * StringBuilder sb = new StringBuilder();
                     * for (int index = 0; index < length; index++)
                     *      sb.AppendLine(string.Join(delimiter, output[index]));
                     *
                     * File.WriteAllText(filePath, sb.ToString());
                     */
                }
                //foreach (int emgval in emg) { // doesn't work
                //	print ("emgval" + emgval);
                //}
            }

            pose     = _myoPose;
            unlocked = _myoUnlocked;
        }
    }
 void myo_OnPoseChange(object sender, Thalmic.Myo.PoseEventArgs e)
 {
     lock (_lock) {
         _myoPose = e.Pose;
     }
 }
    // 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);
                    //}
                    //}
                }
            }
        }
    }
示例#48
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);
            }
        }
    }
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();

        // Update references when the pose becomes fingers spread or the q key is pressed.
        bool updateReference = false;
        if (thalmicMyo.pose != _lastPose) {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.FingersSpread) {
                updateReference = true;

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

        // 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),
                forwardDirection.transform.forward
                //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);
        }

        // TODO: call Pinn in other function IF reference changed
        if (updateReference) {
            MyoJoystick joystickScript = box.GetComponent<MyoJoystick>();
            joystickScript.PinOrigin();
        }
    }
    // 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);
                    //}
                    //}
                }

            }
        }
    }
    void Update()
    {
        if (timerActive)
        {
            powerupTimer -= Time.deltaTime;
            Debug.Log(powerupTimer);
        }
        if (powerupTimer <= 0)
        {
            powerupTimer   = 5f;
            Time.timeScale = 1.1f;
            powerUpCanvas.GetComponent <CanvasGroup>().alpha = 0;

            timerActive = false;
            spawner.GetComponent <FruitSpawner>().setPowerUpReady(false);
        }
        updateReference = false;

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

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

            if (thalmicMyo.pose == Pose.DoubleTap)
            {
                updateReference = true;

                ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }

            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                BoxCollider2D  playCollider = play.GetComponent <BoxCollider2D>();
                SphereCollider sc           = transform.GetComponent <SphereCollider>();

                // If in position of start button
                if (playCollider.bounds.Intersects(sc.bounds))
                {
                    // Start game
                    mainMenuPanel.GetComponent <MainMenuScript>().startGame();
                }

                BoxCollider2D tutCollider = btnTutorial.GetComponent <BoxCollider2D>();

                // IF in position of tutorial button
                if (tutCollider.bounds.Intersects(sc.bounds) && !gameStarted)
                {
                    mainMenuPanel.GetComponent <MainMenuScript>().showInstructions();
                }

                // If in position of main menu button, and game is over
                bool          gameOver     = spawner.GetComponent <FruitSpawner>().getGameOver();
                bool          tutEnabled   = mainMenuPanel.GetComponent <MainMenuScript>().getTutEnabled();
                BoxCollider2D mainMenuColl = tutorialPanel.transform.GetChild(0).GetComponent <BoxCollider2D>();
                if (mainMenuColl.bounds.Intersects(sc.bounds))
                {
                    if (gameOver || tutEnabled)
                    {
                        mainMenuPanel.GetComponent <MainMenuScript>().showMainMenu();
                    }
                }
            }

            if (thalmicMyo.pose == Pose.Fist)
            {
                if (spawner.GetComponent <FruitSpawner>().isPowerupReady())
                {
                    Time.timeScale = .75f;
                    // PowerUp Timer start
                    powerupTimer -= Time.deltaTime;
                    // Make canvas visible for effect
                    scoreText.color = Color.white;
                    timerActive     = true;
                    spawner.GetComponent <FruitSpawner>().setPowerUpReady(false);
                    spawner.GetComponent <FruitSpawner>().setPowerCombo(0);

                    powerUpCanvas.GetComponent <CanvasGroup>().alpha = 1;
                }
            }
        }
        if (Input.GetKeyDown("r"))
        {
            updateReference = true;
        }

        if (updateReference)
        {
            referenceVector = new Vector2(myo.transform.forward.x * -1 * 200, myo.transform.forward.y * 70);
        }
        // Here the anti-roll and yaw rotations are applied to the myo Armband's forward direction to yield
        // the orientation of the joint.
        transform.position = new Vector2((myo.transform.forward.x * -1 * 200) - referenceVector.x, myo.transform.forward.y * 70 - referenceVector.y);
    }
示例#52
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);
                }
            }
        }
    }
    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.

        // Next two if loops checks which key is pressed for each frame. It takes Input.inputString to see which key
        // If no key is pressed then it will contain an empty string. We check for this.
        // This is necessary since the way EPOC is implemented is by EmoKey. A key is being pressed once every 0.2sec. This is captured.
        //Writes the first input from keyboard to _key
        if (string.IsNullOrEmpty(_key))
        {
            _key = Input.inputString;
        }
        // if the new input is not empty then it must be a new key
        if (!string.IsNullOrEmpty(Input.inputString))
        {
            _key = Input.inputString;
        }

        Debug.Log(_key);
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            // Vibrate the Myo armband when a fist is made.
            if (thalmicMyo.pose == Pose.Fist)
            {
                if (_key == "u")
                {
                    _side = 3;
                }
                // First test of "key active" for EEG headset. This works.
                if (_key == "t")
                {
                    _side = 10;
                }
                if (_key == "y")
                {
                    _side = 7;
                }
            }
            else if (thalmicMyo.pose == Pose.WaveIn)
            {
                if (_key == "u")
                {
                    _side = 5;
                }
                // First test of "key active" for EEG headset. This works.
                if (_key == "t")
                {
                    _side = 1;
                }
                if (_key == "y")
                {
                    _side = 9;
                }
            }
            else if (thalmicMyo.pose == Pose.WaveOut)
            {
                if (_key == "u")
                {
                    _side = 6;
                }
                // First test of "key active" for EEG headset. This works.
                if (_key == "t")
                {
                    _side = 2;
                }
                if (_key == "y")
                {
                    _side = 8;
                }
            }
            else if (thalmicMyo.pose == Pose.DoubleTap)
            {
                //_side = 4;
                //ExtendUnlockAndNotifyUserAction(thalmicMyo);
            }
            else if (thalmicMyo.pose == Pose.FingersSpread)
            {
                _side = 4;
            }
            else if (thalmicMyo.pose == Pose.Rest)
            {
                _side = 0;
            }
        }


//		The following constaints the animation until a specific time (frame)
//		This stops the animation from completing or going into a wrong playtime-frame
        // Fist
        if (animation["Fist"].time > 0.65f)
        {
            animation["Fist"].time = 0.65f;
        }
        else if (animation["Fist"].time < 0.1f)
        {
            animation["Fist"].time = 0.1f;
        }
        // Cylindrical
        else if (animation["Cylindrical"].time > 0.7f)
        {
            animation["Cylindrical"].time = 0.7f;
        }
        else if (animation["Cylindrical"].time < 0.1f)
        {
            animation["Cylindrical"].time = 0.1f;
        }
        // Rotate Left
        else if (animation["RotateLeft"].time > 0.65f)
        {
            animation["RotateLeft"].time = 0.65f;
        }
        else if (animation["RotateLeft"].time < 0.1f)
        {
            animation["RotateLeft"].time = 0.1f;
            // Rotate Right
        }
        else if (animation["RotateRight"].time > 0.65f)
        {
            animation["RotateRight"].time = 0.65f;
        }
        else if (animation["RotateRight"].time < 0.1f)
        {
            animation["RotateRight"].time = 0.1f;
            // 2-finger pinch
        }
        else if (animation["TwoPinch"].time > 0.7f)
        {
            animation["TwoPinch"].time = 0.7f;
        }
        else if (animation["TwoPinch"].time < 0.1f)
        {
            animation["TwoPinch"].time = 0.1f;
            // 1-finger pinch
        }
        else if (animation["Pinch"].time > 0.7f)
        {
            animation["Pinch"].time = 0.7f;
        }
        else if (animation["Pinch"].time < 0.1f)
        {
            animation["Pinch"].time = 0.1f;
            // Wave in
        }
        else if (animation["WaveIn"].time > 0.7f)
        {
            animation["WaveIn"].time = 0.7f;
        }
        else if (animation["WaveIn"].time < 0.1f)
        {
            animation["WaveIn"].time = 0.1f;
            // Wave out
        }
        else if (animation["WaveOut"].time > 0.7f)
        {
            animation["WaveOut"].time = 0.7f;
        }
        else if (animation["WaveOut"].time < 0.1f)
        {
            animation["WaveOut"].time = 0.1f;
            // Point with index finger
        }
        else if (animation["Point"].time < 0.1f)
        {
            animation["Point"].time = 0.1f;
        }
        else if (animation ["Point"].time > 0.70f)
        {
            animation["Point"].time = 0.70f;
        }

        // The following plays the animations based on the input.
        // CrossFade is used in order to blend between animations
        // Speed can be adjusted to play faster or slower. Higher number = faster
        // _side == 4 is the one going from any grip to idle

        if (_side == 3)
        {
//			_fist_out_stop = false;
            animation["Fist"].speed = 0.6f;
            animation.CrossFade("Fist");
            Debug.Log(animation["Fist"].time + " - FIST IN TIME");

            //box.transform.Translate(Vector3.left * Time.deltaTime);
        }
        else if (_side == 4)
        {
            _fist_stop = false;
            animation["Fist"].speed = -0.6f;
            animation.CrossFade("Fist");
            Debug.Log(animation["Fist"].time + " - POSE OUT TIME");
        }
        else if (_side == 1)
        {
            _point_out_stop = false;

            animation["RotateLeft"].speed = 0.6f;
            animation.CrossFade("RotateLeft");
            Debug.Log(animation["RotateLeft"].time + " - ROTATE LEFT TIME");
        }
        else if (_side == 2)
        {
            animation["RotateRight"].speed = 0.6f;
            animation.CrossFade("RotateRight");
            Debug.Log(animation["RotateRight"].time + " - ROTATE RIGHT TIME");
        }
        else if (_side == 5)
        {
            animation["WaveIn"].speed = 0.6f;
            animation.CrossFade("WaveIn");
            Debug.Log(animation["WaveIn"].time + " - WaveIn TIME");
        }
        else if (_side == 6)
        {
            animation["WaveOut"].speed = 0.6f;
            animation.CrossFade("WaveOut");
            Debug.Log(animation["WaveOut"].time + " - WAVE OUT TIME");
        }
        else if (_side == 7)
        {
            animation["Point"].speed = 0.6f;
            animation.CrossFade("Point");
            Debug.Log(animation["Point"].time + " - POINT TIME");
        }
        else if (_side == 8)
        {
            animation["TwoPinch"].speed = 0.6f;
            animation.CrossFade("TwoPinch");
            Debug.Log(animation["TwoPinch"].time + " - TWO PINCH TIME");
        }
        else if (_side == 9)
        {
            animation["Pinch"].speed = 0.6f;
            animation.CrossFade("Pinch");
            Debug.Log(animation["Pinch"].time + " - PINCH TIME");
        }
        else if (_side == 10)
        {
            animation["Cylindrical"].speed = 0.6f;
            animation.CrossFade("Cylindrical");
            Debug.Log(animation["Cylindrical"].time + " - CYLINDRICAL TIME");
        }
        else
        {
            animation["Fist"].speed        = 0.0f;
            animation["Point"].speed       = 0.0f;
            animation["WaveIn"].speed      = 0.0f;
            animation["WaveOut"].speed     = 0.0f;
            animation["RotateLeft"].speed  = 0.0f;
            animation["RotateRight"].speed = 0.0f;
            animation["TwoPinch"].speed    = 0.0f;
            animation["Pinch"].speed       = 0.0f;
            animation["Cylindrical"].speed = 0.0f;
        }
    }
示例#54
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();
    }
示例#55
0
    // Update is called once per frame.
    void Update()
    {
        // Access the ThalmicMyo component attached to the Myo object.
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

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

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

            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                updateReference = true;

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

        // 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);
        }
    }
示例#56
0
    // Update is called once per frame
    void Update()
    {
        /*
         * // Get the myo associated with this GameObject
         * ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();
         *
         * // Reset orientation if requested
         * if (thalmicMyo.pose != _lastPose) {
         *      _lastPose = thalmicMyo.pose;
         *
         *      if (thalmicMyo.pose == Pose.FingersSpread) {
         *              referenceOrientation = thalmicMyo.transform.rotation.eulerAngles;
         *              ExtendUnlockAndNotifyUserAction (thalmicMyo);
         *              Debug.Log ("Resetting orientation!");
         *      }
         * }
         *
         * Vector3 myoTransform = thalmicMyo.transform.rotation.eulerAngles;	// Raw transform from myo data
         * Vector3 normalizedTransform = myoTransform - referenceOrientation;	// Normalized to the reference orientation
         * //Debug.Log (normalizedTransform);
         *
         * Quaternion x = Quaternion.AngleAxis (90 + normalizedTransform.x, Vector3.right);     // Left-right
         * Quaternion y = Quaternion.AngleAxis (normalizedTransform.y, Vector3.back);           // Up-down
         * Quaternion z = Quaternion.AngleAxis (normalizedTransform.z, Vector3.up);             // Rotation (twisting arm)
         *
         * // Set the transformation to be equal to the myo's data.
         * transform.rotation = x * y * z;
         */
        ThalmicMyo thalmicMyo = myo.GetComponent <ThalmicMyo> ();

        // Resetting capabilities
        RightStorage.shouldUpdate = false;
        if (thalmicMyo.pose != _lastPose)
        {
            _lastPose = thalmicMyo.pose;

            if (thalmicMyo.pose == Pose.FingersSpread)
            {
                ExtendUnlockAndNotifyUserAction(thalmicMyo);
                RightStorage.shouldUpdate = true;
            }
        }

        if (RightStorage.shouldUpdate)
        {
            _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);

        transform.rotation = _antiYaw * antiRoll * Quaternion.LookRotation(myo.transform.forward);

        standardPosition   = RightStorage.upperArmEndPosition;
        transform.position = standardPosition + (transform.rotation * Vector3.forward * length);
    }
示例#57
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);
        //}
    }
示例#58
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.
            }
        }
    }
示例#59
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);
            }
        }
    }
 void Update()
 {
     armSynced = _myoArmSynced;
     if (armSynced)
     {
         syncText.text = "Myo is synced!";
     }
     else
     {
         syncText.text = "Perform the sync motion.";
     }
     arm = _myoArm;
     xDirection = _myoXDirection;
     if (_myoQuaternion != null) {
         transform.localRotation = new Quaternion(_myoQuaternion.Y, _myoQuaternion.Z, -_myoQuaternion.X, -_myoQuaternion.W);
     }
     if (_myoAccelerometer != null) {
         accelerometer = new Vector3(_myoAccelerometer.Y, _myoAccelerometer.Z, -_myoAccelerometer.X);
     }
     if (_myoGyroscope != null) {
         gyroscope = new Vector3(_myoGyroscope.Y, _myoGyroscope.Z, -_myoGyroscope.X);
     }
     pose = _myoPose;
     if ((pose == Pose.Fist) && (armSynced)) {
         fistText.text = "Curl or Punch";
     }
     else
     {
         fistText.text = "Make sure the myo is synced and make a fist!";
     }
     unlocked = _myoUnlocked;
 }