Log in or register to post comments

Gyroscope integration

August 4, 2015 - 9:01am #1

Here is what I would like to do.

I am standing in a room. When I track a picture/target on the wall, old pictures (like from 50 years ago) of this room will appear on different positions in that room. 

So when I track that target , all pictures should be freezed so that I can look around and see also the pictures behind me, it is like using the gyroscope.

Is it possible to intregrate a gyroscope with vuforia? So first track a target and after that view stuff and look around in gyro style?

 

Thanks.

Gyroscope integration

May 9, 2018 - 10:13pm #10

I found a temporary solution. The objects will not be frozen in the perspective view, but will not be moving a lot, like what was happening earlier.

 

Try going to Vuforia Configurations>Device Tracker>Select "Track device pose">Change tracking mode to "Rotational" and set enable prediction to "true".



Idk how much this helps, but made my objects still.

Gyroscope integration

May 8, 2018 - 11:15pm #9

@lhno Hey, thanks for the code! It helped a lot. Yes, the objects are not exactly frozen in their places. If you find a solution, do post it, and I'll do the same if I find something. I'm searching the internet right now.

 

All the best, keep us updated brother :D

Gyroscope integration

October 25, 2017 - 8:26am #8

Hi, I am wondering, is it working now?

Gyroscope integration

January 4, 2017 - 10:11pm #7

Hi, I want to get the similar effect in my project, Have you maked it work? Please let me know, Thanks !

Gyroscope integration

January 4, 2017 - 10:10pm #6

Hi, I want to get the similar effect in my project, Have you maked it work? Please let me know, Thanks !

Gyroscope integration

August 7, 2015 - 12:02am #5

The movement is more like drifting or lerping to a certain position.

I tried lerp and slerp. But both are giving the same result.

Gyroscope integration

August 6, 2015 - 10:12am #4

What sort of movement are you seeing? - are the objects drifting or shaking?

Have you experimented w/ LERPing or SLERPing the rotation inputs?

http://forum.unity3d.com/threads/what-is-the-difference-of-quaternion-slerp-and-lerp.101179/

 

Gyroscope integration

August 6, 2015 - 8:38am #3

Thanks for the reply.

I am using the following script. Which works fine. Now I can track a target, after that, some objects are visible in scene (not as a child of the image Target).

When I look around I can see all objects. But they move a little bit weird. The Objects aren't freezed, they move around just a little bit. I can't find a solution for that, I am close to what I need. Maybe someone has an idea how to fix that?

 

I put this script on the AR camera. When the target is found I call the method "AttachGyro()" and show the Objects in the room.

 

// ***********************************************************
// Written by Heyworks Unity Studio http://unity.heyworks.com/
// ***********************************************************
using UnityEngine;

/// <summary>
/// Gyroscope controller that works with any device orientation.
/// </summary>
public class GyroController : MonoBehaviour 
{
	#region [Private fields]
	
	private bool gyroEnabled = true;
	private const float lowPassFilterFactor = 0.2f;
	
	private readonly Quaternion baseIdentity =  Quaternion.Euler(90, 0, 0);
	private readonly Quaternion landscapeRight =  Quaternion.Euler(0, 0, 90);
	private readonly Quaternion landscapeLeft =  Quaternion.Euler(0, 0, -90);
	private readonly Quaternion upsideDown =  Quaternion.Euler(0, 0, 180);
	
	private Quaternion cameraBase =  Quaternion.identity;
	private Quaternion calibration =  Quaternion.identity;
	private Quaternion baseOrientation =  Quaternion.Euler(90, 0, 0);
	private Quaternion baseOrientationRotationFix =  Quaternion.identity;
	
	
	
	private Quaternion referanceRotation = Quaternion.identity;
	private bool debug = true;
	
	#endregion
	
	#region [Unity events]
	
	protected void Start () 
	{
		AttachGyro();
	}
	
	protected void Update() 
	{
		if (!gyroEnabled)
			return;
		transform.rotation = Quaternion.Slerp(transform.rotation,
		                                      cameraBase * ( ConvertRotation(referanceRotation * Input.gyro.attitude) * GetRotFix()), lowPassFilterFactor);
	}
	
