Log in or register to post comments

Using Vuforia with Accelerometer?

April 7, 2014 - 8:19am #5

I am trying to get a model ofa  butterfly coming out of a chryslis, to hang off a target and always point down even when the marker(temporary tattoo) is rotated. Does anyone have an idea on how to do this?

 

Thank you

Using Vuforia with Accelerometer?

April 7, 2014 - 8:32am #4

Hi, sounds like you may want to use the Acelerometer of your device (see the Unity Input API for access to accelerometer information):

http://docs.unity3d.com/Documentation/Manual/Input.html

 

then, once you have the gravity vector from the device sensors, you will need to use that information to estimate how the device (and so the ARCamera) is oriented w.r.t. the ground.

At the same time, you will also need to compute how the Target is oriented w.r.t. the camera (you can derive this information from the Target transform component).

If you combine the information above, you should be able to rotate the butterfly in a way that is consistent with the real gravity.

But, as far as the implementation is concerned, this would require a bit of coding (it's probably more of a Unity programming, rather than a Vuforia matter)

Using Vuforia with Accelerometer?

April 7, 2014 - 3:41pm #3

Hi,

I am trying to do this (I am the developer for the OP) and I am struggling to get it working. I have the following code, but I cannot get it to always point downwards. Any help would be appreciated:

public class FaceGround : MonoBehaviour
{

	#region Public Variables

	public float _AccelerometerUpdateInterval = 1.0f / 60.0f;
	public float _LowPassKernelWidthInSeconds = 1.0f;
	public Vector3 _Direction;

	#endregion

	#region Private Variables

	private float mLowPassFilterFactor = 0;
	private Vector3 mLowPassValue = Vector3.zero;

	#endregion

	#region Unity Methods

	void Start ()
	{
		mLowPassFilterFactor = _AccelerometerUpdateInterval / _LowPassKernelWidthInSeconds;
		mLowPassValue = Input.acceleration;
	}

	void Update ()
	{
		Vector3 newDirection = Camera.main.transform.TransformDirection (new Vector3 (LowPassFilterAccelerometer ().y * _Direction.y, (LowPassFilterAccelerometer ().x * _Direction.x) + 0.0f, LowPassFilterAccelerometer ().z * _Direction.z));
		transform.up = newDirection;
	}

	#endregion

	#region Private Methods

	private Vector3 LowPassFilterAccelerometer ()
	{
		mLowPassValue = Vector3.Lerp (mLowPassValue, Input.acceleration, mLowPassFilterFactor);
		return mLowPassValue;
	}

	#endregion

}
 

Using Vuforia with Accelerometer?

April 8, 2014 - 7:49am #2

Does anyone have a soloution for the code below?

Using Vuforia with Accelerometer?

April 8, 2014 - 9:56am #1

Guys, the snippet below is pure Unity, I don't see a single line of code that relates to Vuforia ;-)

Have you considered looking in the Unity website ?

 

Log in or register to post comments