Reprint please indicate the source: blog.csdn.net/linglongxin… This post is from DylanAndroid’s blog.


[Android development VR combat] A. The user is presented with a 360° panorama

Virtual Reality. Virtual reality technology is a computer simulation system that can create and experience the virtual world. It uses the computer to generate a simulation environment, which is a multi-source information fusion interactive THREE-DIMENSIONAL dynamic view and system simulation of entity behavior. Users are immersed in the environment. So, how to develop VR function APP in Android? We use the open source SDK provided by Google to achieve a 360° panoramic image function


Build. Gradle with Google VR SDK dependencies

The compile 'com. Google. Vr: SDK - panowidget: 1.10.0'Copy the code

Note the minimum SDK supported

  minSdkVersion 19
  targetSdkVersion 25Copy the code

3. Interface layout file

<?xml version="1.0" encoding="utf-8"? >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="cn.bluemobi.dylan.vrdevelop.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="AndroidVR development 360-degree panoramic picture" />

    <com.google.vr.sdk.widgets.pano.VrPanoramaView
        android:id="@+id/vr_pan_view"
        android:layout_width="match_parent"
        android:layout_marginTop="20dp"
        android:layout_height="250dp"></com.google.vr.sdk.widgets.pano.VrPanoramaView>
</LinearLayout>Copy the code

Load 360° panoramic image


    /** * load 360-degree panoramic image */
    private void load360Image(a) {
        vr_pan_view = (VrPanoramaView) findViewById(R.id.vr_pan_view);
        /** Get the pictures under assets **/
        InputStream open = null;
        try {
            open = getAssets().open("andes.jpg");
        } catch (IOException e) {
            e.printStackTrace();
        }
        Bitmap bitmap = BitmapFactory.decodeStream(open);
        /** Set the Settings for loading VR images **/
        VrPanoramaView.Options options = new VrPanoramaView.Options();
        options.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER;
        /** Set load VR picture listener **/
        vr_pan_view.setEventListener(new VrPanoramaEventListener() {
            /** * Display mode change callback * 1. Default * 2. Full screen mode * 3@param* / newDisplayMode mode
            @Override
            public void onDisplayModeChanged(int newDisplayMode) {
                super.onDisplayModeChanged(newDisplayMode);
                Log.d(TAG, "onDisplayModeChanged()->newDisplayMode=" + newDisplayMode);
            }

            /** * Failed to load VR image callback *@param errorMessage
             */
            @Override
            public void onLoadError(String errorMessage) {
                super.onLoadError(errorMessage);
                Log.d(TAG, "onLoadError()->errorMessage=" + errorMessage);
            }

            /** * Successfully loaded VR image callback */
            @Override
            public void onLoadSuccess(a) {
                super.onLoadSuccess();
                Log.d(TAG, "OnLoadSuccess -> Image loaded successfully");
            }

            /** * Click VR picture callback */
            @Override
            public void onClick(a) {
                super.onClick();
                Log.d(TAG, "onClick()"); }});/** Load VR image **/
        vr_pan_view.loadImageFromBitmap(bitmap, options);
    }Copy the code

Five.GitHub