	protected void OnGUI()
	{
		if (!debug)
			return;
		
		GUILayout.Label("Orientation: " + Screen.orientation);
		GUILayout.Label("Calibration: " + calibration);
		GUILayout.Label("Camera base: " + cameraBase);
		GUILayout.Label("input.gyro.attitude: " + Input.gyro.attitude);
		GUILayout.Label("transform.rotation: " + transform.rotation);
		
		if (GUILayout.Button("On/off gyro: " + Input.gyro.enabled, GUILayout.Height(100)))
		{
			Input.gyro.enabled = !Input.gyro.enabled;
		}
		
		if (GUILayout.Button("On/off gyro controller: " + gyroEnabled, GUILayout.Height(100)))
		{
			if (gyroEnabled)
			{
				DetachGyro();
			}
			else
			{
				AttachGyro();
			}
		}
		
		if (GUILayout.Button("Update gyro calibration (Horizontal only)", GUILayout.Height(80)))
		{
			UpdateCalibration(true);
		}
		
		
		if (GUILayout.Button("Reset base orientation", GUILayout.Height(80)))
		{
			ResetBaseOrientation();
		}
		
		if (GUILayout.Button("Reset camera rotation", GUILayout.Height(80)))
		{
			transform.rotation = Quaternion.identity;
		}
		
		if (GUILayout.Button("Update camera base rotation (Horizontal only)", GUILayout.Height(80)))
		{
			UpdateCameraBaseRotation(true);
		}
		
		if (GUILayout.Button("Close", GUILayout.Height(80)))
		{
			debug = false;
		}
	}
	
	#endregion
	
	#region [Public methods]
	
	/// <summary>
	/// Attaches gyro controller to the transform.
	/// </summary>
	public void AttachGyro()
	{
		Debug.Log ("test");
		gyroEnabled = true;
		ResetBaseOrientation();
		UpdateCalibration(true);
		UpdateCameraBaseRotation(true);
		RecalculateReferenceRotation();
	}
	
	/// <summary>
	/// Detaches gyro controller from the transform
	/// </summary>
	private void DetachGyro()
	{
		gyroEnabled = false;
	}
	
	#endregion
	
	#region [Private methods]
	
	/// <summary>
	/// Update the gyro calibration.
	/// </summary>
	private void UpdateCalibration(bool onlyHorizontal)
	{
		if (onlyHorizontal)
		{
			var fw = (Input.gyro.attitude) * (-Vector3.forward);
			fw.z = 0;
			if (fw == Vector3.zero)
			{
				calibration = Quaternion.identity;
			}
			else
			{
				calibration = (Quaternion.FromToRotation(baseOrientationRotationFix * Vector3.up, fw));
			}
		}
		else
		{
			calibration = Input.gyro.attitude;
		}
	}
	
	/// <summary>
	/// Update the camera base rotation.
	/// </summary>
	/// <param name='onlyHorizontal'>
	/// Only y rotation.
	/// </param>
	private void UpdateCameraBaseRotation(bool onlyHorizontal)
	{
		if (onlyHorizontal)
		{
			var fw = transform.forward;
			fw.y = 0;
			if (fw == Vector3.zero)
			{
				cameraBase = Quaternion.identity;
			}
			else
			{
				cameraBase = Quaternion.FromToRotation(Vector3.forward, fw);
			}
		}
		else
		{
			cameraBase = transform.rotation;
		}
	}
	
	/// <summary>
	/// Converts the rotation from right handed to left handed.
	/// </summary>
	/// <returns>
	/// The result rotation.
	/// </returns>
	/// <param name='q'>
	/// The rotation to convert.
	/// </param>
	private static Quaternion ConvertRotation(Quaternion q)
	{
		
		return new Quaternion(q.x, q.y, -q.z, -q.w);	
	}
	
	/// <summary>
	/// Gets the rot fix for different orientations.
	/// </summary>
	/// <returns>
	/// The rot fix.
	/// </returns>
	private Quaternion GetRotFix()
	{
		#if UNITY_3_5
		if (Screen.orientation == ScreenOrientation.Portrait)
			return Quaternion.identity;
		
		if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.Landscape)
			return landscapeLeft;
		
		if (Screen.orientation == ScreenOrientation.LandscapeRight)
			return landscapeRight;
		
		if (Screen.orientation == ScreenOrientation.PortraitUpsideDown)
			return upsideDown;
		return Quaternion.identity;
		#else
		return Quaternion.identity;
		#endif
	}
	
	/// <summary>
	/// Recalculates reference system.
	/// </summary>
	private void ResetBaseOrientation()
	{
		baseOrientationRotationFix = GetRotFix();
		baseOrientation = baseOrientationRotationFix * baseIdentity;
	}
	
	/// <summary>
	/// Recalculates reference rotation.
	/// </summary>
	private void RecalculateReferenceRotation()
	{
		referanceRotation = Quaternion.Inverse(baseOrientation)*Quaternion.Inverse(calibration);
	}
	
	#endregion
}

 

Gyroscope integration

August 5, 2015 - 4:24pm #2

Vuforia 5.0.5 doesn't utilize the gyroscope. It does have Extended Tracking which uses image-based background features to allow for tracking when a target moves out of view. You can read more about it here:

https://developer.vuforia.com/library/articles/Training/Extended-Tracking

 

Log in or register to post comments