public void UpdateState(int sourceID, int mocapID) { // Just in case we want to change controllers at runtime this.sourceID = sourceID; this.mocapID = mocapID; // Set buttons held if down on the last frame // Set buttons as idle if up on the last frame // We only check if frame time if input is coming from an external async // source like an Omicron oinputserver if (Time.frameCount - lastUpdateEventFrame > 1 || !CAVE2Manager.UsingOmicronServer() || (CAVE2Manager.UsingOmicronServer() && CAVE2Manager.UsingGetReal3D())) { for (int i = 0; i < 16; i++) { ButtonState buttonState = GetButtonState(i); if (buttonState == ButtonState.Down) { UpdateButton(i, (int)ButtonState.Held); } else if (buttonState == ButtonState.Up) { UpdateButton(i, (int)ButtonState.Idle); } } } }
// Update is called once per frame void Update() { if (simulatorMode) { #if USING_GETREAL3D if (Camera.main != null && Camera.main.GetComponent <getRealCameraUpdater>()) { Camera.main.GetComponent <getRealCameraUpdater>().applyHeadPosition = false; Camera.main.GetComponent <getRealCameraUpdater>().applyHeadRotation = false; Camera.main.GetComponent <getRealCameraUpdater>().applyCameraProjection = false; } #endif keyboardEventEmulation = true; wandMousePointerEmulation = true; mocapEmulation = true; if (Input.GetKeyDown(toggleWandModeKey)) { wandModeToggled = !wandModeToggled; } if (wandModeToggled) { wandEmulationMode = toggleWandEmulationMode; } else { wandEmulationMode = defaultWandEmulationMode; } mouseDeltaPos = Input.mousePosition - mouseLastPos; mouseLastPos = Input.mousePosition; } wand1.UpdateState(Wand1, Wand1Mocap); wand2.UpdateState(Wand2, Wand2Mocap); float vertical = Input.GetAxis(wandSimulatorAnalogUD) * axisSensitivity; float horizontal = Input.GetAxis(wandSimulatorAnalogLR) * axisSensitivity; float forward = 0 * axisSensitivity; // Horizontal2, Vertical 2 are not a standard Input axis // catch exception to prevent console spamming if not set try { lookHorizontal = Input.GetAxis("Horizontal2") * axisSensitivity; lookVertical = Input.GetAxis("Vertical2") * axisSensitivity; } catch { } uint flags = 0; #if USING_GETREAL3D // If using Omicron, make sure button events don't conflict if (!simulatorMode) { vertical = -getReal3D.Input.GetAxis("Forward") * axisSensitivity; horizontal = getReal3D.Input.GetAxis("Yaw") * axisSensitivity; lookHorizontal = getReal3D.Input.GetAxis("Strafe") * axisSensitivity; lookVertical = getReal3D.Input.GetAxis("Pitch") * axisSensitivity; float DPadUD = getReal3D.Input.GetAxis("DPadUD"); float DPadLR = getReal3D.Input.GetAxis("DPadLR"); if (DPadUD > 0) { flags += (int)EventBase.Flags.ButtonUp; } else if (DPadUD < 0) { flags += (int)EventBase.Flags.ButtonDown; } if (DPadLR > 0) { flags += (int)EventBase.Flags.ButtonLeft; } else if (DPadLR < 0) { flags += (int)EventBase.Flags.ButtonRight; } // Wand Button 1 (Triangle/Y) if (getReal3D.Input.GetButton("Jump")) { flags += (int)EventBase.Flags.Button1; } // F -> Wand Button 2 (Circle/B) if (getReal3D.Input.GetButton("Reset")) { flags += (int)EventBase.Flags.Button2; } // R -> Wand Button 3 (Cross/A) if (getReal3D.Input.GetButton("ChangeWand")) { flags += (int)EventBase.Flags.Button3; } // Wand Button 4 (Square/X) if (getReal3D.Input.GetButton("WandButton")) { flags += (int)EventBase.Flags.Button4; } // Wand Button 8 (R1/RB) if (getReal3D.Input.GetButton("NavSpeed")) { flags += (int)EventBase.Flags.Button8; } // Wand Button 5 (L1/LB) if (getReal3D.Input.GetButton("WandLook")) { flags += (int)EventBase.Flags.Button5; } // Wand Button 6 (L3) if (getReal3D.Input.GetButton("L3")) { flags += (int)EventBase.Flags.Button6; } // Wand Button 7 (L2) if (getReal3D.Input.GetButton("LT")) { flags += (int)EventBase.Flags.Button7; } // Wand Button 8 (R2) if (getReal3D.Input.GetButton("RT")) { flags += (int)EventBase.Flags.Button8; } // Wand Button 9 (R3) if (getReal3D.Input.GetButton("R3")) { flags += (int)EventBase.Flags.Button9; } // Wand Button SP1 (Back) if (getReal3D.Input.GetButton("Back")) { flags += (int)EventBase.Flags.SpecialButton1; } // Wand Button SP2 (Start) if (getReal3D.Input.GetButton("Start")) { flags += (int)EventBase.Flags.SpecialButton2; } } #endif Vector2 wandAnalog = new Vector2(horizontal, vertical); Vector2 wandAnalog2 = new Vector2(lookHorizontal, lookVertical); Vector2 wandAnalog3 = new Vector2(forward, 0); if (mouseHeadLook) { Vector3 mouseDiff = Input.mousePosition - lastMousePosition; if (!mouseUsingGUI) { headEmulatedRotation += new Vector3(-mouseDiff.y, mouseDiff.x, 0) * emulatedRotationSpeed; } lastMousePosition = Input.mousePosition; mouseUsingGUI = false; } if (keyboardEventEmulation) { if (WASDkeys == TrackerEmulated.CAVE) { if (WASDkeyMode == TrackerEmulationMode.Translate) { wandAnalog = new Vector2(horizontal, vertical); wandAnalog2 = new Vector2(lookHorizontal, lookVertical); wandAnalog3 = new Vector2(forward, 0); } else if (WASDkeyMode == TrackerEmulationMode.Rotate) { wandAnalog = new Vector2(0, vertical); wandAnalog2 = new Vector2(horizontal, lookVertical); wandAnalog3 = new Vector2(forward, 0); } } else if (WASDkeys == TrackerEmulated.Head) { if (WASDkeyMode == TrackerEmulationMode.Translate) { headEmulatedPosition += new Vector3(horizontal, 0, vertical) * Time.deltaTime; } else if (WASDkeyMode == TrackerEmulationMode.Rotate) { headEmulatedRotation += new Vector3(vertical, horizontal, 0); } } headEmulatedRotation += new Vector3(lookVertical, 0, 0) * emulatedRotationSpeed; // Arrow keys -> DPad if (Input.GetKey(wandSimulatorDPadUp)) { flags += (int)EventBase.Flags.ButtonUp; } if (Input.GetKey(wandSimulatorDPadDown)) { flags += (int)EventBase.Flags.ButtonDown; } if (Input.GetKey(wandSimulatorDPadLeft)) { flags += (int)EventBase.Flags.ButtonLeft; } if (Input.GetKey(wandSimulatorDPadRight)) { flags += (int)EventBase.Flags.ButtonRight; } // F -> Wand Button 2 (Circle) if (Input.GetKey(KeyCode.F) || Input.GetButton(wandSimulatorButton2)) { flags += (int)EventBase.Flags.Button2; } // R -> Wand Button 3 (Cross) if (Input.GetKey(KeyCode.R) || Input.GetButton(wandSimulatorButton3)) { flags += (int)EventBase.Flags.Button3; } // Wand (L2 Trigger) if (Input.GetKey(wandSimulatorButton7)) { flags += (int)EventBase.Flags.Button7; } // Wand (L1 Trigger) if (Input.GetKey(wandSimulatorButton5)) { flags += (int)EventBase.Flags.Button5; } // Wand (L3 Trigger) if (Input.GetButton(wandSimulatorButton6)) { flags += (int)EventBase.Flags.Button6; } float headForward = 0; float headStrafe = 0; float headVertical = 0; float speed = emulatedTranslateSpeed; if (IJKLkeyMode == TrackerEmulationMode.Translate) { speed = emulatedTranslateSpeed; } else if (IJKLkeyMode == TrackerEmulationMode.Rotate) { speed = emulatedRotationSpeed; } if (Input.GetKey(KeyCode.I)) { headForward += speed * Time.deltaTime; } else if (Input.GetKey(KeyCode.K)) { headForward -= speed * Time.deltaTime; } if (Input.GetKey(KeyCode.J)) { headStrafe -= speed * Time.deltaTime; } else if (Input.GetKey(KeyCode.L)) { headStrafe += speed * Time.deltaTime; } if (Input.GetKey(KeyCode.U)) { headVertical += speed * Time.deltaTime; } else if (Input.GetKey(KeyCode.O)) { headVertical -= speed * Time.deltaTime; } if (IJKLkeys == TrackerEmulated.Head) { if (IJKLkeyMode == TrackerEmulationMode.Translate) { headEmulatedPosition += new Vector3(headStrafe, headVertical, headForward); } else if (IJKLkeyMode == TrackerEmulationMode.Rotate) { headEmulatedRotation += new Vector3(headForward, headStrafe, headVertical); } } else if (IJKLkeys == TrackerEmulated.Wand) { if (IJKLkeyMode == TrackerEmulationMode.Translate) { wandEmulatedPosition += new Vector3(headStrafe, headVertical, headForward); } else if (IJKLkeyMode == TrackerEmulationMode.Rotate) { wandEmulatedRotation += new Vector3(headForward, headStrafe, headVertical); } } } if (!CAVE2Manager.UsingOmicronServer() || (CAVE2Manager.UsingOmicronServer() && CAVE2Manager.UsingGetReal3D()) || (keyboardEventEmulation && Input.anyKey)) { wand1.UpdateController(flags, wandAnalog, wandAnalog2, wandAnalog3); } if (mocapEmulation) { Vector3 lookAround = new Vector3(-wand1.GetAxis(Axis.RightAnalogStickUD), wand1.GetAxis(Axis.RightAnalogStickLR), 0); headEmulatedRotation += lookAround * emulatedRotationSpeed; // Update emulated positions/rotations head1.Update(headEmulatedPosition, Quaternion.Euler(headEmulatedRotation)); if (lockWandToHeadTransform) { wand1.UpdateMocap(headEmulatedPosition, Quaternion.Euler(headEmulatedRotation)); } else { wand1.UpdateMocap(wandEmulatedPosition, Quaternion.Euler(wandEmulatedRotation)); } if (cameraController != null) { cameraController.transform.localPosition = headEmulatedPosition; cameraController.transform.localEulerAngles = headEmulatedRotation; } else { Debug.LogWarning("CAVE2Manager: No CameraController found. May not display properly in CAVE2!"); } } else { #if USING_GETREAL3D head1.Update(getReal3D.Input.head.position, getReal3D.Input.head.rotation); wand1.UpdateMocap(getReal3D.Input.wand.position, getReal3D.Input.wand.rotation); #endif } }
// --------------------------------------------------------------------------------------------- // CAVE2 Input Management ---------------------------------------------------------------------- public static bool UsingOmicronServer() { return(CAVE2Manager.UsingOmicronServer()); }