/// <summary> /// Close G4 when application quits. /// </summary> void OnApplicationQuit() { if ((RGConn == true) || (LGConn == true)) { CyberGloveUnityPlugin.Fini(); } }
/// <summary> /// Initialize the cybergloves, check connection in DCU and allocate. /// </summary> void Start() { //ClearConsole (); for (int i = 0; i < MAX_GLOVES; i++) { m_Gloves [i] = new CyberGlove(); } RGConn = CyberGloveUnityPlugin.InitRightGrasp(); Debug.Log(RGConn); LGConn = CyberGloveUnityPlugin.InitLeftGrasp(); Debug.Log(LGConn); if (!RGConn && !LGConn) { Debug.Log("DCU is not running or gloves not connected.\nIf connected check naming convention - RightGrasp and LeftGrasp. Devices must be added as cyberglove devices in DCU."); } else if (!RGConn && LGConn) { Debug.Log("RightGrasp not connected.\nIf connected check naming convention - RightGrasp. Device must be added as a cyberglove device in DCU."); } else if (RGConn && !LGConn) { Debug.Log("LeftGrasp not connected.\nIf connected check naming convention - LeftGrasp. Device must be added as a cyberglove device in DCU."); } else { Debug.Log("Nice!!\nPress Space to move hands down"); } }
/// <summary> /// Update the glove data once per frame. /// </summary> void Update() { // update glove data uint numGlovesEnabled = 0; CyberGloveUnityPlugin.CyberGloveData cd = new CyberGloveUnityPlugin.CyberGloveData(); cd.palmPos = new Vector3(0.0f, 0.0f, 0.0f); cd.palmRot_quat = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); for (int i = 0; i < MAX_GLOVES; i++) { if (m_Gloves[i] != null) { if (i == 0) // GLOVE 0 IS TAKEN AS RIGHT GLOVE { if (RGConn == true) { CyberGloveUnityPlugin.UpdateRightGrasp(); float[] palmPos_arr = { 0.0f, 0.0f, 0.0f }; float[] palmRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f }; CyberGloveUnityPlugin.GetPalmsPositionRT(palmPos_arr); cd.palmPos.Set(palmPos_arr[0], palmPos_arr[1], palmPos_arr[2]); cd.which_hand = (int)CyberGloveHandedness.RIGHT; CyberGloveUnityPlugin.GetPalmsRotationRT(palmRot_arr); cd.palmRot_quat.Set(palmRot_arr[0], palmRot_arr[1], palmRot_arr[2], palmRot_arr[3]); for (int finger = 0; finger < 5; finger++) { for (int joint = 0; joint < 4; joint++) { float[] fingerJointPos_arr = { 0.0f, 0.0f, 0.0f }; float[] fingerJointRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f }; CyberGloveUnityPlugin.GetFingersPositionRT(finger, joint, fingerJointPos_arr); cd.fingerJointPos[finger, joint].Set(fingerJointPos_arr[0], fingerJointPos_arr[1], fingerJointPos_arr[2]); CyberGloveUnityPlugin.GetFingersRotationRT(finger, joint, fingerJointRot_arr); cd.fingerJointRot_quat[finger, joint].Set(fingerJointRot_arr[0], fingerJointRot_arr[1], fingerJointRot_arr[2], fingerJointRot_arr[3]); } } m_Gloves[i].Update(ref cd); m_Gloves[i].SetEnabled(true); numGlovesEnabled++; } else { m_Gloves[i].SetEnabled(false); } } else if (i == 1) // GLOVE 1 IS TAKEN AS LEFT GLOVE { if (LGConn == true) { CyberGloveUnityPlugin.UpdateLeftGrasp(); float[] palmPos_arr = { 0.0f, 0.0f, 0.0f }; float[] palmRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f }; CyberGloveUnityPlugin.GetPalmsPositionLT(palmPos_arr); cd.palmPos.Set(palmPos_arr[0], palmPos_arr[1], palmPos_arr[2]); cd.which_hand = (int)CyberGloveHandedness.LEFT; CyberGloveUnityPlugin.GetPalmsRotationLT(palmRot_arr); cd.palmRot_quat.Set(palmRot_arr[0], palmRot_arr[1], palmRot_arr[2], palmRot_arr[3]); for (int finger = 0; finger < 5; finger++) { for (int joint = 0; joint < 4; joint++) { float[] fingerJointPos_arr = { 0.0f, 0.0f, 0.0f }; float[] fingerJointRot_arr = { 0.0f, 0.0f, 0.0f, 1.0f }; CyberGloveUnityPlugin.GetFingersPositionLT(finger, joint, fingerJointPos_arr); cd.fingerJointPos[finger, joint].Set(fingerJointPos_arr[0], fingerJointPos_arr[1], fingerJointPos_arr[2]); CyberGloveUnityPlugin.GetFingersRotationLT(finger, joint, fingerJointRot_arr); cd.fingerJointRot_quat[finger, joint].Set(fingerJointRot_arr[0], fingerJointRot_arr[1], fingerJointRot_arr[2], fingerJointRot_arr[3]); } } m_Gloves[i].Update(ref cd); m_Gloves[i].SetEnabled(true); numGlovesEnabled++; } else { m_Gloves[i].SetEnabled(false); } } } } }
// <summary> /// Stop Active Finger/Palm Motor after 1 second /// </summary> public bool StopActuatorMotor(int hand, int finger) { bool result = CyberGloveUnityPlugin.StopActuator(hand, finger); return(result); }
// <summary> /// Actuate Finger/Palm Motors /// </summary> public bool SetActuatorMotor(int hand, int finger, double amplitude) { bool result = CyberGloveUnityPlugin.SetActuator(hand, finger, amplitude); return(result); }