void Update() { //If this is running in the unity editor or flagged as a development build set the gyroscope rotation values on the text objects #if UNITY_EDITOR || DEVELOPMENT_BUILD if (SystemInfo.supportsGyroscope) { //Quaternion referenceRotation = Quaternion.identity; Quaternion deviceRotation = DeviceRotation.Get(); //Vector3 modifier = new Vector3(0, 0, 1); //Quaternion modifiedRotation = Quaternion.Inverse(Quaternion.FromToRotation(referenceRotation * modifier, deviceRotation * modifier)); //modifiedRotation *= deviceRotation; //float xVal = modifiedRotation.eulerAngles.x; //float yVal = modifiedRotation.eulerAngles.y; //float zVal = modifiedRotation.eulerAngles.z; float xVal = deviceRotation.eulerAngles.x; float yVal = deviceRotation.eulerAngles.y; float zVal = deviceRotation.eulerAngles.z; gyroX.text = ((xVal > 180f) ? ((treeInputMin / 180f) * (360f - xVal)) : ((treeInputMax / 180f) * xVal)).ToString(); gyroY.text = ((yVal > 180f) ? ((treeInputMin / 180f) * (360f - yVal)) : ((treeInputMax / 180f) * yVal)).ToString(); gyroZ.text = ((zVal > 180f) ? ((treeInputMin / 180f) * (360f - zVal)) : ((treeInputMax / 180f) * zVal)).ToString(); //gyroX.text = modifiedRotation.eulerAngles.x.ToString(); //gyroY.text = modifiedRotation.eulerAngles.y.ToString(); //gyroZ.text = modifiedRotation.eulerAngles.z.ToString(); } #endif }
protected void OnRotationChanged(object sender, DeviceRotation args) { var btnFlash = (Button)FindByName("btnDone"); switch (args) { case DeviceRotation.Unknown: case DeviceRotation.Portrait: btnFlash.Rotation = 0; imgThumbnail.Rotation = 0; break; case DeviceRotation.ReversePortrait: btnFlash.Rotation = 180; imgThumbnail.Rotation = 180; break; case DeviceRotation.Landscape: btnFlash.Rotation = 270; imgThumbnail.Rotation = 270; break; case DeviceRotation.ReverseLandscape: btnFlash.Rotation = 90; imgThumbnail.Rotation = 90; break; } }
protected void OnRotationChanged(int rotation) { var currentRotation = DeviceRotation.Unknown; switch (rotation / 45) { case 0: case 7: currentRotation = DeviceRotation.Portrait; break; case 1: case 2: currentRotation = DeviceRotation.Landscape; break; case 3: case 4: currentRotation = DeviceRotation.ReversePortrait; break; case 5: case 6: currentRotation = DeviceRotation.ReverseLandscape; break; } if (DeviceRotation != currentRotation) { DeviceRotation = currentRotation; RotationChanged?.Invoke(this, EventArgs.Empty); } }
//required coz we don't control the spawning of networked objects in the scene. public void Start() { PlayerManager.Instance.gunner = this; transform.SetParent(PlayerManager.Instance.pilot.transform); gunBase = transform.Find("Base"); //Base/ - for new prefab barrel = gunBase.Find("Barrel"); muzzle = barrel.Find("Muzzle"); CharStats = new CharacterStats(); previousGyroEuler = DeviceRotation.Get().eulerAngles; EndScreen = GameObject.Find("EndScreen"); GunnerCanvas = GameObject.Find("GunnerCanvas"); if (GunnerCanvas) { DynamicJoystick = GunnerCanvas.transform.Find("Dynamic Joystick").GetComponent <DynamicJoystick>(); shootButton = GunnerCanvas.transform.Find("Button").GetComponent <Button>(); healthbar = GunnerCanvas.transform.Find("DoubleBar").Find("lifeBar").GetComponent <Image>(); shieldbar = GunnerCanvas.transform.Find("DoubleBar").Find("shieldBar").GetComponent <Image>(); shootButton.onClick.AddListener(onShootButton); } screenCenter = new Vector3(Screen.width / 2, Screen.height / 2, 0); mainCamera = Camera.main; }
protected void OnOrientationChanged(object sender, NSNotificationEventArgs args) { var rotaion = DeviceRotation; switch (UIDevice.CurrentDevice.Orientation) { case UIDeviceOrientation.Portrait: DeviceRotation = DeviceRotation.Portrait; break; case UIDeviceOrientation.LandscapeRight: DeviceRotation = DeviceRotation.Landscape; break; case UIDeviceOrientation.PortraitUpsideDown: DeviceRotation = DeviceRotation.ReversePortrait; break; case UIDeviceOrientation.LandscapeLeft: DeviceRotation = DeviceRotation.ReverseLandscape; break; } if (rotaion != DeviceRotation) { OrientationChanged?.Invoke(this, DeviceRotation); } }
void GetOffset() { if (DeviceRotation.Get().ToString() != "(0.0, 0.0, 0.0, 0.0)" && !offset) { offsetRotation = Quaternion.Inverse(DeviceRotation.Get()); offset = true; } }
// Update is called once per frame void Update() { angleAroundX = DeviceRotation.StruisSpeedAngle(); Debug.Log("Angle around X" + angleAroundX); //movementController.WorldSpeed = Sensibility * angleAroundX; }
public ImageSaver(Image image, File file, MediaOptions mediaOptions, DeviceRotation rotation, EventHandler <MediaFile> callBack) { _image = image ?? throw new ArgumentNullException("image"); _file = file ?? throw new ArgumentNullException("file"); _mediaOptions = mediaOptions ?? throw new ArgumentNullException("mediaOptions"); _currentRotation = rotation; CallBack = callBack; }
protected UIImage RotateImage(UIImage image, DeviceRotation currentOrientation) { CGContext bitmap; switch (currentOrientation) { case DeviceRotation.Unknown: case DeviceRotation.Portrait: UIGraphics.BeginImageContext(new CGSize(image.CGImage.Height, image.CGImage.Width)); bitmap = UIGraphics.GetCurrentContext(); bitmap.ScaleCTM(-1, 1); bitmap.RotateCTM((float)Math.PI * 0.5f); bitmap.DrawImage(new CGRect(0, 0, image.CGImage.Width, image.CGImage.Height), image.CGImage); break; case DeviceRotation.ReversePortrait: UIGraphics.BeginImageContext(new CGSize(image.CGImage.Height, image.CGImage.Width)); bitmap = UIGraphics.GetCurrentContext(); bitmap.TranslateCTM(image.CGImage.Height, image.CGImage.Width); bitmap.ScaleCTM(1, -1); bitmap.RotateCTM((float)Math.PI * 0.5f); bitmap.DrawImage(new CGRect(0, 0, image.CGImage.Width, image.CGImage.Height), image.CGImage); break; case DeviceRotation.Landscape: UIGraphics.BeginImageContext(new CGSize(image.CGImage.Width, image.CGImage.Height)); bitmap = UIGraphics.GetCurrentContext(); bitmap.TranslateCTM(image.CGImage.Width, 0); bitmap.ScaleCTM(-1, 1); bitmap.DrawImage(new CGRect(0, 0, image.CGImage.Width, image.CGImage.Height), image.CGImage); break; case DeviceRotation.ReverseLandscape: UIGraphics.BeginImageContext(new CGSize(image.CGImage.Width, image.CGImage.Height)); bitmap = UIGraphics.GetCurrentContext(); bitmap.TranslateCTM(0, image.CGImage.Height); bitmap.ScaleCTM(1, -1); bitmap.DrawImage(new CGRect(0, 0, image.CGImage.Width, image.CGImage.Height), image.CGImage); break; } try { return(UIGraphics.GetImageFromCurrentImageContext()); } finally { UIGraphics.EndImageContext(); } }
void Update() { Quaternion deviceRotation = DeviceRotation.Get(); transform.rotation = deviceRotation; rb.AddForce(transform.forward * speed, ForceMode.Acceleration); rb.AddForce(transform.up * upSpeed, ForceMode.Acceleration); rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed); }
public static float StruisSpeedAngle() { Quaternion deviceRotation = DeviceRotation.Get(0, 0, 1); Quaternion eliminationOfXY = Quaternion.Inverse( Quaternion.FromToRotation(referenceRotation * Vector3.forward, deviceRotation * Vector3.forward) ); Quaternion rotationZ = eliminationOfXY * deviceRotation; return(rotationZ.eulerAngles.z); }
public static float WorldRotationAngleY() { Quaternion deviceRotation = DeviceRotation.Get(0, 1, 0); Quaternion eliminationOfYZ = Quaternion.Inverse( Quaternion.FromToRotation(referenceRotation * Vector3.forward, deviceRotation * Vector3.forward) ); Quaternion rotationZ = eliminationOfYZ * deviceRotation; return(rotationZ.eulerAngles.y); }
//checks magnitude of the acceleromter value - detecting any shake public void movementCheck(Vector3 accelerometerCurrentVal) { currentDeviceRotation = DeviceRotation.GetRotation().eulerAngles; if (keepStillTriggered) { if (accelerometerCurrentVal.magnitude > 1f || hasRotationChanged(currentDeviceRotation) || thirdPersonUserControl.GetMoveMagnitude() > 0) { witchPromptText.text = "YOU MOVED - GAME OVER"; isStill = false; } } }
void Update() { Console.Instance.ClearLog(); GetOffset(); Quaternion temp = DeviceRotation.Get(); temp = offsetRotation * temp; SetRotation(temp); Console.Instance.Log("Device Rotation: " + DeviceRotation.Get().ToString()); Console.Instance.Log("Offset Rotation: " + offsetRotation.ToString()); Console.Instance.Log("InGame Rotation: " + temp.ToString()); }
void Update() { var temp1 = DeviceRotation.Get(); var temp = temp1.eulerAngles; var pos = Input.acceleration; if (client.isConnected) { StringMessage msg = new StringMessage(); msg.value = temp.x + "|" + temp.y + "|" + temp.z + "|" + pos.x + "|" + pos.y + "|" + pos.z;; client.Send(888, msg); } }
public float GetRotation() { Quaternion referenceRotation = Quaternion.identity; Quaternion deviceRotation = DeviceRotation.Get(); Quaternion eliminationOfXY = Quaternion.Inverse( Quaternion.FromToRotation(referenceRotation * Vector3.forward, deviceRotation * Vector3.forward) ); Quaternion rotationZ = eliminationOfXY * deviceRotation; float roll = rotationZ.eulerAngles.z; return(roll); }
void Update() { var temp1 = DeviceRotation.Get(); var temp = temp1.eulerAngles; if (client.isConnected) { connection.interactable = false; status.text = "Connected"; StringMessage msg = new StringMessage(); msg.value = temp.x + "|" + temp.y + "|" + temp.z; client.Send(888, msg); } }
private void Update() { if (inputControllers.CameraRotateMode != CameraRotateMode.Gyroscope) { return; } if (!SystemInfo.supportsGyroscope) { return; } cameraTransform.localRotation = DeviceRotation.Get(); }
public void ChangeControls(MobileControls mobileControls) { CurrentMobileControls = mobileControls; if (mobileControls == MobileControls.Joystick) { UIServiceLocator.Instance.PlayerJoystick.gameObject.SetActive(true); } else if (mobileControls == MobileControls.Gyroscope) { UIServiceLocator.Instance.PlayerJoystick.gameObject.SetActive(false); DeviceRotation.ResetReferenceRotation(); } }
public void BeginBalance(Transform thisEnd, Transform otherEnd) { print("Begin balance"); isBalancing = true; _dial.SetActive(true); _character.transform.position = thisEnd.position; _character.transform.LookAt(otherEnd); _moveTowards = otherEnd.position; _enterZAngle = DeviceRotation.GetRotation().eulerAngles.z; // _negatePhoneRotation = Quaternion.Inverse(DeviceRotation.GetRotation()); GlobalGameManager.Instance.ToggleUI(false); }
private float BalanceAngleDifference() { // What is the z angle of the phone? _currentZAngle = DeviceRotation.GetRotation().eulerAngles.z; // How different is it to the entry z angle? var difference = _enterZAngle - _currentZAngle; // A bit of normalisation if (difference > 180) { difference -= 360f; } // Return the inverse as otherwise the UI rotation is counter intuitive (it's the opposite) return(difference * -1); }
void UpdateGyroInput(InputPkg ip) { Vector3 deviceEulers = DeviceRotation.Get().eulerAngles; Vector3 deltaEulers = previousGyroEuler - deviceEulers; previousGyroEuler = deviceEulers; //if (deltaEulers.x > gyroXsensitivity) ip.gunPitch = deltaEulers.x; /*else * ip.gunPitch = 0;*/ //if (deltaEulers.y > gyroYsensitivity) ip.gunYaw = deltaEulers.y; /*else * ip.gunYaw = 0;*/ }
private void MoveCheck() { float xAngle = 0f; float yAngle = 0f; if (ControlsManager.Instance.CurrentMobileControls == MobileControls.Gyroscope) { Vector3 referenceRotation = DeviceRotation.ReferenceOrientation * Vector3.forward; Vector3 currentRotation = DeviceRotation.GetRotation() * Vector3.forward; xAngle = -Vector3.SignedAngle(referenceRotation, currentRotation, Vector3.forward); yAngle = -Vector3.SignedAngle(referenceRotation, currentRotation, Vector3.right); if (Mathf.Abs(xAngle) > xMinMoveAngle) { xAngle /= xMaxMoveAngle; } else { xAngle = 0f; } if (Mathf.Abs(yAngle) > yMinMoveAngle) { yAngle /= yMaxMoveAngle; } else { yAngle = 0f; } } Vector2 joystickDir = joystick.Direction; float rawX = Input.GetAxisRaw("Horizontal") + joystickDir.x + xAngle; float rawY = Input.GetAxisRaw("Vertical") + joystickDir.y + yAngle; Vector2 rawMove = new Vector2(rawX, rawY); Vector2 normalizedMove = rawMove.sqrMagnitude > 1f ? rawMove.normalized : rawMove; float smoothing = moveSmoothing * Time.deltaTime; Move = Vector2.Lerp(Move, normalizedMove, smoothing); }
//timer for 10 seconds public IEnumerator KeepStillTime() { //guard boolean to make sure the movementCheck is only relevant for these 10 seconds keepStillTriggered = true; initialDeviceRotation = DeviceRotation.GetRotation().eulerAngles; // Notify the AI that they need to run away and whatnot if (witchArriveEvent != null) { witchArriveEvent(); } for (int i = (int)keepStillDuration; i >= 1; i--) { //if we moved, stop the timer if (!isStill) { yield return(new WaitForSecondsRealtime(2.5f)); loadLevelScript.LoadSavedLevel(true); break; } yield return(new WaitForSecondsRealtime(1)); } keepStillTriggered = false; //if we stayed still for the full time, prompt user and then clear text if (isStill) { witchPromptText.text = "WELL DONE!"; yield return(new WaitForSecondsRealtime(1)); } witchPromptText.text = " "; if (witchLeaveEvent != null) { witchLeaveEvent(); } reset(); }
Vector3 CalculateGyroDelta() { Vector3 deviceEulers = DeviceRotation.Get().eulerAngles; Vector3 deltaEulers = previousGyroEuler - deviceEulers; Debug.Log("Delta : " + deltaEulers); previousGyroEuler = deviceEulers; if (Mathf.Abs(deltaEulers.x) < gyroXsensitivity) { deltaEulers.x = 0; } if (Mathf.Abs(deltaEulers.y) < gyroYsensitivity) { deltaEulers.y = 0; } return(new Vector3(Mathf.Clamp(deltaEulers.x, -10f, 10f), Mathf.Clamp(deltaEulers.y, -10f, 10f))); }
// Update is called once per frame void Update() { // ------------- Camera rotation based on gyroscope input ---------------- // Grab the reference matrix for quaternions, as a base Quaternion referenceRotation = Quaternion.identity; // Get the current rotation of the phone Quaternion deviceRotation = DeviceRotation.Get(); if (Input.gyro.enabled) { // Rotate the player's Y axis to match the camera's Quaternion newRot = transform.rotation; Vector3 euler = newRot.eulerAngles; // Android SDK level is represented as an int // Android 6.0 Marshmallow is represented as 23 // Since Unity can't use gyroscope.attitude in Android 6.0, check if we need // to use a clunky workaround on this device if (AndroidVer >= 23) { // We need to workaround this yRotation += -Input.gyro.rotationRateUnbiased.y * 2.5f; xRotation += -Input.gyro.rotationRateUnbiased.x * 2.5f; cam.transform.eulerAngles = new Vector3(xRotation, yRotation, 0f); //euler.y = cam.transform.eulerAngles.y; } else { // Use the nice solution // Rotate Camera based on gyroscope (more free) cam.transform.rotation = deviceRotation; //euler.y = deviceRotation.eulerAngles.y; } //newRot.eulerAngles = euler; //transform.rotation = newRot; // This wouldn't be so wasteful if Unity let you actually edit returned quaternions directly } }
float GetAngleByDeviceAxis(Vector3 axis) { Quaternion deviceRotation = DeviceRotation.Get(); Quaternion eliminationOfOthers = Quaternion.Inverse( Quaternion.FromToRotation(axis, deviceRotation * axis) ); Vector3 filteredEuler = (eliminationOfOthers * deviceRotation).eulerAngles; float result = filteredEuler.z; if (axis == Vector3.up) { result = filteredEuler.y; } if (axis == Vector3.right) { // incorporate different euler representations. result = (filteredEuler.y > 90 && filteredEuler.y < 270) ? 180 - filteredEuler.x : filteredEuler.x; } return(result); }
void Update() { Debug.Log(songRequested.name + " + " + PlayerPrefs.GetString(songRequested.name)); songName.text = Truncate(songName.text, 30); songNameLC.text = Truncate(songNameLC.text, 34); //Gyro if (gameObject.activeSelf) { if (Input.gyro.enabled) { Quaternion deviceRotation; deviceRotation = DeviceRotation.Get(); if (deviceRotation.eulerAngles.z > 45 && deviceRotation.eulerAngles.z < 225) { landscapePanel.SetActive(true); } else { landscapePanel.SetActive(false); } } } if (songRequested.isFavorite) { favoriteButton.GetComponent <Image>().sprite = favoriteOn; favoriteButtonLandscape.GetComponent <Image>().sprite = favoriteOn; PlayerPrefs.SetString(songRequested.name, songRequested.isFavorite.ToString()); } if (!songRequested.isFavorite) { favoriteButton.GetComponent <Image>().sprite = favoriteOff; favoriteButtonLandscape.GetComponent <Image>().sprite = favoriteOff; PlayerPrefs.SetString(songRequested.name, songRequested.isFavorite.ToString()); } }
/// <summary> /// This rotates the camera to match the orientation of the phone /// </summary> public void TiltPhone() { // Helps to stop us getting caught in a bad change of states. Resets in ResetRotation(). if (!tilting) { // Save our current rotation before doing anything else. This is where we'll return later. _resetRotation = transform.localRotation; // This is the opposite of the phones rotation when entering the tilt mode. // We are aiming to negate by this value later. _negatePhoneRotation = Quaternion.Inverse(DeviceRotation.GetRotation()); tilting = true; //debugText.enabled = true; } // None! This is 1 rotation offest by another. No idea how it works. // Why do you offset the right by the left? Who knows. It's magic. _desiredRotation = _negatePhoneRotation * DeviceRotation.GetRotation(); // Set rotation at the end, assumes _desiredRotation has been set in 1 of the above if statements. transform.localRotation = _desiredRotation; // Cache it back into the conveniently shorter variable name. _currentRotation = transform.localRotation; //debugText.text = _desiredRotation.ToString(); }
// Update is called once per frame void Update() { Quaternion deviceRotation = DeviceRotation.Get(); transform.rotation = deviceRotation; if (Mathf.Abs(xRotation - transform.eulerAngles.x) > 1) { xRotation = Mathf.Round(transform.eulerAngles.x); } if (Mathf.Abs(yRotation - transform.eulerAngles.y) > 1) { yRotation = Mathf.Round(transform.eulerAngles.y); } if (Mathf.Abs(zRotation - transform.eulerAngles.z) > 1) { zRotation = Mathf.Round(transform.eulerAngles.z); } X.GetComponent <TextMeshProUGUI>().text = "X = " + xRotation; Y.GetComponent <TextMeshProUGUI>().text = "Y = " + yRotation; Z.GetComponent <TextMeshProUGUI>().text = "Z = " + zRotation; errorsText.GetComponent <TextMeshProUGUI>().text = "Errores = " + errorsCont; if (!isStabilized) { startCalibration(); if (xRotation > 88 && xRotation < 91) { timePassed += Time.deltaTime; progressValue = timePassed / secondsToCalibrate; if (progressValue > 1) { progressValue = 1; } progressCalibration.GetComponent <Image>().fillAmount = progressValue; if (timePassed > secondsToCalibrate) { endCalibration(); } } else { timePassed = 0; progressCalibration.GetComponent <Image>().fillAmount = 0; } } if (IntroductionComplete) { switch (_exercises) { case EnumExercises.ARMEXERCISE: if (repetitionCounter < 3) { if (xRotation <= 45) { if (!repetitionCompleted) { _audioSource.clip = correct; _audioSource.Play(); repetitionCompleted = true; repetitionCounter++; } } if (xRotation >= 90) { if (repetitionCompleted) { _audioSource.clip = correct; _audioSource.Play(); repetitionCompleted = false; } } } else { _audioSource.clip = exerciseComplete; _audioSource.Play(); //feedback } break; case EnumExercises.SHOULDEREXERCISE: if (setCounter < set) { if (repetitionCounter < repetitions) { if (xRotation > 15 && xRotation < 300) { wrongXPosition = true; } else { wrongXPosition = false; } if (yRotation > safeZoneA || yRotation < safeZoneB) { wrongYPosition = true; } else { wrongYPosition = false; } if (zRotation >= 177 && zRotation <= 181) { firstStateCompleted(); } if (zRotation >= 88 && zRotation <= 91) { secondStateCompleted(); } if ((zRotation >= 0 && zRotation <= 2) || (zRotation >= 357 && zRotation <= 360)) { thirdStateCompleted(); } wrongDirectionError(); } else { nextSet(); } } else { endOfActivity(); } break; } } }