How can I find the rotation of the head in Google Cardboard Unity3D?

心已入冬 提交于 2019-12-24 03:27:26

问题


Hey guys how do I find the rotation of the phone with Google Cardboard SDK in Unity3D, like the way the persons head is facing? I need to find if it is facing more towards the east, the west, or the north. Do I find the rotation of the head, or the parent Main camera?


回答1:


The Cardboard class contains a property called HeadRotation which is a Quaternion.

Quaternion crtRot = youCardboardController.HeadRotation;

To use its rotation like you'd in Unity with directional vectors you may simply multiply it by Vector3.forward.

Vector3 lookDir = crtRot * Vector3.forward;

Visualizing the vector in editor might help narrow down issues

void Update () {
  // ..
  Debug.DrawRay( pos, lookDir * 100, Color.blue );
  // ..
}

From here you only need to know where North is, in meaning of the facing vector. Do a Vector3.Angle() and you have the angle between your avatar's and North's vector. You might want to evaluate both vectors with their y axes set to 0.

You could also use Vector3.Dot() (the dot product) to determine how much both vectors look into the same direction.

I had an issue with HeadPosition, which wasn't updated properly. So if you operate from HeadPosition keep in mind it may stick to 0,0,0 .




回答2:


Take Head.transform.rotation - that's the orientation of the user's head.

I'm not really sure what do you mean by North or West. If the mobile device has a magnetometer, then maybe you could read it's data to determine where North is, but I've never done that




回答3:


It would be the rotation of the Head object, although the Main Camera usually has the same rotation.

But if you want the direction relative to the real world, that information is not available in the SDK. The compass cannot be used because of the magnet, so there is no way to get the real direction.



来源:https://stackoverflow.com/questions/30046425/how-can-i-find-the-rotation-of-the-head-in-google-cardboard-unity3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!