Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get correct device orientation from Cardboard SDK #6

Closed
cai-mobfish opened this issue Apr 9, 2020 · 6 comments · Fixed by #35
Closed

Get correct device orientation from Cardboard SDK #6

cai-mobfish opened this issue Apr 9, 2020 · 6 comments · Fixed by #35
Assignees

Comments

@cai-mobfish
Copy link
Contributor

cai-mobfish commented Apr 9, 2020

Technical Detail

Currently, Input.gyro is used to retrieve and calculate device orientation, because there are problems with cardboard way to get the orientation. The quaternion needs converted, but the bigger issue is, the "rotation speed" is almost 2 times faster, rotate device 90 degrees makes in-game camera 180 degrees rotation. Somethings are definately wrong with the usage.

Related file is CardboardHeadTracker.cs

@cai-mobfish cai-mobfish added the help wanted Extra attention is needed label Apr 9, 2020
@rohantipare rohantipare self-assigned this Apr 18, 2020
@rohantipare
Copy link
Collaborator

rohantipare commented Apr 22, 2020

I think the float array for orientation from native to Unity is not transferred the right way. I found this by:
1: Inserting the a log in the function call 'Cardboard_getPose' to print orientation values in the sdk
2: Building the sdk with log, and importing it in unity
3: Observing the orientation values at the unity side, on the device screen.

The orientation values from the native side (printed on log in xcode) does not match with values on unity side.
It has something to do with managed(Unity/c#) and unmanaged memory(c++) conversion. I have tried using GCHandle, Marshall. Not been able to solved so far.

@rohantipare
Copy link
Collaborator

@cai-mobfish
The issue is fixed. Changes are pushed to branch 'deviceOrientation'.

@cai-mobfish
Copy link
Contributor Author

cai-mobfish commented May 6, 2020

CACurrentMediaTime is iOS native method. Some other equivalent method in c# or unity is needed here.

On Android, the equivalent is written in util, with some extra calculation.

https://github.com/googlevr/cardboard/blob/master/hellocardboard-android/src/main/jni/util.cc

long GetMonotonicTimeNano() {
  struct timespec res;
  clock_gettime(CLOCK_MONOTONIC, &res);
  return (res.tv_sec * kNanosInSeconds) + res.tv_nsec;
}

@cai-mobfish
Copy link
Contributor Author

iOS code:

  double targetTime = CACurrentMediaTime() * 1e9;
  targetTime += kPredictionTimeWithoutVsyncNanos;

Android code:

  long monotonic_time_nano = GetMonotonicTimeNano();
  monotonic_time_nano += kPredictionTimeWithoutVsyncNanos;

The goal is to have a monotonic time in nanoseconds.

@cai-mobfish
Copy link
Contributor Author

Do a refactor, push the branch.

@cai-mobfish cai-mobfish removed the help wanted Extra attention is needed label May 7, 2020
@cai-mobfish cai-mobfish linked a pull request May 7, 2020 that will close this issue
@cai-mobfish
Copy link
Contributor Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants