public virtual void UpdateMovement() { if (HaltUpdateMovement) { return; } bool moveForward = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow); bool moveLeft = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow); bool moveRight = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow); bool moveBack = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow); bool moveUp = Input.GetKey(KeyCode.T); bool moveDown = Input.GetKey(KeyCode.G); bool zoomIn = Input.GetAxis("Mouse ScrollWheel") > 0; bool zoomOut = Input.GetAxis("Mouse ScrollWheel") < 0; MoveScale = 1.0f; if ((moveForward && moveLeft) || (moveForward && moveRight) || (moveBack && moveLeft) || (moveBack && moveRight)) { MoveScale = 0.70710678f; } MoveScale *= SimulationRate * Time.deltaTime; // Compute this for key movement float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier; Quaternion ort = (HmdRotatesY) ? CameraController.centerEyeAnchor.rotation : transform.rotation; Vector3 ortEuler = ort.eulerAngles; ortEuler.z = ortEuler.x = 0f; ort = Quaternion.Euler(ortEuler); if (moveForward) { MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward); } if (moveBack) { MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back); } if (moveLeft) { MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left); } if (moveRight) { MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right); } if (moveUp) { MoveThrottle += ort * (transform.lossyScale.y * moveInfluence * Vector3.up); } if (moveDown) { MoveThrottle += ort * (transform.lossyScale.y * moveInfluence * BackAndSideDampen * Vector3.down); } if (zoomIn) { Camera leftCamera = CameraController.leftEyeAnchor.GetComponent <Camera> (); Camera rightCamera = CameraController.rightEyeAnchor.GetComponent <Camera> (); if (leftCamera.fieldOfView > 2) { leftCamera.fieldOfView -= 2; } if (rightCamera.fieldOfView > 2) { rightCamera.fieldOfView -= 2; } } if (zoomOut) { Camera leftCamera = CameraController.leftEyeAnchor.GetComponent <Camera> (); Camera rightCamera = CameraController.rightEyeAnchor.GetComponent <Camera> (); if (leftCamera.fieldOfView < 99) { leftCamera.fieldOfView += 2; } if (rightCamera.fieldOfView < 99) { rightCamera.fieldOfView += 2; } } //toggle if (Input.GetKey(KeyCode.R) & buttonPushed < Time.time - 0.2f) //show hide ribbons { if (addAtoms.ribbonShowing) { addAtoms.ribbonShowing = addAtoms.resetProtein("ribbons"); } else { addAtoms.ribbonShowing = addAtoms.showMode("ribbons"); } buttonPushed = Time.time; } if (Input.GetKey(KeyCode.N) & buttonPushed < Time.time - 0.2f) //menu { source.PlayOneShot(menuToggled, 0.5f); menu.enabled = !menu.enabled; //hide show menu buttonPushed = Time.time; } if (Input.GetKey(KeyCode.V) & buttonPushed < Time.time - 0.2f) //center { addAtoms.setPosition(ort * Vector3.forward * 30 + this.transform.position); //centers the atoms infront of the user buttonPushed = Time.time; } if (Input.GetKey(KeyCode.L) & buttonPushed < Time.time - 0.2f) //screenshot { Application.CaptureScreenshot(Application.dataPath + "/Screenshot.png", 4); buttonPushed = Time.time; } if (Input.GetKey(KeyCode.X) & buttonPushed < Time.time - 0.2f) //reset center { addAtoms.resetTarget(); buttonPushed = Time.time; } if (Input.GetKey(KeyCode.Z) & buttonPushed < Time.time - 0.2f) //lock target { addAtoms.lockTarget(); buttonPushed = Time.time; } if (Input.GetKey(KeyCode.P) & buttonPushed < Time.time - 0.2f) // change driver { bool newDriver = false; foreach (var user in trackedUsers) { if (user == null) { continue; } if (user.IsTracked) { if (driver == user.TrackingId) { newDriver = true; continue; } if (newDriver) { setDriver(user.TrackingId); newDriver = false; break; } } } if (newDriver) //iterate once more if a new driver wasn't selected { foreach (var user in trackedUsers) { if (user == null) { continue; } if (user.IsTracked) { if (newDriver) { setDriver(user.TrackingId); break; } } } } } moveInfluence = SimulationRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier; }
void Awake() { Controller = gameObject.GetComponent <CharacterController> (); if (Controller == null) { Debug.LogWarning("OVRPlayerController: No CharacterController attached."); } // We use OVRCameraRig to set rotations to cameras, // and to be influenced by rotation OVRCameraRig[] CameraControllers; CameraControllers = gameObject.GetComponentsInChildren <OVRCameraRig> (); if (CameraControllers.Length == 0) { Debug.LogWarning("OVRPlayerController: No OVRCameraRig attached."); } else if (CameraControllers.Length > 1) { Debug.LogWarning("OVRPlayerController: More then 1 OVRCameraRig attached."); } else { CameraController = CameraControllers [0]; } YRotation = transform.rotation.eulerAngles.y; Physics.IgnoreLayerCollision(0, 8); //ignores collisions between the player and all objects menu = gameObject.GetComponent <Menu> (); source = GetComponent <UnityEngine.AudioSource> (); addAtoms = gameObject.GetComponent <AddAtoms> (); addAtoms.Init(); // load the file addAtoms.parsePDB(); //populate the scene Quaternion ort = (HmdRotatesY) ? CameraController.centerEyeAnchor.rotation : transform.rotation; addAtoms.setPosition(ort * Vector3.forward * 30 + this.transform.position); //centers the atoms infront of the user //initiate the kinect _Sensor = KinectSensor.GetDefault(); if (_Sensor != null) { _Mapper = _Sensor.CoordinateMapper; _Reader = _Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.Depth); rightHand = transform.FindChild("RightHand").gameObject; leftHand = transform.FindChild("LeftHand").gameObject; rightHandMover = rightHand.GetComponent <GestureMover> (); leftHandMover = leftHand.GetComponent <GestureMover> (); var frameDesc = _Sensor.DepthFrameSource.FrameDescription; depthFrameWidth = frameDesc.Width; if (!_Sensor.IsOpen) { _Sensor.Open(); } _gestureDatabase = VisualGestureBuilderDatabase.Create(Application.streamingAssetsPath + "/Menu2.gbd"); _gestureFrameSource = VisualGestureBuilderFrameSource.Create(_Sensor, 0); foreach (var gesture in _gestureDatabase.AvailableGestures) { _gestureFrameSource.AddGesture(gesture); if (gesture.Name == "Menu2") { _menu = gesture; } } _gestureFrameReader = _gestureFrameSource.OpenReader(); _gestureFrameReader.IsPaused = true; } }