GVR-Android-SDK:如何凝视VideoUiView视图

时间:2019-05-29 03:42:36

标签: android google-vr google-vr-sdk gvr-android-sdk

您好,当任何自定义Ui出现在眼睛或中心点时,您都​​希望凝视。像“播放”按钮或“纸板”按钮一样,什么也没发生。

https://github.com/googlevr/gvr-android-sdk/blob/master/samples/sdk-video360/src/main/java/com/google/vr/sdk/samples/video360/VideoUiView.java

@override
public void onDrawEye(Eye eye) {

  // Apply the eye transformation to the camera.
  Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0);

  Matrix.multiplyMM(viewProjectionMatrix, 0, eye.getPerspective(Z_NEAR, Z_FAR), 0, eye.getEyeView(), 0);
  scene.glDrawFrame(viewProjectionMatrix, eye.getType());
  if(isLookingAtTarget()){
    Log.e(TAG,"Bulls eye : ###################");
  }else{

  }
}
/**
* Check if user is looking at the target object by calculating where the object is in eye-space.
*
* @return true if the user is looking at the target object.
*/
private boolean isLookingAtTarget() {
// Convert object space to camera space. Use the headView from onNewFrame.
Matrix.multiplyMM(viewProjectionMatrix, 0, headView, 0, modelTarget, 0);
Matrix.multiplyMV(tempPosition, 0, viewProjectionMatrix, 0, POS_MATRIX_MULTIPLY_VEC, 0);

  float angle = Util.angleBetweenVectors(tempPosition, FORWARD_VEC);
  Log.e(TAG,"Angle : " +angle);
  return angle < ANGLE_LIMIT;
}

0 个答案:

没有答案