// Update is called once per frame void Update() { if (MiddleVR.VRDeviceMgr != null) { // cluster client won't get the joystick if it's at Start() joy = MiddleVR.VRDeviceMgr.GetJoystickByIndex(0); if (joy != null) IsJoystickConnected = true; } if (IsJoystickConnected) { Axis0Value = joy.GetAxisValue(0); Axis1Value = joy.GetAxisValue(1); Axis2Value = joy.GetAxisValue(2); Axis3Value = joy.GetAxisValue(3); Axis4Value = joy.GetAxisValue(4); Axis5Value = joy.GetAxisValue(5); Axis6Value = joy.GetAxisValue(6); Axis7Value = joy.GetAxisValue(7); ButtonA_Pressed = joy.IsButtonPressed(0); ButtonB_Pressed = joy.IsButtonPressed(1); ButtonX_Pressed = joy.IsButtonPressed(2); ButtonY_Pressed = joy.IsButtonPressed(3); Button4_Pressed = joy.IsButtonPressed(4); Button5_Pressed = joy.IsButtonPressed(5); Button6_Pressed = joy.IsButtonPressed(6); Button7_Pressed = joy.IsButtonPressed(7); ButtonA_ToggleRelease = joy.IsButtonToggled(0); ButtonB_ToggleRelease = joy.IsButtonToggled(1); ButtonX_ToggleRelease = joy.IsButtonToggled(2); ButtonY_ToggleRelease = joy.IsButtonToggled(3); Button4_ToggleRelease = joy.IsButtonToggled(4); Button5_ToggleRelease = joy.IsButtonToggled(5); Button6_ToggleRelease = joy.IsButtonToggled(6); Button7_ToggleRelease = joy.IsButtonToggled(7); Button8_ToggleRelease = joy.IsButtonToggled(8); Button9_ToggleRelease = joy.IsButtonToggled(9); //********** Toggling WandRay Visiblity BEGIN ********// // if (Button5_ToggleRelease) { // WandRay = GameObject.Find("WandRay"); // WandCube = GameObject.Find("WandCube"); // if (WandRay.renderer!=null) { // WandRay.renderer.enabled=!WandRay.renderer.enabled; // WandCube.renderer.enabled=!WandCube.renderer.enabled; // } // } //********** Toggling WandRay Visiblity END ********// } // if (Weapon == null) { // Weapon = GameObject.Find("main_weapon001"); // } // else { //// Weapon.transform.localPosition = //// new Vector3(WeaponDisplacement,Weapon.transform.localPosition.y, Weapon.transform.localPosition.z); // } }
void Start() { r1 = MiddleVR.VRDeviceMgr.GetJoystick (0); r2 = MiddleVR.VRDeviceMgr.GetJoystick (1); obj = GameObject.Find ("Cube"); tracker = GameObject.Find ("HandNode"); }
void Start() { // Grab all controlers... leftJoystick = MiddleVR.VRDeviceMgr.GetJoystickByIndex(0); rightJoystick = MiddleVR.VRDeviceMgr.GetJoystickByIndex(1); leftTracker = MiddleVR.VRDeviceMgr.GetTracker(0); rightTracker = MiddleVR.VRDeviceMgr.GetTracker(1); leftTrigger = leftJoystick.IsButtonPressed(0); rightTrigger = rightJoystick.IsButtonPressed(0); }
void Start() { r1 = MiddleVR.VRDeviceMgr.GetJoystick(0); r2 = MiddleVR.VRDeviceMgr.GetJoystick(1); obj = GameObject.Find("Cube"); tracker = GameObject.Find("HandNode"); }
private void TestDevices() { vrTracker tracker = null; vrJoystick joy = null; vrAxis axis = null; vrButtons buttons = null; var deviceMgr = MiddleVR.VRDeviceMgr; // Getting a reference to different device types if (deviceMgr != null) { tracker = deviceMgr.GetTracker("VRPNTracker0.Tracker0"); joy = deviceMgr.GetJoystickByIndex(0); axis = deviceMgr.GetAxis("VRPNAxis0.Axis"); buttons = deviceMgr.GetButtons("VRPNButtons0.Buttons"); } // Getting tracker data if (tracker != null) { MVRTools.Log("TrackerX : " + tracker.GetPosition().x()); } // Testing joystick button if (joy != null && joy.IsButtonPressed(0)) { MVRTools.Log("Joystick!"); } // Testing axis value if (axis != null && axis.GetValue(0) > 0) { MVRTools.Log("Axis Value: " + axis.GetValue(0)); } // Testing button state if (buttons != null) { if (buttons.IsToggled(0)) { MVRTools.Log("Button 0 pressed !"); } if (buttons.IsToggled(0, false)) { MVRTools.Log("Button 0 released !"); } } }
// Use this for initialization void Start() { vrDeviceManager deviceMgr = MiddleVR.VRDeviceMgr; // Get XBOX Controller for (uint i=0, iEnd=deviceMgr.GetJoysticksNb(); i<iEnd; ++i) { vrJoystick joystick = deviceMgr.GetJoystick(i); if (joystick.GetName().StartsWith("Controller")) { m_Joystick = joystick; break; } } }
void Start() { rigidbody.freezeRotation=true; Physics.gravity = new Vector3(0, -gravity, 0); //RAZER########################### leftHand = GameObject.FindWithTag("LeftHand"); rightHand = GameObject.FindWithTag("RightHand"); leftJoy = MiddleVR.VRDeviceMgr.GetJoystickByIndex(0); rightJoy = MiddleVR.VRDeviceMgr.GetJoystickByIndex(1); StartCoroutine("Woohoo",0.5); }
// Update is called once per frame void Update() { Collider hit = GetClosestHit(); if (hit != null) { //print("Closest : " + hit.name); if (CurrentObject != hit.gameObject && ObjectInHand == null) { //MiddleVRTools.Log("Enter other : " + hit.name); HighlightObject(CurrentObject, false); CurrentObject = hit.gameObject; HighlightObject(CurrentObject, true); //MiddleVRTools.Log("Current : " + CurrentObject.name); } } // Else else { //MiddleVRTools.Log("No touch ! "); if (CurrentObject != null && CurrentObject != ObjectInHand) { HighlightObject(CurrentObject, false, HighlightColor); CurrentObject = null; } } //MiddleVRTools.Log("Current : " + CurrentObject); if (m_Buttons == null) { m_Buttons = MiddleVR.VRDeviceMgr.GetJoystick(JoystickName); } if (m_Buttons == null) { if (m_SearchedButtons == false) { //MiddleVRTools.Log("[~] VRWandInteraction: Wand buttons undefined. Please specify Wand Buttons in the configuration tool."); m_SearchedButtons = true; } } if (m_Buttons != null && CurrentObject != null) { VRActor script = CurrentObject.GetComponent <VRActor>(); //MiddleVRTools.Log("Trying to take :" + CurrentObject.name); if (script != null) { // Grab if (m_Buttons.IsButtonToggled(m_MainButton)) { if (script.Grabable) { Grab(CurrentObject); } } // Release if (m_Buttons.IsButtonToggled(m_MainButton, false) && ObjectInHand != null) { Ungrab(); } // Action if (((!RepeatAction && m_Buttons.IsButtonToggled(m_MainButton)) || (RepeatAction && m_Buttons.IsButtonPressed(m_MainButton)))) { CurrentObject.SendMessage("VRAction", SendMessageOptions.DontRequireReceiver); } } } }
// Update is called once per frame void Update() { Collider hit = GetClosestHit(); if( hit != null ) { //print("Closest : " + hit.name); if( CurrentObject != hit.gameObject && ObjectInHand == null ) { //MiddleVRTools.Log("Enter other : " + hit.name); HighlightObject( CurrentObject, false ); CurrentObject = hit.gameObject; HighlightObject(CurrentObject, true ); //MiddleVRTools.Log("Current : " + CurrentObject.name); } } // Else else { //MiddleVRTools.Log("No touch ! "); if (CurrentObject != null && CurrentObject != ObjectInHand) { HighlightObject(CurrentObject, false, HighlightColor ); CurrentObject = null; } } //MiddleVRTools.Log("Current : " + CurrentObject); if (m_Buttons == null) { m_Buttons = MiddleVR.VRDeviceMgr.GetJoystick(JoystickName); } if (m_Buttons == null) { if (m_SearchedButtons == false) { //MiddleVRTools.Log("[~] VRWandInteraction: Wand buttons undefined. Please specify Wand Buttons in the configuration tool."); m_SearchedButtons = true; } } if (m_Buttons != null && CurrentObject != null ) { VRActor script = CurrentObject.GetComponent<VRActor>(); //MiddleVRTools.Log("Trying to take :" + CurrentObject.name); if (script != null) { // Grab if (m_Buttons.IsButtonToggled(m_MainButton)) { if (script.Grabable) { Grab(CurrentObject); } } // Release if (m_Buttons.IsButtonToggled(m_MainButton, false) && ObjectInHand != null) { Ungrab(); } // Action if (((!RepeatAction && m_Buttons.IsButtonToggled(m_MainButton)) || (RepeatAction&& m_Buttons.IsButtonPressed(m_MainButton)))) { CurrentObject.SendMessage("VRAction", SendMessageOptions.DontRequireReceiver); } } } }
// Update is called once per frame void Update() { if (handNode2 == null) { handNode2 = GameObject.Find("RightHand"); } if (headNode == null) { headNode = GameObject.Find("LeftHand"); } if (handNode2 == null || headNode == null) { return; } handDir = handNode2.transform.forward; handDir.y = 0; handDir = handDir.normalized; handDirLat = new Vector3(handDir.z, 0, -handDir.x); if (MiddleVR.VRDeviceMgr != null) { if (MiddleVR.VRDeviceMgr.GetJoysticksNb() > 0) { vrJoystick joy = MiddleVR.VRDeviceMgr.GetJoystickByIndex(0); vrButtons but = joy.GetButtonsDevice(); if (joy != null) { float x = joy.GetAxisValue(0); float y = joy.GetAxisValue(1); float fourth = joy.GetAxisValue(3); float deltaTime = (float)MiddleVR.VRKernel.GetDeltaTime(); if (but.IsPressed(5)) { var currentXZHeadDir = headNode.transform.forward; currentXZHeadDir.y = 0; currentXZHeadDir = currentXZHeadDir.normalized; if (buttonDown) { firstXZHeadDir = currentXZHeadDir; buttonDown = false; } else { var cosAlpha = Vector3.Dot(firstXZHeadDir, currentXZHeadDir); var sinAlpha = Vector3.Cross(firstXZHeadDir, currentXZHeadDir).y; var alpha = Mathf.Atan2(sinAlpha, cosAlpha); transform.RotateAround(headNode.transform.position, new Vector3(0, 1, 0), -alpha * Mathf.Rad2Deg); } } else { buttonDown = true; } if (fourth > deadZone || fourth < -deadZone) { transform.RotateAround(headNode.transform.position, new Vector3(0, 1, 0), camSens * deltaTime * fourth); } if (x * x + y * y > deadZone * deadZone) { transform.Translate(-handDir * mainSpeed * deltaTime * y, Space.World); transform.Translate(handDirLat * mainSpeed * deltaTime * x, Space.World); } } } } }