void MouseWandPointerMode() { GameObject wandObject = CAVE2.GetWandObject(wandID); if (wandObject) { if (wandObject.GetComponent <Rigidbody>()) { wandObject.GetComponent <Rigidbody>().MovePosition(CAVE2.Input.GetWandPosition(wandID)); } else { wandObject.transform.localPosition = CAVE2.Input.GetWandPosition(wandID); } // Mouse pointer ray controls rotation Vector2 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y); // Ray extending from main camera into screen from touch point Ray ray = CAVE2.GetCameraController().GetMainCamera().ScreenPointToRay(position); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { //transform.LookAt( hit.point ); } else { //transform.LookAt( ray.GetPoint(1000) ); } wandObject.transform.LookAt(ray.GetPoint(1000)); // Update the wandState rotation (opposite of normal since this object is determining the rotation) CAVE2.GetCAVE2Manager().simulatorWandRotation = wandObject.transform.localEulerAngles; } }
void FixedUpdate() { // Runtime check in case of reset (i.e. update in editor) if (!CAVE2.IsWandRegistered(wandID, gameObject)) { Debug.LogWarning("CAVE2WandMocapUpdater: Re-registering ID " + wandID); CAVE2.RegisterWandObject(wandID, gameObject); } if (virtualWand && virtualWand.GetComponent <Rigidbody>()) { transform.localPosition = CAVE2Manager.GetWandPosition(wandID); transform.localRotation = CAVE2Manager.GetWandRotation(wandID); // If position and rotation are zero, wand is not tracking, disable drawing and physics if (transform.localPosition == Vector3.zero && transform.localRotation == Quaternion.identity && virtualWand.gameObject.activeSelf) { virtualWand.gameObject.SetActive(false); } else if (transform.localPosition != Vector3.zero && transform.localRotation != Quaternion.identity && !virtualWand.gameObject.activeSelf) { virtualWand.gameObject.SetActive(true); } } }
// Use this for initialization void Start() { if (CAVE2.GetPlayerController(playerID) == null) { CAVE2.AddPlayerController(playerID, gameObject); } }
public override void OnEvent(EventData e) { if (e.sourceId == sourceID || sourceID == -1) { //Debug.Log("OmicronEventClient: '" + name + "' received " + e.serviceType + " sourceId: " + e.sourceId); if ((int)e.flags != rawFlags) { buttonsChanged = true; } rawFlags = (int)e.flags; rawAnalogInput1 = new Vector2(e.getExtraDataFloat(0), e.getExtraDataFloat(1)); rawAnalogInput2 = new Vector2(e.getExtraDataFloat(2), e.getExtraDataFloat(3)); rawAnalogInput3 = new Vector2(e.getExtraDataFloat(4), e.getExtraDataFloat(5)); rawAnalogInput4 = new Vector2(e.getExtraDataFloat(6), e.getExtraDataFloat(7)); analogInput1 = ApplyDeadzone(rawAnalogInput1); analogInput2 = ApplyDeadzone(rawAnalogInput2); analogInput3 = rawAnalogInput3; analogInput4 = rawAnalogInput4; // Flip Up/Down analog stick values analogInput1.y *= -1; analogInput2.y *= -1; CAVE2.SendMessage(gameObject.name, "UpdateAnalogC2", analogInput1, analogInput2, analogInput3, analogInput4); CAVE2.SendMessage(gameObject.name, "UpdateRawFlagsC2", (int)e.flags); } }
void Start() { LobbyManager = this; serverAddressField.text = networkAddress; NetworkedVRPlayerManager playerInfo = lobbyPlayerPrefab.GetComponent <NetworkedVRPlayerManager>(); string playerType = playerInfo.localPlayerControllerPrefab.GetComponent <VRPlayerWrapper>().GetVRTypeLabel(); localPlayerTypeText.text = "Player type '" + playerType + "' detected"; if (PlayerPrefs.GetString("ServerIPAddress").Length > 0) { serverAddressField.text = PlayerPrefs.GetString("ServerIPAddress"); } if (PlayerPrefs.GetString("LocalPlayerName").Length > 0) { localPlayerNameField.text = PlayerPrefs.GetString("LocalPlayerName"); playerName = localPlayerNameField.text; } if (!CAVE2.IsMaster()) { StartHost(); } }
// Parses Omicron Input Data public override void OnEvent(EventData e) { //Debug.Log("CAVE2Manager_Legacy: '"+name+"' received " + e.serviceType); if (e.serviceType == EventBase.ServiceType.ServiceTypeMocap) { if (!mocapSensors.ContainsKey((int)e.sourceId)) { OmicronMocapSensor mocapManager = gameObject.AddComponent <OmicronMocapSensor>(); mocapManager.sourceID = (int)e.sourceId; if (CAVE2.GetCAVE2Manager().usingKinectTrackingSimulator) { mocapManager.positionMod = new Vector3(1, 1, -1); } mocapSensors[(int)e.sourceId] = mocapManager; } } else if (e.serviceType == EventBase.ServiceType.ServiceTypeWand) { if (!wandControllers.ContainsKey((int)e.sourceId)) { OmicronController wandController = gameObject.AddComponent <OmicronController>(); wandController.sourceID = (int)e.sourceId; wandControllers[(int)e.sourceId] = wandController; } } }
// Use this for initialization void Start() { if (!CAVE2.OnCAVE2Display()) { headToGroundLine = gameObject.AddComponent <LineRenderer>(); #if UNITY_5_5_OR_NEWER headToGroundLine.startWidth = 0.02f; headToGroundLine.endWidth = 0.02f; #else headToGroundLine.SetWidth(0.02f, 0.02f); #endif headToGroundLine.material = lineMaterial; GameObject forwardReference = new GameObject("Head-ForwardRef"); forwardReference.transform.parent = transform; forwardLine = forwardReference.AddComponent <LineRenderer>(); #if UNITY_5_5_OR_NEWER forwardLine.startWidth = 0.02f; forwardLine.endWidth = 0.02f; #else forwardLine.SetWidth(0.02f, 0.02f); #endif forwardLine.material = lineMaterial; } CAVE2.RegisterHeadObject(headID, gameObject); }
// Update is called once per frame void FixedUpdate() { if (Input.GetKey(toggleMouseTracking)) { if (!mouseInitSet) { mouseLastPosition = Input.mousePosition; mouseInitSet = true; } else { mouseTrackingOffset = (Input.mousePosition - mouseLastPosition) * Time.fixedDeltaTime * 0.1f; mouseLastPosition = Input.mousePosition; Vector3 wandPosition = CAVE2.GetCAVE2Manager().simulatorWandPosition; CAVE2.GetCAVE2Manager().simulatorWandPosition = wandPosition + mouseTrackingOffset; mouseWandOffsetTriggered = true; } } else { mouseTrackingOffset = Vector3.zero; mouseInitSet = false; if (CAVE2.GetCAVE2Manager().wandMousePointerEmulation) { MouseWandPointerMode(); } if (CAVE2.GetCAVE2Manager().mocapEmulation) { KeyboardHeadTracking(); } } }
// Update is called once per frame void Update() { if (warp && warpID < poiLocations.Length) { player.transform.position = poiLocations[warpID].position; player.transform.rotation = poiLocations[warpID].rotation; warp = false; } if (CAVE2.GetButtonDown(1, CAVE2.Button.ButtonLeft)) { warpID--; WarpTo(warpID); //getReal3D.RpcManager.call("WarpTo", warpID); } if (CAVE2.GetButtonDown(1, CAVE2.Button.ButtonRight)) { warpID++; WarpTo(warpID); //getReal3D.RpcManager.call("WarpTo", warpID); } if (CAVE2.GetButtonDown(1, CAVE2.Button.ButtonUp)) { //player.GetComponent<OmicronPlayerController>().flyMovementScale *= 10; } if (CAVE2.GetButtonDown(1, CAVE2.Button.ButtonDown)) { //player.GetComponent<OmicronPlayerController>().flyMovementScale *= 0.1f; } }
// Use this for initialization void Start() { // Wand (Navigation Controller) buttonCross = transform.Find("CrossButton"); buttonCircle = transform.Find("CircleButton"); buttonDown = transform.Find("ButtonDown"); buttonLeft = transform.Find("ButtonLeft"); buttonRight = transform.Find("ButtonRight"); buttonUp = transform.Find("ButtonUp"); buttonL1 = transform.Find("L1"); buttonL2 = transform.Find("L2"); buttonL3 = transform.Find("AnalogStick-L3"); // Full Controller buttonTriangle = transform.Find("TriangleButton"); buttonSquare = transform.Find("SquareButton"); buttonR1 = transform.Find("R1"); buttonR2 = transform.Find("R2"); buttonR3 = transform.Find("AnalogStick-R3"); buttonSelect = transform.Find("Select"); buttonStart = transform.Find("Start"); meshRenderers = GetComponentsInChildren <MeshRenderer>(); if (!CAVE2.OnCAVE2Display()) { SetWandVisible(true); } else { SetWandVisible(wandVisible); } }
void OnInput() { if (CAVE2.Input.GetButtonDown(menuManager.menuWandID, CAVE2.Button.ButtonDown)) { if (currentItem < menuItems.Length - 1 && menuItems[currentItem + 1].IsActive()) { CAVE2.BroadcastMessage(gameObject.name, "MenuNextItemDown"); } } if (CAVE2.Input.GetButtonDown(menuManager.menuWandID, CAVE2.Button.ButtonUp)) { if (currentItem > 0 && menuItems[currentItem - 1].IsActive()) { CAVE2.BroadcastMessage(gameObject.name, "MenuNextItemUp"); } } if (CAVE2.Input.GetButtonDown(menuManager.menuWandID, menuManager.selectButton)) { CAVE2.BroadcastMessage(gameObject.name, "MenuSelectItem"); } if (CAVE2.Input.GetButtonDown(menuManager.menuWandID, menuManager.menuBackButton)) { CAVE2.BroadcastMessage(gameObject.name, "ToggleMenu"); } if (CAVE2.Input.GetButtonDown(menuManager.menuWandID, CAVE2.Button.ButtonLeft)) { CAVE2.BroadcastMessage(gameObject.name, "MenuNextItemLeft"); } if (CAVE2.Input.GetButtonDown(menuManager.menuWandID, CAVE2.Button.ButtonRight)) { CAVE2.BroadcastMessage(gameObject.name, "MenuNextItemRight"); } }
public void Init() { base.Start(); unityInputToOmicronInput[CAVE2.GetCAVE2Manager().wandSimulatorAnalogUD] = CAVE2.Axis.LeftAnalogStickUD; unityInputToOmicronInput[CAVE2.GetCAVE2Manager().wandSimulatorAnalogLR] = CAVE2.Axis.LeftAnalogStickLR; unityInputToOmicronInput[CAVE2.GetCAVE2Manager().wandSimulatorButton3] = CAVE2.Button.Button3; unityInputToOmicronInput[CAVE2.GetCAVE2Manager().wandSimulatorButton2] = CAVE2.Button.Button2; unityInputToOmicronInput[CAVE2.GetCAVE2Manager().wandSimulatorButton6] = CAVE2.Button.Button6; if (VRDevice.model == "Vive MV") { vrModel = VRModel.Vive; } else if (VRDevice.model.Length > 0) { Debug.Log("CAVE2InputManager: Detected VRDevice '" + VRDevice.model + "'."); } OmicronMocapSensor[] mocapSensors = GetComponents <OmicronMocapSensor>(); foreach (OmicronMocapSensor ms in mocapSensors) { Destroy(ms); //mocapSensors[ms.sourceID] = ms; Debug.LogWarning("CAVE2InputManager: Found existing mocap sensor id '" + ms.sourceID + "'."); } OmicronController[] controllers = GetComponents <OmicronController>(); foreach (OmicronController c in controllers) { Destroy(c); //wandControllers[c.sourceID] = c; Debug.LogWarning("CAVE2InputManager: Found existing controllers id '" + c.sourceID + "'."); } }
// Update is called once per frame void Update() { if (CAVE2.IsMaster()) { if (networkWaitTimer <= 0) { #if USING_GETREAL3D ICollection keys = spawnedPlayerList.Keys; foreach (int netID in keys) { GameObject g = spawnedPlayerList[netID] as GameObject; NetworkedVRPlayerManager netPlayer = g.GetComponent <NetworkedVRPlayerManager>(); getReal3D.RpcManager.call("UpdateNetworkPlayerRPC", netID, netPlayer.playerPosition, netPlayer.playerRotation, netPlayer.headPosition, netPlayer.headRotation); } #endif } networkWaitTimer = networkUpdateDelay; } else { networkWaitTimer -= Time.deltaTime; } }
// Use this for initialization void Start() { CAVE2.AddCameraController(this); if (mainCamera == null) { mainCamera = GetComponentInChildren <Camera>(); } #if USING_GETREAL3D if (mainCamera.GetComponent <getRealCameraUpdater>()) { mainCamera.GetComponent <getRealCameraUpdater>().enabled = true; } else { mainCamera.gameObject.AddComponent <getRealCameraUpdater>(); } #endif if (setCameraEyeLayerMasks) { leftEyeLayer = 1 << LayerMask.NameToLayer(leftEyeLayerName); rightEyeLayer = 1 << LayerMask.NameToLayer(rightEyeLayerName); cameraLayer = mainCamera.cullingMask; } wandNav = GetComponentInParent <CAVE2WandNavigator>(); }
void Update() { if (CAVE2.IsSimulatorMode()) { #if USING_GETREAL3D if (mainCamera.GetComponent <getRealCameraUpdater>()) { mainCamera.GetComponent <getRealCameraUpdater>().enabled = false; } #endif float simHeadRotateSpeed = 40; if (wandNav) { simHeadRotateSpeed = wandNav.GetTurnSpeed(); } if (Input.GetKey(CAVE2.Input.simulatorHeadRotateL)) { transform.Rotate(-Vector3.up * Time.deltaTime * simHeadRotateSpeed); } else if (Input.GetKey(CAVE2.Input.simulatorHeadRotateR)) { transform.Rotate(Vector3.up * Time.deltaTime * simHeadRotateSpeed); } } }
void UpdateSync() { if (CAVE2.IsMaster()) { if (updateTimer < 0) { SyncTransform(); updateTimer = updateSpeed; } updateTimer -= Time.fixedDeltaTime; } else if (gotFirstUpdateFromMaster) { if (updateMode != UpdateMode.Adaptive) { if (useLocal) { transform.localPosition = nextPosition; transform.localRotation = nextRotation; } else { transform.position = nextPosition; transform.rotation = nextRotation; } } else { driftValue = Vector3.Magnitude(useLocal ? transform.localPosition : transform.position - nextPosition); if (timeSinceLastChange > adaptiveDelay && driftValue > adaptiveThreshold) { if (useLocal) { transform.localPosition = nextPosition; transform.localRotation = nextRotation; } else { transform.position = nextPosition; transform.rotation = nextRotation; } timeSinceLastChange = 0; } } } if (hasScaleFromMaster) { transform.localScale = nextScale; } if (testSyncObject) { transform.localPosition = testSyncObject.localPosition; transform.localRotation = testSyncObject.localRotation; } }
// Update is called once per frame void Update() { if (CAVE2.IsMaster()) { UpdateButtons(rawFlags); CAVE2.SendMessage(gameObject.name, "UpdateButtonStates", Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9, SpecialButton1, SpecialButton2, SpecialButton3, ButtonUp, ButtonDown, ButtonLeft, ButtonRight); } }
new void OnWandButtonDown(CAVE2.WandEvent evt) { if (evt.button == grabButton && (evt.interactionType == grabStyle || grabStyle == CAVE2.InteractionType.Any)) { OnWandGrab(CAVE2.GetWandObject(evt.wandID).transform); grabbingWandID = evt.wandID; } }
// Update is called once per frame void Update() { float forwardVector = CAVE2.GetAxis(wandID, forwardInputAxis); float strafeVector = CAVE2.GetAxis(wandID, strafeInputAxis); transform.Translate(forwardVector * Vector3.forward * movementSpeed * Time.deltaTime); transform.Translate(strafeVector * Vector3.right * movementSpeed * Time.deltaTime); }
void UpdateWalkMovement() { GetComponent <Rigidbody>().isKinematic = false; bodyCollider.GetComponent <Rigidbody>().useGravity = true; bodyCollider.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation; Vector3 nextPos = transform.position; float forwardAngle = transform.eulerAngles.y; if (forwardReference == ForwardRef.Head) { forwardAngle = CAVE2.GetHeadObject(headID).transform.eulerAngles.y; } else if (forwardReference == ForwardRef.Wand) { forwardAngle = CAVE2.GetWandObject(wandID).transform.eulerAngles.y; } if (horizontalMovementMode == HorizonalMovementMode.Strafe) { nextPos.z += forward * Time.deltaTime * Mathf.Cos(Mathf.Deg2Rad * forwardAngle) * (smoothMovement ? movementScale * 20 : movementScale); nextPos.x += forward * Time.deltaTime * Mathf.Sin(Mathf.Deg2Rad * forwardAngle) * (smoothMovement ? movementScale * 20 : movementScale); nextPos.z += strafe * Time.deltaTime * Mathf.Cos(Mathf.Deg2Rad * (forwardAngle + 90)) * (smoothMovement ? movementScale * 20 : movementScale); nextPos.x += strafe * Time.deltaTime * Mathf.Sin(Mathf.Deg2Rad * (forwardAngle + 90)) * (smoothMovement ? movementScale * 20 : movementScale); if (smoothMovement) { transform.position = Vector3.SmoothDamp(transform.position, nextPos, ref velocity, smoothMovementTime); } else { transform.position = nextPos; } transform.Rotate(new Vector3(lookAround.x, lookAround.y, 0) * Time.deltaTime * turnSpeed); } else if (horizontalMovementMode == HorizonalMovementMode.Turn) { nextPos.z += forward * Time.deltaTime * Mathf.Cos(Mathf.Deg2Rad * forwardAngle) * (smoothMovement ? movementScale * 20 : movementScale); nextPos.x += forward * Time.deltaTime * Mathf.Sin(Mathf.Deg2Rad * forwardAngle) * (smoothMovement ? movementScale * 20 : movementScale); if (smoothMovement) { transform.position = Vector3.SmoothDamp(transform.position, nextPos, ref velocity, smoothMovementTime); } else { transform.position = nextPos; } transform.RotateAround(transform.position + transform.rotation * CAVE2.GetHeadPosition(headID), transform.TransformDirection(Vector3.up), strafe * Time.deltaTime * turnSpeed); } if (autoLevelMode == AutoLevelMode.OnGroundCollision) { transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); } }
void LateUpdate() { if (useLateUpdate) { transform.localPosition = CAVE2.GetMocapPosition(sourceID) + posOffset; transform.localRotation = CAVE2.GetMocapRotation(sourceID); transform.Rotate(rotOffset); } }
void Start() { #if !UNITY_EDITOR if (CAVE2.OnCAVE2Display()) { GetComponent <Renderer>().enabled = false; } #endif }
void Awake() { #if UNITY_EDITOR if (!showInHMDVR && CAVE2.UsingHMDVR()) { renderMode = RenderMode.None; } #endif }
void Start() { if (virtualWand && wandID == 1 && !CAVE2.UsingHMDVR()) { virtualWand.localPosition = CAVE2.Input.wandTrackingOffset[wandID - 1]; } // Register this gameobject as wand CAVE2.RegisterWandObject(wandID, gameObject); }
void Start() { if (virtualWand && wandID == 1) { virtualWand.localPosition = CAVE2.Input.wand1TrackingOffset; } // Register this gameobject as wand CAVE2.RegisterWandObject(wandID, gameObject); }
// Update is called once per frame void Update() { if (CAVE2.IsMaster()) { //transform.localPosition = CAVE2.GetMocapPosition(sourceID); Vector3 rotation = CAVE2.GetMocapRotation(sourceID).eulerAngles; rotation.y += 163.351f - 90; transform.localEulerAngles = new Vector3(0, 0, rotation.y); } }
void MouseWandPointerMode() { GameObject wandObject = CAVE2.GetWandObject(wandID); if (wandObject) { if (wandObject.GetComponent <Rigidbody>()) { wandObject.GetComponent <Rigidbody>().MovePosition(CAVE2.Input.GetWandPosition(wandID)); } else { wandObject.transform.localPosition = CAVE2.Input.GetWandPosition(wandID); } if (wandUsesHeadPosition) { wandObject.transform.localPosition = CAVE2.Input.GetHeadPosition(1); } else { wandObject.transform.localPosition = wandDefaultPositionOffset; } // Disable head collider if wand is attached to head if (CAVE2.GetHeadObject(1) != null) { SphereCollider headCollider = CAVE2.GetHeadObject(1).GetComponentInChildren <SphereCollider>(); if (headCollider) { headCollider.enabled = !wandUsesHeadPosition; } } // Mouse pointer ray controls rotation Vector2 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y); // Ray extending from main camera into screen from touch point Ray ray = CAVE2.GetCameraController().GetMainCamera().ScreenPointToRay(position); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { //transform.LookAt( hit.point ); } else { //transform.LookAt( ray.GetPoint(1000) ); } wandObject.transform.LookAt(ray.GetPoint(1000)); // Update the wandState rotation (opposite of normal since this object is determining the rotation) CAVE2.GetCAVE2Manager().simulatorWandPosition = wandObject.transform.localPosition; CAVE2.GetCAVE2Manager().simulatorWandRotation = wandObject.transform.localEulerAngles; } }
// Update is called once per frame void Update() { if (showMenu) { newScale = maxScale; } else { newScale = 0; } if (GetComponent <UndockMenu>()) { if (GetComponent <UndockMenu>().undocked) { newScale = maxScale; showMenu = false; if (activeMenu) { transform.Translate(Vector3.right); if (previousMenu) { previousMenu.showMenu = true; menuManager.currentMenu = previousMenu; } activeMenu = false; menuManager.openMenus--; menuManager.PlayCloseMenuSound(); } return; } else if (!showMenu) { newScale = 0; } } UpdateScale(); if (newScale > 0) { menuProgress = currentScale / newScale; if (showMenu) { activeMenu = true; } } if (showMenu && activeMenu && menuProgress > 0.5f && CAVE2.IsMaster()) { OnInput(); } }
public Quaternion GetWandRotation(int ID) { int wandID = 1; switch (ID) { case (1): wandID = CAVE2.GetCAVE2Manager().wand1MocapID; break; case (2): wandID = CAVE2.GetCAVE2Manager().wand2MocapID; break; } return(GetMocapRotation(wandID)); }
new public void OnWandButtonDown(CAVE2.WandEvent evt) { CAVE2PlayerIdentity playerID = (CAVE2PlayerIdentity)evt.playerID; int wandID = (int)evt.wandID; CAVE2.Button button = (CAVE2.Button)evt.button; if (wandID == this.wandID && button == this.button) { CAVE2.LoadScene(sceneName); } }