How to navigate in Google VR view?

拈花ヽ惹草 提交于 2019-12-01 08:52:41
  1. You need to declare Sensors

    private SensorManager mSensorManager;
    private OrientationSensor mOrientationSensor;
    mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    mOrientationSensor = new OrientationSensor(this, mSensorManager, OrientationSensor.MODE_LOOK_THROUGH);
    
  2. Make your activity or fragment implements SensorEventListener

  3. Create vector to retreive rotation values

     private float[] mHeadRotation = new float[2];
    
  4. In onSensorChanged

    @Override
    public void onSensorChanged(SensorEvent sensorEvent) {
        mUiPanoWidgetView.getHeadRotation(mHeadRotation);
        updateReticule();
    }
    
  5. Do what you want depending on where you are on picture. Example:

    private void updateReticule() {
        if(mHeadRotation[1] > -20 && mHeadRotation[1] < 20 && mHeadRotation[0] > -15 && mHeadRotation[0] < 15){
            showButton();
        } else {
            showReticule();
        }
    }
    
  6. showButton() can show or hide an arrow (ImageButton) in the center of the screen. Then you set an OnClickListener on the arrow. If users click, then you can go to next picture.

Hope it will help you :)

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