// Update is called once per frame void Update() { if (notifSwitchSet) { Device.ConnectionStatus status = dev.device.getConnectionStatus(); if (status == Device.ConnectionStatus.Connected) { dev.device.setNotification((uint)(gf.DataNotifFlags.DNF_EMG_RAW | gf.DataNotifFlags.DNF_QUATERNION)); notifSwitchSet = true; } } GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); quater = gforceDevice.quater; // Check if the gesture has changed since last update. if (gforceDevice.gesture != lastGesture) { lastGesture = gforceDevice.gesture; switch (lastGesture) { case Gesture.Relax: // seems Relax is always coming fast, so setup a delay timer, // only when Relax keeps for a while, then render relaxMaterial. //GetComponent<Renderer>().material = relaxMaterial; relaxStart = DateTime.Now; break; case Gesture.Shoot: GetComponent <Renderer>().material = shootMaterial; break; case Gesture.Undefined: GetComponent <Renderer>().material = undefinedMaterial; break; default: GetComponent <Renderer>().material = otherMaterial; break; } } else { if (Gesture.Relax == lastGesture && GetComponent <Renderer>().material != relaxMaterial) { TimeSpan ts = DateTime.Now - relaxStart; if (ts.Milliseconds > RelaxDelay) { GetComponent <Renderer>().material = relaxMaterial; } } } }
// Update is called once per frame. void Update() { GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); lastGesture = gforceDevice.gesture; quater = gforceDevice.quater; transform.rotation = quater; }
// Update is called once per frame. void Update() { GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); //Get gforce data lastGesture = gforceDevice.gesture; //Get Gesture quater = gforceDevice.quater; //Get Quater Quater = new Quaternion(quater.y, -quater.x, quater.z, quater.w); //Correct rotation direction transform.rotation = Quater; //Control arm rotation }
// Update is called once per frame void Update() { GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); quater = gforceDevice.quater; // Check if the gesture has changed since last update. if (gforceDevice.gesture != lastGesture) { lastGesture = gforceDevice.gesture; switch (lastGesture) { case Gesture.Relax: // seems Relax is always coming fast, so setup a delay timer, // only when Relax keeps for a while, then render relaxMaterial. //GetComponent<Renderer>().material = relaxMaterial; relaxStart = DateTime.Now; break; case Gesture.Shoot: GetComponent <Renderer>().material = shootMaterial; break; case Gesture.Undefined: GetComponent <Renderer>().material = undefinedMaterial; break; default: GetComponent <Renderer>().material = otherMaterial; break; } } else { if (Gesture.Relax == lastGesture && GetComponent <Renderer>().material != relaxMaterial) { TimeSpan ts = DateTime.Now - relaxStart; if (ts.Milliseconds > RelaxDelay) { GetComponent <Renderer>().material = relaxMaterial; } } } }
// Update is called once per frame void Update() { if (!notifSwitchSet) { Device.ConnectionStatus status = dev.device.getConnectionStatus(); if (status == Device.ConnectionStatus.Connected) { dev.device.setNotification((uint)(gf.DataNotifFlags.DNF_EMG_RAW | gf.DataNotifFlags.DNF_QUATERNION)); notifSwitchSet = true; } } GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); quater = gforceDevice.quater; //Get gForce quater Rawdata = gforceDevice.EMGRawdata; //Get gForce Rawdata }
//Show Gesture Name void OnGUI() { GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); gestures = gforceDevice.gesture; switch (gestures) { case Gesture.Relax: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "Relax"); break; case Gesture.Shoot: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "Shoot"); break; case Gesture.Fist: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "Fist"); break; case Gesture.SpreadFingers: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "SpreadFingers"); break; case Gesture.WaveIn: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "WaveIn"); break; case Gesture.WaveOut: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "WaveOut"); break; case Gesture.Pinch: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "Pinch"); break; case Gesture.Undefined: GUI.Label(new Rect(12, 38, Screen.width, Screen.height), "Undefined"); break; default: break; } }
//Control arm rotation //isright : Judgment is left hand or right hand public void ArmQuaterControl(bool isright) { GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); //Get gforce data quater = gforceDevice.quater; //Get Quater if (isright) { //Right Arm Quater = new Quaternion(-quater.z, quater.x, -quater.y, quater.w); //Correct rotation direction Hand_right.transform.localRotation = Quater; } else { //Left Arm Quater = new Quaternion(quater.z, -quater.x, -quater.y, quater.w); //Correct rotation direction Hand_left.transform.rotation = Quater; } }
//Control arm rotation //isright : Judgment is left hand or right hand public void ArmQuaterControl(bool isright) { GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); //Get gforce data quater = gforceDevice.quater; //Get Quater rawdata = gforceDevice.EMGRawdata; //Get EMGRawdata BendAngle = GetBendAngle(isright, ((rawdata[7] + rawdata[15]) / 2)); if (isright) { //Right Arm Hand_right_A.transform.localRotation = new Quaternion(quater.y, -quater.x, quater.z, quater.w); //Correct rotation direction Hand_right_B.transform.localRotation = Quaternion.Euler(Hand_right_A.transform.localRotation.x, BendAngle, Hand_right_A.transform.localRotation.z); //Control arm bending } else { //Left Arm Hand_left_A.transform.rotation = new Quaternion(-quater.y, quater.x, -quater.z, -quater.w); //Correct rotation direction Hand_left_B.transform.localRotation = Quaternion.Euler(Hand_left_A.transform.localRotation.x, BendAngle, Hand_left_A.transform.localRotation.z); //Control arm bending } }
// Draw some basic instructions. void OnGUI() { GUI.skin.label.fontSize = 20; GForceHub hub = GForceHub.instance; // Access the attached object. GForceDevice device = gforce.GetComponent <GForceDevice>(); if (null != device) { if (!string.IsNullOrEmpty(hub.lastlog)) { log = hub.lastlog; } GUI.Label(new Rect(12, 8, Screen.width, Screen.height), log); } else { GUI.Label(new Rect(12, 8, Screen.width, Screen.height), "Loading failed." ); } }
//Gesture Control //isright : Judgment is left hand or right hand public void GestureControl(bool isright) { GForceDevice gforceDevice = gforce.GetComponent <GForceDevice>(); if (gforceDevice.gesture != lastGesture) { lastGesture = gforceDevice.gesture; switch (lastGesture) { case Gesture.Relax: // seems Relax is always coming fast, so setup a delay timer, // only when Relax keeps for a while, then render relaxMaterial. //GetComponent<Renderer>().material = relaxMaterial; relaxStart = DateTime.Now; GestureAnimationControl(isright, (int)Gesturex.Relax); break; case Gesture.Fist: GestureAnimationControl(isright, (int)Gesturex.Fist); break; case Gesture.SpreadFingers: GestureAnimationControl(isright, (int)Gesturex.Spread); break; case Gesture.WaveIn: GestureAnimationControl(isright, (int)Gesturex.WaveIn); break; case Gesture.WaveOut: GestureAnimationControl(isright, (int)Gesturex.WaveOut); break; case Gesture.Pinch: GestureAnimationControl(isright, (int)Gesturex.Pinch); break; case Gesture.Shoot: GestureAnimationControl(isright, (int)Gesturex.Shoot); break; case Gesture.Undefined: GestureAnimationControl(isright, (int)Gesturex.Relax); break; default: break; } } else { if (Gesture.Relax == lastGesture) { TimeSpan ts = DateTime.Now - relaxStart; if (ts.Milliseconds > RelaxDelay) { GestureAnimationControl(isright, (int)Gesturex.Relax); } } } }