bool ensureInitialization() { if (isInitialized) return true; Controller = SixenseInput.GetController(HandId); if (Controller != null) { isInitialized = true; } return isInitialized; }
// Update is called once per frame void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { if (startingH == 999 || m_controller.GetButtonDown(SixenseButtons.ONE)) { startingH = m_controller.Rotation.eulerAngles.y; startingV = m_controller.Rotation.eulerAngles.x; } curH = -Mathf.DeltaAngle(m_controller.Rotation.eulerAngles.y, startingH); curV = -Mathf.DeltaAngle(m_controller.Rotation.eulerAngles.x, startingV); curH = curH > 30 ? 30 : curH; curH = curH < -30 ? -30 : curH; curV = curV > 30 ? 30 : curV; curV = curV < -30 ? -30 : curV; cursorX = (curH + 30) / 60; cursorY = (curV + 30) / 60; Quaternion rotation = Quaternion.identity; rotation.eulerAngles = new Vector3(curV, curH * 16 / 9, 0); transform.localRotation = rotation; Vector3 fwd = transform.TransformDirection(Vector3.forward); Debug.DrawRay(transform.position, fwd * 100, Color.green); //if (Physics.Raycast(transform.position, fwd, 10)) { // print("There is something in front of the object!"); //} if (m_controller.GetButtonDown(SixenseButtons.TRIGGER) && !dragging) { RaycastHit hit = new RaycastHit(); if (Physics.Raycast(transform.position, fwd, out hit, 100) && hit.rigidbody) { Debug.Log("Jacob is dumb"); dragging = true; target = hit.rigidbody; target.useGravity = false; prevRotation = m_controller.Rotation; prevPosition = (m_controller.Position); prevLSP = transform.position; } } if (m_controller.GetButton(SixenseButtons.TRIGGER) && dragging) { target.MovePosition(target.transform.position + transform.TransformDirection(m_controller.Position - prevPosition) / 10 + transform.position - prevLSP); prevLSP = transform.position; prevPosition = (m_controller.Position); } if (m_controller.GetButtonUp(SixenseButtons.TRIGGER) && dragging) { dragging = false; target.useGravity = true; } } }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } }
void Update() { razer = SixenseInput.GetController(controller); if (!GetComponent <Rigidbody>()) { // isRazerBaseMobile is false if Razer Hydra is not position, rotation, or compass source in headTracker if (headTracker && headTracker.isRazerBaseMobile) { movingBasePosition = headTracker.hydraBasePosition; movingBaseRotation = headTracker.hydraBaseRotation; } else { movingBasePosition = Vector3.zero; movingBaseRotation = Quaternion.identity; } transform.localPosition = movingBaseRotation * localPosition + movingBasePosition; transform.localRotation = movingBaseRotation * localRotation; } if (whereToCopyColor != null) { foreach (Material mat in whereToCopyColor.materials) { mat.color = color; } } }
void Update () { razer = SixenseInput.GetController( controller ); if(!GetComponent<Rigidbody>()) { // isRazerBaseMobile is false if Razer Hydra is not position, rotation, or compass source in headTracker if( headTracker && headTracker.isRazerBaseMobile ) { movingBasePosition = headTracker.hydraBasePosition; movingBaseRotation = headTracker.hydraBaseRotation; } else { movingBasePosition = Vector3.zero; movingBaseRotation = Quaternion.identity; } transform.localPosition = movingBaseRotation * localPosition + movingBasePosition; transform.localRotation = movingBaseRotation * localRotation; } if (whereToCopyColor != null) { foreach (Material mat in whereToCopyColor.materials) { mat.color = color; } } }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { float xangle = m_controller.Rotation.eulerAngles.x; xangle = xangle > 90 && xangle < 180 ? 90 : xangle; xangle = xangle < 270 && xangle > 180 ? 270 : xangle; Quaternion rotation = Quaternion.identity; //transform.rotation = m_controller.Rotation; rotation.eulerAngles = new Vector3(xangle, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); //rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); transform.rotation = rotation; } /*else if ( m_animator != null ) * { * UpdateHandAnimation(); * }*/ // Debug.Log(m_controller.Rotation.eulerAngles.x); }
protected override void UpdateObject(SixenseInput.Controller controller) { if (controller.Enabled) { UpdateHand(controller); } if (!m_enabled && controller.Trigger > 0.01f) { m_enabled = true; // delta controller position is relative to this point m_baseControllerPosition = new Vector3(controller.Position.x * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.z * Sensitivity.z); // this is the new start position m_initialPosition = this.gameObject.transform.localPosition; } if (m_enabled && controller.GetButton(SixenseButtons.START)) { m_enabled = false; } if (m_enabled) { UpdatePosition(controller); UpdateRotation(controller); } }
private void Update() { m_controller = SixenseInput.GetController(SixenseHands.LEFT); if (!m_Jump) { //m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } }
protected virtual void UpdateObject(SixenseInput.Controller controller) { if (m_enabled) { UpdatePosition(controller); UpdateRotation(controller); } }
// Unity - Update void Update() { if (Manager.IsHydraConnected()) { linkerController = SixenseInput.Controllers[(int)SixenseHands.LEFT]; rechterController = SixenseInput.Controllers[(int)SixenseHands.RIGHT]; } }
void Update() { hydraRight = SixenseInput.Controllers[1]; hydraLeft = SixenseInput.Controllers[0]; if(hydraLeft.GetButtonDown(SixenseButtons.TRIGGER) || hydraRight.GetButtonDown(SixenseButtons.TRIGGER)) { if(buttonHighlited == "StartTut") { Application.LoadLevelAsync("Level_00"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "StartHub") { Application.LoadLevelAsync("hub"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesPart1") { Application.LoadLevelAsync("pirates"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesSchiebe") { Application.LoadLevelAsync("SchiebeRätselPart1"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesDark") { Application.LoadLevelAsync("BelowTheDeck"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesPart2") { Application.LoadLevelAsync("pirates"); manager.pirateLevelPartTwo = true; keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesSchiebe2") { Application.LoadLevelAsync("SchieberätselPart2"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "Exit") { Application.Quit(); } } }
// Update is called once per frame void Update () { if(leftController == null) { leftController = leftHand.m_controller; } if(rightController == null) { rightController = rightHand.m_controller; } }
// Update is called once per frame protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { } Debug.DrawLine(transform.position, Vector3.forward); }
// Update is called once per frame void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController (m_hand); } else { ForwardSpeed (m_controller.JoystickY); LateralMovement (m_controller.JoystickX); } Debug.DrawLine(playerCam.transform.position, playerCam.transform.position + playerCam.transform.forward, Color.red); }
// Update is called once per frame void Update() { //var rot = controller.Rotation; if (controller == null) { controller = SixenseInput.Controllers[0]; start = controller.RotationRaw * transform.localRotation; } UpdateRotation(controller); }
protected void UpdatePosition(SixenseInput.Controller controller) { Vector3 controllerPosition = new Vector3(controller.Position.x * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.z * Sensitivity.z); // distance controller has moved since enabling positional control Vector3 vDeltaControllerPos = controllerPosition - m_baseControllerPosition; // update the localposition of the object this.gameObject.transform.localPosition = m_initialPosition + vDeltaControllerPos; }
void Start() { anim = GetComponentInChildren <Animation> (); leftHydra = SixenseInput.Controllers [0]; rightHydra = SixenseInput.Controllers [1]; if (b_mobile) { changeCameraPerspective(); } }
protected virtual void Update() { if ( m_controller == null ) { m_controller = SixenseInput.GetController( m_hand ); } else if ( m_animator != null ) { UpdateHandAnimation(); } }
void Update() { if (leftController == null || rightController == null) { leftController = SixenseInput.GetController(SixenseHands.LEFT); rightController = SixenseInput.GetController(SixenseHands.RIGHT); } if (rightController != null && rightController.Enabled) { //Rotate scene /*if (rightController.GetButtonDown (SixenseButtons.JOYSTICK)) { * * rotationX = player.transform.localEulerAngles.y + rightController.JoystickX * sensitivityX * Time.deltaTime; * * float joystickY = rightController.JoystickY; * * if (joystickY > 0.05f || joystickY < 0.0f) { * rotationY += rightController.JoystickY * sensitivitiY * Time.deltaTime; * rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); * } * * player.transform.localEulerAngles = new Vector3 (0, rotationX, 0); * * Camera.current.transform.localEulerAngles = new Vector3 (-rotationY, 0, 0); * } */ //if(leftController.GetButtonDown (SixenseButtons.JOYSTICK)) { float x = rightController.JoystickX; float y = rightController.JoystickY; float R_analog_threshold = 0.10f; if (Mathf.Abs(x) < R_analog_threshold) { x = 0.0f; } if (Mathf.Abs(y) < R_analog_threshold) { y = 0.0f; } if (x != 0.0f || y != 0.0f) { rotAngle = Mathf.Atan2(y, x) * Mathf.Rad2Deg; transform.Rotate(new Vector3(0, x, y)); } //} } }
protected void Update() { if ( m_controller == null ) { m_controller = SixenseInput.GetController( m_hand ); } // else if ( m_animator != null ) // { // UpdateHandAnimation(); // } }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else if (m_animator != null) { UpdateHandAnimation(); } }
// Update is called once per frame void Update() { if (Hand == SixenseHands.UNKNOWN) { return; } SixenseInput.Controller controller = SixenseInput.GetController(Hand); if (controller != null && controller.Enabled) { UpdateObject(controller); } }
protected override void Update() { // Get the input vector from hydra SixenseInput.Controller hydraRightController = SixenseInput.GetController(SixenseHands.RIGHT); if (hydraRightController != null) { axisX = hydraRightController.JoystickX; axisY = hydraRightController.JoystickY; } base.Update(); }
// Update is called once per frame void Update() { leftHydra = SixenseInput.Controllers [0]; rightHydra = SixenseInput.Controllers [1]; Vector3 moveVec = new Vector3(0, 0, 0); CalculateMovementSpeed(leftHydra, rightHydra); moveVec = (transform.forward * 100.0f) * f_speed; moveVec.y = -f_gravity; charControl.Move(moveVec * Time.deltaTime); }
bool ensureInitialization() { if (isInitialized) return true; Controller = SixenseInput.GetController(HandId); if (Controller != null) { isInitialized = true; //rotOffset = transform.rotation; // Quaternion.Inverse(Controller.Rotation); } return isInitialized; }
protected void UpdateActionInput(SixenseInput.Controller controller) { Vector3 currentPosition = GetCurrentColliderPosition(); Quaternion currentRotation = GetCurrentColliderRotation(); Velocity(); if (isHoldingObject && !controller.GetButton(SixenseButtons.TRIGGER)) { Throw(); isHoldingObject = false; } if (!isHoldingObject) { foreach (GameObject o in GameObject.FindGameObjectsWithTag("Grabbable")) { float dist = Vector3.Distance(o.transform.position, currentPosition); if (dist < minGrabDistance) { closestObject = o; } } } if ((isHoldingObject && controller.GetButton(SixenseButtons.TRIGGER)) || (closestObject != null && Vector3.Distance(closestObject.transform.position, currentPosition) < minGrabDistance && controller.GetButton(SixenseButtons.TRIGGER))) { if (closestObject.GetComponent <Rigidbody>() && closestObject.GetComponent <Rigidbody>().isKinematic) { return; } grabObject = closestObject.GetComponent <GrabObject>(); if (grabObject && grabObject.isEnabled) { grabObject.SetRigidbodyDetectionCollisions(false); closestObject.transform.position = currentPosition + closestObject.transform.TransformDirection(grabObject.GetPosition(Hand)); closestObject.transform.rotation = currentRotation * Quaternion.Euler(grabObject.GetRotation(Hand)); } else { closestObject.transform.position = currentPosition; closestObject.transform.rotation = currentRotation; } isHoldingObject = true; } }
// Update is called once per frame void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { ForwardSpeed(m_controller.JoystickY); LateralMovement(m_controller.JoystickX); } Debug.DrawLine(playerCam.transform.position, playerCam.transform.position + playerCam.transform.forward, Color.red); }
// Update is called once per frame void Update() { if (handL == null) { handL = GameObject.Find("Left Hand"); } if (handR == null) { handR = GameObject.Find("Right Hand"); } if (handL == null || handR == null) { return; } // Material mat = (Material) gameObject.GetComponent<Material>(); Vector3 l = handL.transform.position; Vector3 r = handR.transform.position; bool move = false; bool lCollide = gameObject.collider.bounds.Contains(l); bool rCollide = gameObject.collider.bounds.Contains(r); SixenseInput.Controller lControl = SixenseInput.GetController(SixenseHands.LEFT); SixenseInput.Controller rControl = SixenseInput.GetController(SixenseHands.RIGHT); if (lControl != null && rControl != null) { lDown = (lCollide || lDown) && lControl.GetButton(SixenseButtons.TRIGGER); rDown = (rCollide || rDown) && rControl.GetButton(SixenseButtons.TRIGGER); if (lDown && rDown) { move = true; //Vector3 v1 = gameObject.transform.rotation * (l - lPrev); //Vector3 v2 = gameObject.transform.rotation * (l - gameObject.transform.position); scaleSpeed = (r - l).magnitude - (rPrev - lPrev).magnitude; } lPrev = l; rPrev = r; } //gameObject.transform.Rotate(rotSpeed); totalScale += scaleSpeed; gameObject.transform.localScale = new Vector3(totalScale, totalScale, totalScale); scaleSpeed = scaleSpeed * .7f; //rotSpeed = new Vector3(0, 1, 0); }
public void ActivateHand(SixenseInput.Controller controller) { // enable position and orientation control m_enabled = true; // delta controller position is relative to this point m_baseControllerPosition = new Vector3(controller.Position.x * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.z * Sensitivity.z); // this is the new start position m_initialControllerRotation = controller.Rotation; m_initialPosition = this.gameObject.transform.localPosition; m_initialRotation = transform.rotation; }
protected override void UpdateObject(SixenseInput.Controller controller) { if (m_animator == null) { return; } if (controller.Enabled) { // Animation update UpdateAnimationInput(controller); } base.UpdateObject(controller); }
public void Calibrate(SixenseInput.Controller controller) { if (!this.m_bCalibrated) { this.m_handOffset = Vector3.zero; if ((double)controller.Trigger > 0.5) { this.m_bCalibrated = true; Vector3 vector3 = new Vector3(controller.Position.x * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.z * Sensitivity.z); this.m_handOffset = this.ShoulderPosition - vector3; //this.m_playerController.OffsetY = this.m_handOffset.y - this.BaseHandOffsetY; gameObject.transform.localPosition = vector3 + this.m_handOffset + Vector3.up; } } }
// initialisation and object-finding private void Init() { linkerFluegel = GameObject.Find("Wing-Left"); rechterFluegel = GameObject.Find("Wing-Right"); rb_main = gameObject.GetComponent<Rigidbody>(); if (Manager.IsHydraConnected()) { linkerController = SixenseInput.GetController(SixenseHands.LEFT); rechterController = SixenseInput.GetController(SixenseHands.RIGHT); linkeHand = GameObject.Find("Hand - Left"); rechteHand = GameObject.Find("Hand - Right"); } lastPosition_links = actPosition_links = lastPosition_rechts = actPosition_rechts = Vector3.zero; }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } // calculate velocity for left then right controller LVelocity = CalcVelocity(0); RVelocity = CalcVelocity(1); //handles input from hydra buttons and triggers }
// initialization void Start() { player = GameObject.Find("OVRPlayerController"); controller = player.GetComponent <CharacterController>(); HandRight = GameObject.Find("Right GunHand"); // r_animator= HandRight.GetComponent<Animator>(); TriggersRight = HandRight.GetComponent <HandTriggers>(); HandLeft = GameObject.Find("Left GunHand"); // l_animator= HandLeft.GetComponent<Animator>(); TriggersLeft = HandLeft.GetComponent <HandTriggers>(); HLC = SixenseInput.Controllers[0]; HRC = SixenseInput.Controllers[1]; }
void Update() { jump = false; if (characterController == null || !characterController.grounded) { return; } if ((Input.GetButtonDown("Jump") || JumpGestureTriggered())) { shouldJump = true; } if (useRazerHydra) { razerController = SixenseInput.GetController(razerHydraID); if (razerController != null && razerController.Enabled) { if (razerController.GetButtonDown(SixenseButtons.BUMPER)) { shouldJump = true; } } } // Check if jumping with PS Move Navigation controller if (usePSNavigationController && moveWrapper && moveWrapper.isConnected) { if (PSNaviControllerID <= moveWrapper.navConnected.Length && PSNaviControllerID >= 1) { if (moveWrapper.navConnected[PSNaviControllerID - 1]) { if (moveWrapper.WasPressed(PSNaviControllerID - 1, "NavL1")) { shouldJump = true; } } } } if (shouldJump) { jump = true; } }
private void Start() { m_controller = SixenseInput.GetController(SixenseHands.LEFT); // get the transform of the main camera if (Camera.main != null) { m_Cam = Camera.main.transform; } else { Debug.LogWarning( "Warning: no main camera found. Third person character needs a Camera tagged \"MainCamera\", for camera-relative controls."); // we use self-relative controls in this case, which probably isn't what the user wants, but hey, we warned them! } // get the third person character ( this should never be null due to require component ) m_Character = GetComponent<ThirdPersonCharacter>(); }
// Update is called once per frame void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController (m_hand); } else { if(m_controller.GetButtonDown(SixenseButtons.TRIGGER)){ shoot(); } if (lRenderer == null) { lRenderer = GetComponentInChildren (typeof(LineRenderer)) as LineRenderer; } else { Vector3 endPoint = (this.transform.position + (m_controller.Rotation * (Vector3.forward*length))); lRenderer.SetPosition(0, this.transform.position); lRenderer.SetPosition(1, endPoint); } } }
protected override void UpdateObject(SixenseInput.Controller controller) { if (controller.Enabled) { // Action update UpdateActionInput(controller); TriggerMouseLook(false); TriggerHydraLook(true); } else { TriggerMouseLook(true); TriggerHydraLook(false); } base.UpdateObject(controller); }
void RotateY(SixenseInput.Controller leftHydra, SixenseInput.Controller rightHydra) { float inputRotationY = 0.0f; if (b_keyboard) { inputRotationY = Input.GetAxis("Horizontal") * 0.5f; } else { inputRotationY = (rightHydra.Rotation.y + leftHydra.Rotation.y) / 2.0f; } if (inputRotationY < -0.03f || inputRotationY > 0.03f) { float yRot = transform.eulerAngles.y + (inputRotationY * 4); transform.rotation = Quaternion.Euler(new Vector3(0, yRot, 0)); } }
// Update is called once per frame void Update() { leftHydra = SixenseInput.Controllers [0]; rightHydra = SixenseInput.Controllers [1]; cooldown -= Time.deltaTime; //Debug.Log (cooldown); #if UNITY_ANDROID if (f_timeSinceLastDoubleTouch > 0.0f) #else if ((leftHydra.GetButton(SixenseButtons.BUMPER) && rightHydra.GetButton(SixenseButtons.BUMPER)) || Input.GetAxis("Fire1") > 0.0f) #endif { cooldown = 3.0f; } checkTouch(); }
protected void Update() { if ( m_controller == null ) { m_controller = SixenseInput.GetController( m_hand ); } else if ( m_animator != null ) { UpdateHandAnimation(); } if (m_hand == SixenseHands.RIGHT ? m_controller.GetButtonDown(SixenseButtons.TWO) : m_controller.GetButtonDown(SixenseButtons.ONE)) { initialHandPosition = m_controller.Position.z; Debug.Log(initialHandPosition); } }
public void OnAnimatorIK() { turningDeadTime -= Time.deltaTime; leftController = SixenseInput.GetController( SixenseHands.LEFT ); rightController = SixenseInput.GetController( SixenseHands.RIGHT ); if ( leftController == null || rightController == null ) { ChangeToState( State.Standing ); return; } bool leftTriggerActive = leftController.GetButton( SixenseButtons.TRIGGER ); bool rightTriggerActive = rightController.GetButton( SixenseButtons.TRIGGER ); if ( leftTriggerActive && rightTriggerActive ) ChangeToState ( State.Turning ); else if ( leftTriggerActive ) ChangeToState ( State.LeftFootPushes ); else if ( rightTriggerActive ) ChangeToState( State.RightFootPushes ); else ChangeToState( State.Standing ); switch ( state ) { case State.Turning: if ( turningDeadTime <= 0 ) Turn(); break; case State.LeftFootPushes: PushFootLeft(); break; case State.RightFootPushes: PushFootRight(); break; } lastLeftPos = leftController.Position; lastRightPos = rightController.Position; }
private void GetInput(out float speed) { // Read input float horizontal = CrossPlatformInputManager.GetAxis("Horizontal"); float vertical = CrossPlatformInputManager.GetAxis("Vertical"); //Get the input vector from Hydra SixenseInput.Controller hydraLeftController = SixenseInput.GetController(SixenseHands.LEFT); SixenseInput.Controller hydraRightController = SixenseInput.GetController(SixenseHands.RIGHT); if (hydraLeftController != null && hydraLeftController.Enabled) { //Debug.Log ("Controle ok!"); horizontal = hydraLeftController.JoystickX; vertical = hydraLeftController.JoystickY; } bool waswalking = m_IsWalking; #if !MOBILE_INPUT // On standalone builds, walk/run speed is modified by a key press. // keep track of whether or not the character is walking or running m_IsWalking = !Input.GetKey(KeyCode.LeftShift); #endif // set the desired speed to be walking or running speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed; m_Input = new Vector2(horizontal, vertical); // normalize input if it exceeds 1 in combined length: if (m_Input.sqrMagnitude > 1) { m_Input.Normalize(); } // handle speed change to give an fov kick // only if the player is going to a run, is running and the fovkick is to be used if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0) { StopAllCoroutines(); StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown()); } }
// Update is called once per frame void Update() { // Wenn die Hydra angeschlossen und initialisiert ist if (Manager.IsHydraConnected() && IsControllerActive()) { // .. wird geprüft, ob die Flügel ausgebreitet sind areWingsSprawled = CheckSprawl(); } // Wenn nur die Hydra angeschlossen ist (nicht initialisiert) else if (Manager.IsHydraConnected()) { // manchmal verliert sich die Initialisierung, daher hier nochmal.. linkerController = SixenseInput.GetController(SixenseHands.LEFT); rechterController = SixenseInput.GetController(SixenseHands.RIGHT); linkeHand = GameObject.Find("Hand - Left"); rechteHand = GameObject.Find("Hand - Right"); } // Setzen des aktuelles Modis SetMode(); }
protected virtual void UpdateObject(SixenseInput.Controller controller) { if (controller.GetButtonDown(SixenseButtons.START)) { // enable position and orientation control m_enabled = !m_enabled; // delta controller position is relative to this point m_baseControllerPosition = new Vector3(controller.Position.x * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.z * Sensitivity.z); // this is the new start position m_initialPosition = this.gameObject.transform.localPosition; } if (m_enabled) { UpdatePosition(controller); UpdateRotation(controller); } }
// Updates the animated object from controller input. private void UpdateHand(SixenseInput.Controller controller) { if (Hand == SixenseHands.RIGHT && vrGrabHand != null) { vrGrabHand.thumbInput = 0f; if (controller.GetButton(SixenseButtons.ONE)) { vrGrabHand.thumbInput = 0.5f; } if (controller.GetButton(SixenseButtons.THREE)) { vrGrabHand.thumbInput = 1f; } vrGrabHand.indexInput = controller.GetButton(SixenseButtons.BUMPER) ? 1 : 0; vrGrabHand.middleInput = controller.Trigger; vrGrabHand.ringInput = controller.Trigger; vrGrabHand.littleInput = controller.Trigger; } if (Hand == SixenseHands.LEFT && vrGrabHand != null) { vrGrabHand.thumbInput = 0f; if (controller.GetButton(SixenseButtons.TWO)) { vrGrabHand.thumbInput = 0.5f; } if (controller.GetButton(SixenseButtons.FOUR)) { vrGrabHand.thumbInput = 1f; } vrGrabHand.indexInput = controller.GetButton(SixenseButtons.BUMPER) ? 1 : 0; vrGrabHand.middleInput = controller.Trigger; vrGrabHand.ringInput = controller.Trigger; vrGrabHand.littleInput = controller.Trigger; } }
/* * Updaters */ void Update() { if (m_leftHandController == null) { m_leftHandController = SixenseInput.GetController(SixenseHands.LEFT); } if (m_rightHandController == null) { m_rightHandController = SixenseInput.GetController(SixenseHands.RIGHT); } //Hand velocities m_leftHandVelocity = m_leftHand.transform.position - m_lastLeftHandPos; m_rightHandVelocity = m_rightHand.transform.position - m_lastRightHandPos; m_lastLeftHandPos = m_leftHand.transform.position; m_lastRightHandPos = m_rightHand.transform.position; SetCommonTools(BaseTool.ToolHand.LEFT); SetCommonTools(BaseTool.ToolHand.RIGHT); SetIndividualToolsRight(BaseTool.ToolHand.LEFT); //SetRhythmTools(m_rhythmGlove); }
protected void Update() { if ( m_controller == null ) { m_controller = SixenseInput.GetController( m_hand ); if (m_controller == null) { return; } } float fTriggerVal = m_controller.Trigger; //fTriggerVal = Mathf.Lerp( m_fLastTriggerVal, fTriggerVal, 0.1f ); //m_fLastTriggerVal = fTriggerVal; if ( fTriggerVal > 0.01f ) { Grab(); } else { Ungrab(); } }
// Use this for initialization IEnumerator Start () { if (hand == SixenseHands.RIGHT) { ChunkManager.Instance.LoadChunks(scene + ".vox"); } while (SixenseInput.GetController(hand) == null) { yield return null; } var renderers = GetComponentsInChildren<Renderer>(true); for (int i = 0; i < renderers.Length; i++) { renderers[i].enabled = true; } material = GetComponentInChildren<Renderer>().sharedMaterial; material.color = MarchingCubes.Builder.colorMap[color]; controller = SixenseInput.GetController(hand); }
// Update is called once per frame void Update() { if(Input.GetKeyDown("2")) { GetComponent<ShieldController>().riseShield(); } if (projectilePowerIsActive > 0 && Input.GetKeyDown("1") /*hand.GetComponent<Transform>().rotation.x < 0.5*/) { if (!GetComponentInChildren<ShootProjectile>().getThrowed()) { GetComponentInChildren<ShootProjectile>().sendProjectile(); projectilePowerIsActive--; soundGoalSource.Play(); } } m_controller = SixenseInput.GetController(SixenseHands.LEFT); if (/*m_controller.GetButtonDown(SixenseButtons.TRIGGER)*/Input.GetKeyDown("3")) { if (ballTrapPowerIsActive > 0 && !ball.GetComponent<Control>().trapmat ) { ballTrapPowerIsActive--; ball.GetComponent<Control>().setTrap(); } } if (blurVision) { if (resetTimer) { GetComponentInChildren<UnityStandardAssets.ImageEffects.Blur>().enabled = true; startTime = Time.time; resetTimer = false; } currentTimer = 5.0f - (Time.time - startTime); if (startTime + 5.0f < Time.time) { GetComponentInChildren<UnityStandardAssets.ImageEffects.Blur>().enabled = false; resetTimer = true; blurVision = false; } } if (shieldPowerIsActive > 0 && /*Input.GetKeyDown("2")*/m_controller.GetButtonUp(SixenseButtons.ONE)) { if ((hand.GetComponent<Transform>().position.y - initialPosition) > 0.1) { GetComponent<ShieldController>().riseShield(); shieldPowerIsActive--; } } if (terrainPowerIsActive > 0 && /*Input.GetKeyDown("2")*/m_controller.GetButtonUp(SixenseButtons.TWO)) { if(localPointTerrainRaycasting.Equals(NULL_VECTOR3)) localPointTerrainRaycasting = GetComponent<RayCasting>().sendRaycast(); if ( !localPointTerrainRaycasting.Equals(NULL_VECTOR3) &&((hand.GetComponent<Transform>().position.y - initialPosition) > 0.1)) { GetComponent<RaiseLowerTerrain>().riseController(localPointTerrainRaycasting); terrainPowerIsActive--; localPointTerrainRaycasting = NULL_VECTOR3; Debug.Log("raiseterrain"); } } if(m_controller.GetButtonDown(SixenseButtons.ONE)) { initialPosition = hand.GetComponent<Transform>().position.y; } if (m_controller.GetButtonDown(SixenseButtons.TWO)) { initialPosition = hand.GetComponent<Transform>().position.y; Debug.Log(initialPosition); } if (m_controller.GetButtonDown(SixenseButtons.FOUR)) { initialRotation = hand.GetComponent<Transform>().rotation.x; } }
private void ConnectHydra() { if (SixenseInput.IsBaseConnected(0) != false) { hydra = SixenseInput.Controllers[0]; // SixensePlugin.sixenseAutoEnableHemisphereTracking(0); } }
private void Update() { //RotateView(); m_controller_right = SixenseInput.GetController(SixenseHands.RIGHT); m_controller = SixenseInput.GetController(SixenseHands.LEFT); RotateViewWithRazer(); /*if (CrossPlatformInputManager.GetButtonDown("Jump") && !m_Jump) { m_Jump = true; }*/ if(slowed) { movementSettings.BackwardSpeed = 8.0f; movementSettings.ForwardSpeed = 8.0f; movementSettings.StrafeSpeed = 8.0f; if (resetTimer) { startTime = Time.time; resetTimer = false; } if (startTime + 5.0f < Time.time) { resetTimer = true; slowed = false; movementSettings.BackwardSpeed = 15.0f; movementSettings.ForwardSpeed = 15.0f; movementSettings.StrafeSpeed = 15.0f; } } }
private void updateTracker(float deltaT) { // Lets reduce the amount of required if clauses by setting the following: if(!externalDriftCorrection) compass = CompassSource.None; if(useOculusRiftRotation) headRotationInput = HeadRotationSource.None; else if( headRotationInput == HeadRotationSource.Kinect || headRotationInput == HeadRotationSource.PSMove || headRotationInput == HeadRotationSource.RazerHydra || headRotationInput == HeadRotationSource.None ) compass = CompassSource.None; // The above rotation sources do not need yaw drift correction if( headPositionInput != HeadPositionSource.RazerHydra && headRotationInput != HeadRotationSource.RazerHydra && compass != CompassSource.RazerHydra ) { isRazerBaseMobile = false; // If Razer Hydra is not used as a source then this can be false } // Reset view if necessary bool checkRazer = false; bool checkPSMove = false; // Reset view: Is PS Move used for tracking? if (inputManager) { if(headPositionInput == HeadPositionSource.PSMove) { posePSMove = inputManager.GetMoveWand(positionPSMoveID); checkPSMove = true; } else if(compass == CompassSource.PSMove) { posePSMove = inputManager.GetMoveWand(compassPSMoveID); checkPSMove = true; } else if(headRotationInput == HeadRotationSource.PSMove) { posePSMove = inputManager.GetMoveWand(rotationPSMoveID); checkPSMove = true; } } // Reset view: Is Razer Hydra used for tracking? if(headPositionInput == HeadPositionSource.RazerHydra) { poseRazer = SixenseInput.GetController(positionRazerID); checkRazer = true; } else if(compass == CompassSource.RazerHydra) { poseRazer = SixenseInput.GetController(compassRazerID); checkRazer = true; } else if(headRotationInput == HeadRotationSource.RazerHydra) { poseRazer = SixenseInput.GetController(rotationRazerID); checkRazer = true; } // Reset view: Check if reset view button was pressed if(checkPSMove && posePSMove != null) { if(posePSMove.moveButtonWasPressed) ResetOrientation(); } if(checkRazer && poseRazer != null && poseRazer.Enabled) { if( poseRazer.GetButton(SixenseButtons.BUMPER) && poseRazer.GetButtonDown(SixenseButtons.START) ) ResetOrientation(); } if(Input.GetKeyDown(resetKey)) ResetOrientation(); /* If we are using Razer Hydra and it's attached to a moving object (i.e. the user), lets calculate the position and rotation of the base station */ if(isRazerBaseMobile) // In the beginning of the method we coupled this to tracker sources { // Adjust hydraBasePositionOffset and hydraBaseRotationOffset if BUMPER button is down if(headPositionInput == HeadPositionSource.RazerHydra) poseRazer = SixenseInput.GetController(positionRazerID); else if(headRotationInput == HeadRotationSource.RazerHydra) poseRazer = SixenseInput.GetController(rotationRazerID); else if(compass == CompassSource.RazerHydra) poseRazer = SixenseInput.GetController(compassRazerID); if(poseRazer != null && poseRazer.Enabled && poseRazer.GetButton(SixenseButtons.BUMPER)) { if(Mathf.Abs(poseRazer.JoystickX) > 0.1f) { if(mobileRazerBase == RazerHydraBase.Kinect) hydraBasePositionOffsetKinect.x += 0.5f*deltaT*poseRazer.JoystickX; } if(Mathf.Abs(poseRazer.JoystickY) > 0.1f) { if(mobileRazerBase == RazerHydraBase.Kinect) hydraBasePositionOffsetKinect.y += 0.5f*deltaT*poseRazer.JoystickY; } if(poseRazer.GetButton(SixenseButtons.THREE)) { if(mobileRazerBase == RazerHydraBase.Kinect) hydraBaseRotationOffsetKinect.x += 60*deltaT; } if(poseRazer.GetButton(SixenseButtons.ONE)) { if(mobileRazerBase == RazerHydraBase.Kinect) hydraBaseRotationOffsetKinect.x -= 60*deltaT; } } switch(mobileRazerBase) { case RazerHydraBase.Kinect: if (skeletonManager) { jointData = skeletonManager.GetJointData(hydraBaseJoint, hydraBaseKinectPlayerID); if( skeletonManager.skeletons[hydraBaseKinectPlayerID].isTracking && jointData != null) { filterHydraBasePose = filterHydraBasePoseKinect; hydraBasePositionCovariance = hydraBasePositionCovarianceKinect + Mathf.Clamp01(1.0f - jointData.positionConfidence)*2000; hydraBaseRotationCovariance = hydraBaseRotationCovarianceKinect; if( inferBaseRotationFromRotationTrackerKinect && headRotationInput != HeadRotationSource.RazerHydra) { // Assuming that poseRazer is attached to Rotation Tracker if(poseRazer != null && poseRazer.Enabled) { // Offset-adjusted Razer Hydra rotation in offset-adjusted base station coordinate // system: Rotation from base to Razer Hydra tempLocalRotation = Quaternion.Euler(hydraBaseRotationOffsetKinect) * poseRazer.Rotation * Quaternion.Inverse(Quaternion.Euler(hydraAtRotationTrackerOffset)); // Subtract above rotation from Rotation Tracker's rotation (drift corrected, if enabled) hydraTempRotation = localRotation * Quaternion.Inverse(tempLocalRotation); // Get yaw rotation of above, result is the base station's yaw in Unity world coordinates hydraTempRotation = Quaternion.Euler(0, hydraTempRotation.eulerAngles.y, 0) ; // hydraTempVector will become hydraBasePosition after filtering hydraTempVector = jointData.position + hydraTempRotation * hydraBasePositionOffsetKinect; // Apply base station offset to hydraTempRotation, that will become hydraBaseRotation hydraTempRotation = hydraTempRotation * Quaternion.Euler(hydraBaseRotationOffsetKinect); } } else { hydraTempVector = jointData.position + jointData.rotation * hydraBasePositionOffsetKinect; hydraTempRotation = jointData.rotation * Quaternion.Euler(hydraBaseRotationOffsetKinect); hydraBaseRotationCovariance += Mathf.Clamp01(1.0f - jointData.rotationConfidence)*2000; } } } break; case RazerHydraBase.InputTransform: if(hydraBaseInput) { filterHydraBasePose = filterHydraBasePoseTransform; hydraBasePositionCovariance = hydraBasePositionCovarianceTransform; hydraBaseRotationCovariance = hydraBaseRotationCovarianceTransform; if( inferBaseRotationFromRotationTrackerTransform && headRotationInput != HeadRotationSource.RazerHydra) { // Assuming that poseRazer is attached to Rotation Tracker if(poseRazer != null && poseRazer.Enabled) { // Offset-adjusted Razer Hydra rotation in base station coordinate // system: Rotation from base to Razer Hydra tempLocalRotation = poseRazer.Rotation * Quaternion.Inverse(Quaternion.Euler(hydraAtRotationTrackerOffset)); // Subtract above rotation from Rotation Tracker's rotation (drift corrected, if enabled) hydraTempRotation = localRotation * Quaternion.Inverse(tempLocalRotation); // Get yaw rotation of above, result is the base station's yaw in Unity world coordinates hydraTempRotation = Quaternion.Euler(0, hydraTempRotation.eulerAngles.y, 0) ; // hydraTempVector will become hydraBasePosition after filtering hydraTempVector = hydraBaseInput.position; } } else { hydraTempVector = hydraBaseInput.position; hydraTempRotation = hydraBaseInput.rotation; } } break; default: filterHydraBasePose = false; break; } if(filterHydraBasePose) { measuredPos[0] = hydraTempVector.x; measuredPos[1] = hydraTempVector.y; measuredPos[2] = hydraTempVector.z; hydraBaseFilterPos.setR(deltaT * hydraBasePositionCovariance); hydraBaseFilterPos.predict(); hydraBaseFilterPos.update(measuredPos); filteredPos = hydraBaseFilterPos.getState(); hydraBasePosition = new Vector3( (float) filteredPos[0], (float) filteredPos[1], (float) filteredPos[2] ); } else hydraBasePosition = hydraTempVector; // float normalizedT = Mathf.Clamp01(deltaT * 5); // if(normalizedT != 0) // hydraBasePosition = Vector3.Lerp(hydraBasePosition, hydraTempVector, normalizedT ); if(filterHydraBasePose) { // measuredRot[0] = hydraTempRotation.x; // measuredRot[1] = hydraTempRotation.y; // measuredRot[2] = hydraTempRotation.z; // measuredRot[3] = hydraTempRotation.w; // hydraBaseFilterRot.setR(deltaT * hydraBaseRotationCovariance); // hydraBaseFilterRot.predict(); // hydraBaseFilterRot.update(measuredRot); // filteredRot = hydraBaseFilterRot.getState(); // hydraBaseRotation = new Quaternion( (float) filteredRot[0], (float) filteredRot[1], // (float) filteredRot[2], (float) filteredRot[3] ); hydraBaseKalmanRot.rotationNoiseCovariance = hydraBaseRotationCovariance; hydraBaseRotation = hydraBaseKalmanRot.Update(hydraTempRotation, deltaT); } else hydraBaseRotation = hydraTempRotation; // normalizedT = Mathf.Clamp01(deltaT * 5); // if(normalizedT != 0) // hydraBaseRotation = Quaternion.Lerp(hydraBaseRotation, hydraTempRotation, normalizedT); } else { hydraBasePosition = new Vector3(0, 0, 0); hydraBaseRotation = Quaternion.identity; } switch(headPositionInput) { case HeadPositionSource.Kinect: if ( skeletonManager && skeletonManager.skeletons[positionPlayerID].torso.positionConfidence >= 1) // Most stable joint is torso { filterPosition = filterPositionKinect; positionNoiseCovariance = positionNoiseCovarianceKinect; jointData = skeletonManager.GetJointData(positionJoint, positionPlayerID); if(jointData != null) measuredHeadPosition = jointData.position // Fix for Kinect2: below takes rotation from torso - skeletonManager.skeletons[positionPlayerID].torso.rotation * Quaternion.Inverse(Quaternion.Euler(rotationOffsetKinect)) * positionOffsetKinect; } break; case HeadPositionSource.PSMove: if (inputManager) { posePSMove = inputManager.GetMoveWand(positionPSMoveID); if(posePSMove) { filterPosition = filterPositionPSMove; positionNoiseCovariance = positionNoiseCovariancePSMove; measuredHeadPosition = posePSMove.localPosition - posePSMove.localRotation * Quaternion.Inverse(Quaternion.Euler(rotationOffsetPSMove)) * positionOffsetPSMove; } } break; case HeadPositionSource.RazerHydra: poseRazer = SixenseInput.GetController(positionRazerID); if(poseRazer != null && poseRazer.Enabled) { filterPosition = filterPositionHydra; positionNoiseCovariance = positionNoiseCovarianceHydra; measuredHeadPosition = new Vector3( poseRazer.Position.x * sensitivity.x, poseRazer.Position.y * sensitivity.y, poseRazer.Position.z * sensitivity.z ) - poseRazer.Rotation * Quaternion.Inverse(Quaternion.Euler(rotationOffsetHydra)) * positionOffsetHydra; if(isRazerBaseMobile) measuredHeadPosition = hydraBasePosition + hydraBaseRotation*measuredHeadPosition; } break; case HeadPositionSource.InputTransform: if(positionInput) { filterPosition = filterPositionTransform; positionNoiseCovariance = positionNoiseCovarianceTransform; measuredHeadPosition = positionInput.position; } break; case HeadPositionSource.None: filterPosition = false; break; } if (filterPosition) { measuredPos[0] = measuredHeadPosition.x; measuredPos[1] = measuredHeadPosition.y; measuredPos[2] = measuredHeadPosition.z; filterPos.setR(deltaT * positionNoiseCovariance); filterPos.predict(); filterPos.update(measuredPos); filteredPos = filterPos.getState(); localPosition = new Vector3((float) filteredPos[0], (float) filteredPos[1], (float) filteredPos[2]); transform.localPosition = localPosition; } else { //if((localPosition - measuredHeadPosition).magnitude > 0.3f) // Debug.LogError("aa " + (localPosition - measuredHeadPosition).magnitude + "locR " /// + localRotation + "bPos " + hydraBasePosition+ "bRot " + hydraBaseRotation); //else print ("ok " + (localPosition - measuredHeadPosition).magnitude + "locR " // + localRotation + "bPos " + hydraBasePosition+ "bRot " + hydraBaseRotation); localPosition = measuredHeadPosition; transform.localPosition = measuredHeadPosition; } // Determine whether rotation source is Oculus Rift or some other device if(useOculusRiftRotation) { if(OVRDevice.IsSensorPresent(oculusID)) { if(!OVRDevice.GetOrientation(oculusID, ref tempLocalRotation)) tempLocalRotation = Quaternion.identity; } } else { switch(headRotationInput) { //case HeadRotationSource.OculusRift: // In this case rotation is applied by OVRCameraController which should be parented // under this GameObject // break; case HeadRotationSource.Kinect: if ( skeletonManager && skeletonManager.skeletons[rotationPlayerID].torso.rotationConfidence >= 1) { filterRotation = filterRotationKinect; rotationNoiseCovariance = rotationNoiseCovarianceKinect; jointData = skeletonManager.GetJointData(rotationJoint, rotationPlayerID); // Most stable joint: if(jointData != null && jointData.rotationConfidence >= 1) measuredHeadRotation = jointData.rotation * Quaternion.Inverse(Quaternion.Euler(rotationOffsetKinect)); } break; case HeadRotationSource.PSMove: if (inputManager) { posePSMove = inputManager.GetMoveWand(rotationPSMoveID); if(posePSMove) { filterRotation = filterRotationPSMove; rotationNoiseCovariance = rotationNoiseCovariancePSMove; measuredHeadRotation = posePSMove.localRotation * Quaternion.Inverse(Quaternion.Euler(rotationOffsetPSMove)); } } break; case HeadRotationSource.RazerHydra: poseRazer = SixenseInput.GetController(rotationRazerID); if(poseRazer != null && poseRazer.Enabled) { filterRotation = filterRotationHydra; rotationNoiseCovariance = rotationNoiseCovarianceHydra; measuredHeadRotation = poseRazer.Rotation * Quaternion.Inverse(Quaternion.Euler(rotationOffsetHydra)); if(isRazerBaseMobile) measuredHeadRotation = hydraBaseRotation * measuredHeadRotation; } break; case HeadRotationSource.InputTransform: if(rotationInput) { filterRotation = filterRotationTransform; rotationNoiseCovariance = rotationNoiseCovarianceTransform; measuredHeadRotation = rotationInput.rotation; } break; case HeadRotationSource.None: filterRotation = false; break; } if (filterRotation) { // measuredRot[0] = measuredHeadRotation.x; // measuredRot[1] = measuredHeadRotation.y; // measuredRot[2] = measuredHeadRotation.z; // measuredRot[3] = measuredHeadRotation.w; // filterRot.setR(deltaT * rotationNoiseCovariance); // filterRot.predict(); // filterRot.update(measuredRot); // filteredRot = filterRot.getState(); // tempLocalRotation = new Quaternion( (float) filteredRot[0], (float) filteredRot[1], // (float) filteredRot[2], (float) filteredRot[3] ); filterRot.rotationNoiseCovariance = rotationNoiseCovariance; tempLocalRotation = filterRot.Update(measuredHeadRotation, deltaT); } else tempLocalRotation = measuredHeadRotation; } rawRotation = tempLocalRotation; // Do yaw drift correction for rotation source if that option is enabled and necessary if( !externalDriftCorrection || compass == CompassSource.None ) { localRotation = rawRotation; transform.localRotation = rawRotation; } else { localRotation = driftCorrectedRotation(tempLocalRotation, deltaT); transform.localRotation = localRotation; } }
private void Start() { m_RigidBody = GetComponent<Rigidbody>(); m_Capsule = GetComponent<CapsuleCollider>(); mouseLook.Init (transform, cam.transform); m_controller = SixenseInput.GetController(SixenseHands.LEFT); }
private void doYawFiltering(Quaternion driftingOrientation, float deltaT) { // If the Rift is HeadRotationSource, we need to apply the yaw correction to it if(useOculusRiftRotation) { if(OVRDevice.IsSensorPresent(oculusID)) { if(oculusCamController) { // In the future OVR SDK oculusCamController will have oculusID? oculusCamController.SetYRotation(-finalYawDifference.eulerAngles.y); } } } driftingEuler = driftingOrientation.eulerAngles; // You can set compassIsPositionTracker to true in a script and it will work as // expected, but if you return it to false, it doesn't remember what the compass // was before setting it to true // if(compassIsPositionTracker) // { // if(headPositionInput == HeadPositionSource.None) // return; // Don't do yaw drift correction in this case // // switch(headPositionInput) // { // case HeadPositionSource.Kinect: // compass = CompassSource.Kinect; // compassPlayerID = positionPlayerID; // compassJoint = positionJoint; // break; // case HeadPositionSource.PSMove: // compass = CompassSource.PSMove; // compassPSMoveID = positionPSMoveID; // break; // case HeadPositionSource.RazerHydra: // compass = CompassSource.RazerHydra; // compassRazerID = positionRazerID; // break; // case HeadPositionSource.InputTransform: // compass = CompassSource.InputTransform; // compassTransform = positionInput; // break; // } // } float driftCorrectionRate = 0.1f; switch(compass) { case CompassSource.Kinect: if (!skeletonManager || !skeletonManager.skeletons[compassPlayerID].isTracking) { break; } else { compassData = skeletonManager.GetJointData(compassJoint, compassPlayerID); // First check for high confidence value if (compassData != null && compassData.rotationConfidence >= 1.0f) { driftCorrectionRate = driftCorrectionRateKinect; updateDifferenceKalman( (compassData.rotation * Quaternion.Inverse(Quaternion.Euler(compassRotationOffsetKinect))).eulerAngles, driftingEuler, deltaT ); } } break; case CompassSource.PSMove: if (inputManager) { compassPSMove = inputManager.GetMoveWand(compassPSMoveID); if(compassPSMove) { driftCorrectionRate = driftCorrectionRatePSMove; updateDifferenceKalman( (compassPSMove.localRotation * Quaternion.Inverse(Quaternion.Euler(compassRotationOffsetPSMove))).eulerAngles, driftingEuler, deltaT ); } } break; case CompassSource.RazerHydra: compassRazer = SixenseInput.GetController(compassRazerID); if(compassRazer != null && compassRazer.Enabled) { driftCorrectionRate = driftCorrectionRateHydra; if(isRazerBaseMobile) updateDifferenceKalman((hydraBaseRotation * compassRazer.Rotation * Quaternion.Inverse(Quaternion.Euler(compassRotationOffsetHydra))).eulerAngles, driftingEuler, deltaT ); else updateDifferenceKalman( (compassRazer.Rotation * Quaternion.Inverse(Quaternion.Euler(compassRotationOffsetHydra))).eulerAngles, driftingEuler, deltaT ); } break; case CompassSource.InputTransform: if(compassTransform != null) { driftCorrectionRate = driftCorrectionRateTransform; updateDifferenceKalman( compassTransform.rotation.eulerAngles, driftingEuler, deltaT ); } break; } float normalizedT = Mathf.Clamp01(deltaT * driftCorrectionRate); if(normalizedT != 0) finalYawDifference = Quaternion.Lerp(finalYawDifference, filteredYawDifference, normalizedT ); // TODO: REMOVE THIS *** // if(finalYawDifference.x*finalYawDifference.x + finalYawDifference.y*finalYawDifference.y // + finalYawDifference.z*finalYawDifference.z + finalYawDifference.w*finalYawDifference.w < 0.3) // Debug.LogError("LERP:ing quaternions was a bad idea: " + finalYawDifference); if(enableVisualizers) { if(driftingDirectionVisualizer != null) driftingDirectionVisualizer.transform.rotation = driftingOrientation; if(correctedDirectionVisualizer != null) correctedDirectionVisualizer.transform.rotation = Quaternion.Euler( new Vector3(driftingEuler.x, (360 + driftingEuler.y - finalYawDifference.eulerAngles.y)%360, driftingEuler.z)); if(driftVisualizerPosition != null) { if(driftingDirectionVisualizer != null) driftingDirectionVisualizer.transform.position = driftVisualizerPosition.position; if(compassDirectionVisualizer != null) compassDirectionVisualizer.transform.position = driftVisualizerPosition.position; if(correctedDirectionVisualizer != null) correctedDirectionVisualizer.transform.position = driftVisualizerPosition.position; } } }
/// <summary> /// Sets the Rotation Tracker's rotation offset (euler angles) to the source /// rotation's current value. The resulting rotation offset will be correct /// if the tracked object (e.g. head) is oriented along Unity world coordinates, /// i.e. the tracked object is "looking" into +Z-direction while its "top" is /// pointing into +Y-direction. /// </summary> public Vector3 CalibrateRotationOffset() { filterRot.Reset(); switch(headRotationInput) { case HeadRotationSource.Kinect: if (skeletonManager) { jointData = skeletonManager.GetJointData(rotationJoint, rotationPlayerID); if(jointData != null) { rotationOffsetKinect = jointData.rotation.eulerAngles; return rotationOffsetKinect; } } break; case HeadRotationSource.PSMove: if (inputManager) { posePSMove = inputManager.GetMoveWand(rotationPSMoveID); if(posePSMove) { rotationOffsetPSMove = posePSMove.localRotation.eulerAngles; return rotationOffsetPSMove; } } break; case HeadRotationSource.RazerHydra: poseRazer = SixenseInput.GetController(rotationRazerID); if(poseRazer != null && poseRazer.Enabled) { rotationOffsetHydra = poseRazer.Rotation.eulerAngles; return rotationOffsetHydra; } break; } return Vector3.zero; }
void FixedUpdate() { //characterController.ApplyForceInCharacterDirection(translation); float locomotionScale = Mathf.Max(transform.lossyScale.x, transform.lossyScale.z); direction = 0; turnMagnitude = 0; if(characterController != null) { grounded = characterController.grounded; colliding = characterController.colliding; } if(grounded || colliding) { airborne = false; } else { if(!airborne) { jumpTimeVelocity = GetComponent<Rigidbody>().velocity; jumpTimeVelocity.y = 0; jumpTimeVelocity = Vector3.ClampMagnitude(jumpTimeVelocity, aerialMobility*speed*locomotionScale); airborneAccumulatedVelocity = jumpTimeVelocity; } airborne = true; } targetVelocity = Vector2.zero; extraSpeed = 0; try { targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); } catch (UnityException) { } try { extraSpeed = Input.GetAxis("Sprint"); if (!airborne) targetVelocity *= 1 + extraSpeed*runAdder; } catch (UnityException) { } // Check if moving with PS Move Navigation controller if (PSNaviControllerID < 1) { Debug.LogError("PSNaviControllerID was set to " + PSNaviControllerID + " which is incorrect value: It must be positive!"); } else if (usePSNavigationController && moveWrapper && moveWrapper.isConnected) { if (PSNaviControllerID <= moveWrapper.navConnected.Length) { if (moveWrapper.navConnected[PSNaviControllerID-1]) { int horiz = moveWrapper.valueNavAnalogX[PSNaviControllerID-1]; int verti = moveWrapper.valueNavAnalogY[PSNaviControllerID-1]; if(!airborne) extraSpeed = ((float)moveWrapper.valueNavL2[PSNaviControllerID-1]) / 255f; else extraSpeed = 0; if (Mathf.Abs(verti) > 20) targetVelocity += new Vector3(0, 0, -((float)verti) / 128f * (1 + extraSpeed*runAdder)); if (strafeInsteadTurning) { if (Mathf.Abs(horiz) > 20) targetVelocity += new Vector3(((float)horiz) / 128f * (1 + extraSpeed*runAdder), 0, 0); } else { if (Mathf.Abs(horiz) > 10) { turnMagnitude += ((float)horiz) / 128f; } } if(moveWrapper.isNavButtonCross[PSNaviControllerID-1]) turnMagnitude -= 1; if(moveWrapper.isNavButtonCircle[PSNaviControllerID-1]) turnMagnitude += 1; } } else { Debug.LogError("PSNaviControllerID was set to " + PSNaviControllerID + " which is too big value: It must be below 8."); } } // TUUKKA if (useRazerHydra) // Check if moving with Razer Hydra controller { razerController = SixenseInput.GetController(razerHydraID); if (razerController != null && razerController.Enabled) { if(!airborne) if(razerController.GetButton(SixenseButtons.JOYSTICK)) extraSpeed = 1; //razerController.Trigger; else extraSpeed = 0; if (Mathf.Abs(razerController.JoystickY) > 0.15f) targetVelocity += new Vector3(0, 0, razerController.JoystickY * (1 + extraSpeed*runAdder)); if (strafeInsteadTurning) { if (Mathf.Abs(razerController.JoystickX) > 0.15f) targetVelocity += new Vector3(razerController.JoystickX * (1 + extraSpeed*runAdder), 0, 0); } else { if (Mathf.Abs(razerController.JoystickX) > 0.075f) { turnMagnitude += razerController.JoystickX; } } if(razerController.GetButton(SixenseButtons.THREE)) turnMagnitude -= 1; if(razerController.GetButton(SixenseButtons.FOUR)) turnMagnitude += 1; } } // controlDirection is a unit vector that shows the direction where the joystick is pressed controlDirection = Vector3.ClampMagnitude(targetVelocity, 1); // desiredVelocity is a vector with magnitude between 0 (not moving) and 2 (sprinting) desiredVelocity = Vector3.ClampMagnitude(targetVelocity, 1 + extraSpeed); // Limit comes from [0,1] + extraSpeed*runAdder targetVelocity = Vector3.ClampMagnitude(targetVelocity, 1 + extraSpeed*runAdder); targetVelocity = characterController.TransformDirection(targetVelocity); targetVelocity *= speed*locomotionScale; velocity = GetComponent<Rigidbody>().velocity; velocityChange = (targetVelocity - velocity); velocityChange.y = 0; velocityChange = Vector3.ClampMagnitude(velocityChange, Time.fixedDeltaTime * maxVelocityChange * locomotionScale); if(!airborne) { GetComponent<Rigidbody>().AddForce(velocityChange, ForceMode.VelocityChange); } else { // Calculate constant air drag whose direction is opposite to the current horizontal velocity vector tempVelocity = velocity; tempVelocity.y = 0; tempAcceleration = -aerialDrag * tempVelocity.normalized ; tempAcceleration.y = 0; // The drag should only stop the character, not push him like a wind in the opposite direction // This condition is true when the tempVelocity is close to zero and its normalization fails if(Vector3.Dot(tempVelocity, tempAcceleration) >= 0) { tempAcceleration = Vector3.zero; } // Calculate proposed acceleration as a sum of player controls and air drag proposedAcceleration = (aerialAcceleration*characterController.TransformDirection(desiredVelocity) + tempAcceleration) * locomotionScale; // Integrate proposed total velocity = old velocity + proposed acceleration * deltaT proposedVelocity = (airborneAccumulatedVelocity + proposedAcceleration*Time.fixedDeltaTime); // If the proposed total velocity is not inside "aerial velocity disc", then shorten the proposed velocity // with length of [proposed acceleration * deltaT]. This allows aerial maneuvers along the edge of the disc (circle). // In other words: If you have reach maximum aerial velocity to certain direction, you can still control the // velocity in the axis that is perpendicular to that direction if(proposedVelocity.magnitude >= aerialMobility*speed* locomotionScale) { proposedVelocity -= 1.01f*airborneAccumulatedVelocity.normalized*proposedAcceleration.magnitude*Time.fixedDeltaTime; proposedAcceleration -= 1.01f*airborneAccumulatedVelocity.normalized*proposedAcceleration.magnitude; } // If the proposed total velocity is within allowed "aerial velocity disc", then add the proposed // acceleration to the character and update the accumulatedAerialSpeed accordingly if(proposedVelocity.magnitude < aerialMobility*speed*locomotionScale) { GetComponent<Rigidbody>().AddForce(proposedAcceleration, ForceMode.Acceleration); airborneAccumulatedVelocity = proposedVelocity; } } try { turnMagnitude += Input.GetAxis("Turn"); } catch (UnityException) { } if(Input.GetKey(turnLeftKey)) turnMagnitude -= 1; if(Input.GetKey(turnRightKey)) turnMagnitude += 1; if(turnMagnitude != 0) characterController.RotateAroundCharacterPivot(new Vector3(0, turnMagnitude * rotationScaler * Time.fixedDeltaTime, 0)); if (shouldJump) { GetComponent<Rigidbody>().AddForce( new Vector3(0, Mathf.Sqrt((1 + 0.5f*(controlDirection.magnitude + extraSpeed)*jumpSpeedEffect)*jumpStrength*locomotionScale) * GetComponent<Rigidbody>().mass, 0), ForceMode.Impulse); if(characterController) characterController.lastJumpTime = Time.fixedTime; shouldJump = false; } }
void Update() { jump = false; if(characterController == null || !characterController.grounded) return; if ((Input.GetButtonDown("Jump") || JumpGestureTriggered())) { shouldJump = true; } if(useRazerHydra) { razerController = SixenseInput.GetController(razerHydraID); if(razerController != null && razerController.Enabled) { if(razerController.GetButtonDown(SixenseButtons.BUMPER)) shouldJump = true; } } // Check if jumping with PS Move Navigation controller if (usePSNavigationController && moveWrapper && moveWrapper.isConnected) { if (PSNaviControllerID <= moveWrapper.navConnected.Length && PSNaviControllerID >= 1) { if (moveWrapper.navConnected[PSNaviControllerID-1]) { if(moveWrapper.WasPressed(PSNaviControllerID-1, "NavL1")) { shouldJump = true; } } } } if (shouldJump) { jump = true; } }
// Update is called once per frame void Update() { if (GameObject.Find ("Schiff").GetComponent<MoveShip> () != null) { _isGrabbing = true; } else { _isGrabbing = false; } isRotation = IsRotation.Not; if (_handsList.Count > 0) { foreach(GameObject hand in _handsList) { if(hand.name == "unterarm_r") { hydra = SixenseInput.Controllers[1]; } else if(hand.name == "unterarm_l") { hydra = SixenseInput.Controllers[0]; } if (hydra.GetButton (SixenseButtons.TRIGGER)) { //print ("Button from: "+hand.name); if(hand.name == "unterarm_r") { MoveWheel(hydra, hand.name == "unterarm_r", hand, isRightHandRight); } else if(hand.name == "unterarm_l") { MoveWheel(hydra, hand.name == "unterarm_r", hand, isLeftHandRight); } if(!_isGrabbing) { _isGrabbing = true; } } if(hand.name == "unterarm_r") { previousHandPositionRight = hydra.Position; } else if(hand.name == "unterarm_l") { previousHandPositionLeft = hydra.Position; } } } }