virtual public bool TryPickup() { if (_heldItem != null || /*already holding something*/ hoverItem == null || /*have something were hovering over*/ (hoverItem.holdType != VRInteractableItem.HoldType.SPRING_JOINT && hoverItem.heldBy != null) /*Thing were hovering over is not a joint hold and is already being held*/) { return(false); } _heldItem = hoverItem; _heldItem.DisableHover(this); if (!_heldItem.Pickup(this)) /*Is the item alright with us picking it up*/ { _heldItem = null; return(false); } hoverItem = null; if (hideControllersWhileHolding) { ToggleControllers(false); } VREvent.Send("Pickup", new object[] { _heldItem }); return(true); }
// Add a single new event called "ImageUpdate" that contains a buffer of floats // for the image data. public void AddEventsSinceLastFrame(ref List <VREvent> eventList) { int w = 100; int h = 100; float[] imgBuffer = new float[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (index % 2 == 0) { imgBuffer[index] = 1.0f; } else { imgBuffer[index] = 0.0f; } index++; } } VREvent e = new VREvent("ImageUpdate"); e.AddData("Buffer", imgBuffer); eventList.Add(e); }
public static VREvent MakeEvent(string name, string type, float?analogValue = null) { VREvent e = new VREvent(name); e.AddData("EventType", type); if (analogValue.HasValue) { e.AddData("AnalogValue", analogValue.Value); } return(e); }
void OnVREvent(VREvent e) { if (e.Name == headTrackingEvent) { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray(matrix4x4DataField)); transform.position = m.GetTranslation(); transform.rotation = m.GetRotation(); //Debug.Log("Head Position = " + m.GetTranslation().ToString()); //Debug.Log("Head Rotation = " + m.GetRotation().ToString()); Vector3 offsetInLocalCoords = new Vector3(0.0f, 0.0f, Camera.main.nearClipPlane + 0.001f); Vector3 offsetInWorldCoords = transform.TransformVector(offsetInLocalCoords); transform.position += offsetInWorldCoords; } }
virtual public void Drop() { if (_heldItem == null || beingDestroyed) { return; } VREvent.Send("Drop", new object[] { _heldItem }); if (hoverItem != null) { hoverItem.DisableHover(this); hoverItem = null; } _lastDropped = Time.time; _heldItem.Drop(true, this); _heldItem = null; if (hideControllersWhileHolding) { ToggleControllers(true); } }
// This function gets called every time a new VREvent is generated. Typically, VREvents will come // from the MinVR server, which polls trackers, buttons, and other input devices for input. When // debugging on your laptop, you can also generate 'fake' VREvents using the VRMain script. void OnVREvent(VREvent e) { // USER 2 ========================================================== if (e.Name == "Brush2_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); brushPos = m.GetTranslation(); brushRot = m.GetRotation(); brushCursor2.transform.position = brushPos; brushCursor2.transform.rotation = brushRot; // Menu Selection ---------------------------------------------- if (MenuManager.ShowMenu && user_id == 2) { // Color change when hover on the button MenuManager.isHover(brushCursor2.transform.position); } } else if (e.Name == "Hand2_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); handPos = m.GetTranslation(); handRot = m.GetRotation(); handCursor2.transform.position = handPos; handCursor2.transform.rotation = handRot; } else if (e.Name == "Head2_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); headPos = m.GetTranslation(); headRot = m.GetRotation(); } // Button Controls -------------------------------------------------- else if (e.Name == "stylus0_btn1_up") { // stylys 0: blue pen if (user_id == 2) { // Show Main Menu if (MenuManager.CurMenu == null) { // Open Main Menu Menu mainMenu = null; //Debug.Log (MenuManager.Menus.Count); foreach (var item in MenuManager.Menus) { if (item.gameObject.name == "MainMenu") { mainMenu = item; break; } } if (mainMenu == null) { // TODO: catch could not find error } else { /* * mainMenu.ShowMenu = true; * mainMenu.gameObject.SetActive (true); * MenuManager.CurMenu = mainMenu.gameObject; * MenuManager.ShowMenu = true; * Vector3 hpos = GameObject.Find ("User2").transform.position; * MenuContainer.transform.position = new Vector3 (hpos.x, hpos.y - 70, hpos.z); */ Vector3 hpos = GameObject.Find("User2").transform.position; MenuManager.OpenMenu(mainMenu, new Vector3(hpos.x, hpos.y - 2, hpos.z), MenuContainer); } } else { MenuManager.CloseMenu(); } } } else if (e.Name == "stylus0_btn0_down") { if (user_id == 2) { if (!MenuManager.ShowMenu) { paintingComponent2.startNewStroke(painting2, brushCursor2); } } else if (user_id == 1) { // determine user 2 whether menu is open } } else if (e.Name == "stylus0_btn0_up") { if (user_id == 2) { if (MenuManager.ShowMenu) { // Call the function when the button is selected MenuManager.CurMenu.GetComponent <Menu> ().Clicked(brushCursor2.transform.position); } else { paintingComponent2.EndStroke(); } } } // USER 1 ========================================================== else if (e.Name == "Brush1_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); brushPos = m.GetTranslation(); brushRot = m.GetRotation(); brushCursor.transform.position = brushPos; brushCursor.transform.rotation = brushRot; if (MenuManager.ShowMenu && user_id == 1) { // Color change when hover on the button MenuManager.isHover(brushCursor.transform.position); } } else if (e.Name == "Hand1_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); handPos = m.GetTranslation(); handRot = m.GetRotation(); handCursor.transform.position = handPos; handCursor.transform.rotation = handRot; } else if (e.Name == "Head1_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); headPos = m.GetTranslation(); headRot = m.GetRotation(); } // Button Controls -------------------------------------------------- else if (e.Name == "stylus1_btn1_up") { // stylys 1: red pen if (user_id == 1) { // Show Main Menu if (MenuManager.CurMenu == null) { // Open Main Menu Menu mainMenu = null; Debug.Log(MenuManager.Menus.Count); foreach (var item in MenuManager.Menus) { if (item.gameObject.name == "MainMenu") { mainMenu = item; break; } } if (mainMenu == null) { // TODO: catch could not find error } else { /* * mainMenu.ShowMenu = true; * mainMenu.gameObject.SetActive (true); * MenuManager.CurMenu = mainMenu.gameObject; * MenuManager.ShowMenu = true; * Vector3 hpos = GameObject.Find ("User1").transform.position; * MenuContainer.transform.position = new Vector3 (hpos.x, hpos.y - 70, hpos.z); */ Vector3 hpos = GameObject.Find("User1").transform.position; MenuManager.OpenMenu(mainMenu, new Vector3(hpos.x, hpos.y - 2, hpos.z), MenuContainer); } } else { MenuManager.CloseMenu(); } } } else if (e.Name == "stylus1_btn0_down") { if (user_id == 1) { if (!MenuManager.ShowMenu) { paintingComponent.startNewStroke(painting, brushCursor); } } else if (user_id == 2) { // determine user 1 whether menu is open } } else if (e.Name == "stylus1_btn0_up") { if (user_id == 1) { if (MenuManager.ShowMenu) { // Call the function when the button is selected MenuManager.CurMenu.GetComponent <Menu> ().Clicked(brushCursor.transform.position); } else { paintingComponent.EndStroke(); } } } // Client input events ----------------------------------------------- else if (e.Name == "Type_Change") { if (user_id == 1) { } else if (user_id == 2) { } } else if (e.Name == "Color_Change") { if (user_id == 1) { } else if (user_id == 2) { } } else if (e.Name == "Start_Collaboration") { if (user_id == 1) { } else if (user_id == 2) { } } }
// This function gets called every time a new VREvent is generated. Typically, VREvents will come // from the MinVR server, which polls trackers, buttons, and other input devices for input. When // debugging on your laptop, you can also generate 'fake' VREvents using the VRMain script. void OnVREvent(VREvent e) { if (e.Name == "Brush_Move") // for faster user 2 { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); brushPos = m.GetTranslation(); brushRot = m.GetRotation(); brushCursor.transform.position = brushPos; brushCursor.transform.rotation = brushRot; } else if (e.Name == "Hand_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); handPos = m.GetTranslation(); handRot = m.GetRotation(); handCursor.transform.position = handPos; handCursor.transform.rotation = handRot; } else if (e.Name == "user_header_1" && user_id) // for cave painting system user 1 { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); headPos = m.GetTranslation(); headRot = m.GetRotation(); headObj.transform.position = headPos; headObj.transform.rotation = headRot; } else if (e.Name == "user_header_2" && !user_id) // for cave painting system user 2 { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); handPos = m.GetTranslation(); handRot = m.GetRotation(); headObj.transform.position = headPos; headObj.transform.rotation = headRot; } else if (e.Name == "Head_Move") { Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform")); headPos = m.GetTranslation(); handRot = m.GetRotation(); } else if (e.Name == "Mouse_Down") // TODO : useless for now { Debug.Log("mouse down"); } else if (e.Name == "Mouse_Up") { Debug.Log("mouse up"); } else if (e.Name == "stylus1_btn0_down") // user 2 start to draw { startDrawing = true; Debug.Log("Red User 2 drawing down"); } else if (e.Name == "stylus1_btn0_up") { startDrawing = false; Debug.Log("Red User 2 drawing up"); } else if (e.Name == "stylus1_btn1_down") // controll what user 2 see // TODO : manipulate User 2 camera { Debug.Log("Red User 2 control down"); } else if (e.Name == "stylus1_btn1_up") { // TODO : .... I don't know for now Debug.Log("Red User 2 control up"); } else if (e.Name == "stylus1_btn1_down") // user 1 start to draw { startDrawing = true; Debug.Log("Red User 1 control down"); } else if (e.Name == "stylus1_btn1_up") { startDrawing = false; Debug.Log("Red User 1 control up"); } else if (e.Name == "stylus1_btn1_down") // controll what user 1 see // TODO : manipulate User 1 camera { Debug.Log("Red User 1 control down"); } else if (e.Name == "stylus1_btn1_up") { // TODO : .... I don't know for now Debug.Log("Red User 1 control up"); } }