private void DoPocket6() { // phone's position within the control space Vector3 distanceFromControlSpaceCenter = controlSpace.transform.InverseTransformPointUnscaled(scenePhone.transform.position); float allowedOffsetBeforeRemapping = 0.01f; //1cm // check if control space remapping is required if ((Mathf.Abs(distanceFromControlSpaceCenter.x) > (ControlSpaceSize.x / 2) + allowedOffsetBeforeRemapping || Mathf.Abs(distanceFromControlSpaceCenter.y) > (ControlSpaceSize.y / 2) + allowedOffsetBeforeRemapping || Mathf.Abs(distanceFromControlSpaceCenter.z) > (ControlSpaceSize.z / 2) + allowedOffsetBeforeRemapping)) { needToBeRemapped = true; stopwatchForRemapping.Reset(); stopwatchForRemapping.Start(); RemapControlSpace(); } // wait until the user stops moving (e.g. after walking to a different position in the room) and then remap the control space // using the stopwatch is optional, the code can be securely removed if (stopwatchForRemapping.ElapsedMilliseconds > 1000) // dwell for 1s after remapping { if (needToBeRemapped) { RemapControlSpace(); needToBeRemapped = false; } Vector3 precalculationStep = distanceFromControlSpaceCenter * 100; Vector3 positionWithinControlSpace_InProcentageCentered = new Vector3( precalculationStep.x / ControlSpaceSize.x, precalculationStep.y / ControlSpaceSize.y, precalculationStep.z / ControlSpaceSize.z); Vector3 positionWithinControlSpace_InProcentage_FromBottomLeft = positionWithinControlSpace_InProcentageCentered + new Vector3(50, 50, 50); Vector3 positionWithinControlSpace_Normalized = positionWithinControlSpace_InProcentage_FromBottomLeft / 100; // normalize the values, from 0 - 100 to 0.0 - 1.0 // update the network phone networkPhone.transform.position = positionWithinControlSpace_Normalized; networkPhone.transform.rotation = arSessionOrigin.camera.transform.rotation; // ui output debugText.text = "Pocket6 position (norm. xyz): " + positionWithinControlSpace_Normalized.x.ToString("F2") + ", " + positionWithinControlSpace_Normalized.y.ToString("F2") + ", " + positionWithinControlSpace_Normalized.z.ToString("F2") + "\n"; debugText.text += "World rotation (xyz): " + networkPhone.transform.eulerAngles.x.ToString("F0") + ", " + networkPhone.transform.eulerAngles.y.ToString("F0") + ", " + networkPhone.transform.eulerAngles.z.ToString("F0") + " °"; debugText.text += "\nTouch data (state, x, y): " + touchDataLogic.GetTouchData().x.ToString("F0") + ", " + touchDataLogic.GetTouchData().y.ToString("F0") + ", " + touchDataLogic.GetTouchData().z.ToString("F0") + "\n"; } }
void Update() { labelConnectionInfo.text = "IP of this phone: " + GetLocalIPAddress(); if (manager.IsClientConnected()) { if (_foundClient) { networkClientPhone.transform.position = sceneNetworkPhone.transform.position; networkClientPhone.transform.rotation = sceneNetworkPhone.transform.rotation; networkClientPhone.GetComponent <NetworkIDManager>().SendTouchData(touchDataLogic.GetTouchData()); } else { SearchForObjectsClient("PhonePocket6"); } } else // there was a disconnect { _foundClient = false; manager.networkAddress = ipInputField.text; } // gui buttons if (manager.IsClientConnected()) { _buttonTextStartOrJoin.text = "Disconnect"; } else { _buttonTextStartOrJoin.text = "Connect"; } }