private void ApplyVirtualArmAndSimulateInput(IVRModuleDeviceStateRW ctrlState, IVRModuleDeviceStateRW headState, Vector3 handSideMultiplier) { if (!ctrlState.isConnected) { return; } if (!VIUSettings.waveVRAddVirtualArmTo3DoFController && !VIUSettings.simulateWaveVR6DofController) { return; } var deviceType = (int)s_index2type[ctrlState.deviceIndex]; #if VIU_WAVEVR_2_1_0_OR_NEWER && !VIU_WAVEVR_3_1_0_OR_NEWER && UNITY_EDITOR if (!WaveVR.Instance.isSimulatorOn || WaveVR_Utils.WVR_GetDegreeOfFreedom_S() == (int)WVR_NumDoF.WVR_NumDoF_6DoF) { return; } #elif VIU_WAVEVR_3_1_0_OR_NEWER && UNITY_EDITOR if (!WaveVR.EnableSimulator || WVR_Simulator.WVR_GetDegreeOfFreedom_S(0) == (int)WVR_NumDoF.WVR_NumDoF_6DoF) { return; } #else if (Interop.WVR_GetDegreeOfFreedom((WVR_DeviceType)deviceType) == WVR_NumDoF.WVR_NumDoF_6DoF) { return; } #endif if (VIUSettings.simulateWaveVR6DofController) { if (Input.GetKeyDown(KeyCode.Alpha1)) { s_simulationMode = Simulate6DoFControllerMode.KeyboardWASD; } if (Input.GetKeyDown(KeyCode.Alpha2)) { s_simulationMode = Simulate6DoFControllerMode.KeyboardModifierTrackpad; } if (Input.GetKeyDown(KeyCode.BackQuote)) { s_simulatedCtrlPosArray[deviceType] = Vector3.zero; } var deltaMove = Time.unscaledDeltaTime; var rotY = Quaternion.Euler(0f, ctrlState.rotation.eulerAngles.y, 0f); var moveForward = rotY * Vector3.forward; var moveRight = rotY * Vector3.right; switch (s_simulationMode) { case Simulate6DoFControllerMode.KeyboardWASD: { if (Input.GetKey(KeyCode.D)) { s_simulatedCtrlPosArray[deviceType] += moveRight * deltaMove; } if (Input.GetKey(KeyCode.A)) { s_simulatedCtrlPosArray[deviceType] -= moveRight * deltaMove; } if (Input.GetKey(KeyCode.E)) { s_simulatedCtrlPosArray[deviceType] += Vector3.up * deltaMove; } if (Input.GetKey(KeyCode.Q)) { s_simulatedCtrlPosArray[deviceType] -= Vector3.up * deltaMove; } if (Input.GetKey(KeyCode.W)) { s_simulatedCtrlPosArray[deviceType] += moveForward * deltaMove; } if (Input.GetKey(KeyCode.S)) { s_simulatedCtrlPosArray[deviceType] -= moveForward * deltaMove; } break; } case Simulate6DoFControllerMode.KeyboardModifierTrackpad: { float speedModifier = 2f; float x = ctrlState.GetAxisValue(VRModuleRawAxis.TouchpadX) * speedModifier; float y = ctrlState.GetAxisValue(VRModuleRawAxis.TouchpadY) * speedModifier; if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { s_simulatedCtrlPosArray[deviceType] += x * moveRight * deltaMove; s_simulatedCtrlPosArray[deviceType] += y * moveForward * deltaMove; } if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { s_simulatedCtrlPosArray[deviceType] += x * moveRight * deltaMove; s_simulatedCtrlPosArray[deviceType] += y * Vector3.up * deltaMove; } break; } } } if (VIUSettings.waveVRAddVirtualArmTo3DoFController) { var neckPose = new RigidPose(s_simulatedCtrlPosArray[deviceType], Quaternion.identity) * GetNeckPose(headState.pose); ctrlState.position = GetControllerPositionWithVirtualArm(neckPose, ctrlState.rotation, handSideMultiplier); } else { ctrlState.position += s_simulatedCtrlPosArray[deviceType]; } }
public void SendRenderTexturePtr(WaveVR_Render render, WVR_Eye eye, WaveVR_Camera wvrCamera) { if (connectType != 1) { return; // USB } if (!enablePreview) { return; } //if () only 1 time if (!isLeftReady && eye == WVR_Eye.WVR_Eye_Left) { rt_L = wvrCamera.GetCamera().targetTexture; if (rt_L != null) { rt[0] = rt_L.GetNativeTexturePtr(); Debug.LogWarning("rt[0] : " + rt[0]); isLeftReady = true; lastUpdateTime = 0; } else { Debug.LogWarning("rt_L == null"); } } if (!isRightReady && eye == WVR_Eye.WVR_Eye_Right) { rt_R = wvrCamera.GetCamera().targetTexture; if (rt_R != null) { rt[1] = rt_R.GetNativeTexturePtr(); Debug.LogWarning("rt[1] : " + rt[1]); isRightReady = true; lastUpdateTime = 0; } else { Debug.LogWarning("rt_R == null"); } } if (isLeftReady && isRightReady) { if (mFPS == 0) { if (Application.targetFrameRate > 0 && Application.targetFrameRate < 99) { mFPS = Application.targetFrameRate; } else { mFPS = 75; } Debug.LogWarning("mFPS is changed to " + mFPS); } long currentTime = getCurrentTimeMillis(); if (currentTime - lastUpdateTime >= (1000 / mFPS)) { if (eye == WVR_Eye.WVR_Eye_Left) { var height = wvrCamera.GetCamera().targetTexture.height; if ((height % 2) != 0) { Debug.LogWarning("RenderTexture height is odd, skip."); return; } var l1 = wvrCamera.GetCamera().targetTexture.GetNativeTexturePtr(); if (l1 != rt[0]) { Debug.LogWarning("left native pointer changed"); isLeftReady = false; isRightReady = false; return; } leftCall = true; } if (eye == WVR_Eye.WVR_Eye_Right) { var height = wvrCamera.GetCamera().targetTexture.height; if ((height % 2) != 0) { Debug.LogWarning("RenderTexture height is odd, skip."); return; } var r1 = wvrCamera.GetCamera().targetTexture.GetNativeTexturePtr(); if (r1 != rt[1]) { Debug.LogWarning("right native pointer changed"); isLeftReady = false; isRightReady = false; return; } rightCall = true; } if (leftCall && rightCall) { lastUpdateTime = currentTime; if (WVR_Simulator.SetTextureHandle(rt)) { // Debug.LogWarning("callback successfully"); } else { Debug.LogWarning("callback fail"); } leftCall = false; rightCall = false; } } } }