- Sort Posts
- 4 replies
- Last post
Using Vuforia with Accelerometer?
Using Vuforia with Accelerometer?
Using Vuforia with Accelerometer?
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?
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)
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 ?