Initial Development of Cardboard VR (II): cardboard Vr
Initial Development of Google Cardboard virtual reality glasses (2)Use of Cardboard SDK for Unity
As the first part of the series, the previous article focuses on the technologies and principles of virtual reality. This article will show you how to use Google's Cardboard SDK for Unity, although there are few materials and documents at present, this package is very convenient to use. As long as you have a little experience with Unity, you can easily use it. I will explain it in the form of Unity beginners.
In order to facilitate reading, I will write the steps as detailed as possible,I will also publish relevant English documents on Google's official website and Chinese references translated by myself in the form of a blog.To facilitate reading and downloading Those who cannot log on to Google.
(1) download Cardboard SDK for Unity from the official website
Google Cardboard Official Website:
Https://www.google.com/get/cardboard/
Go to the developer guide page on the Google Cardboard official website, and click Download and Samples under Unity SDK on the left side:
Https://developers.google.com/cardboard/unity/download
Click Download Cardboard SDK for Unity (direct link to zip) to Download;
If you cannot log on to Google, you can also download it from my uploaded files:
Http://download.csdn.net/detail/sunmc1204953974/8888421
However, it is best to download the latest package from the official website, because it is not long before the package is released, and the upgrade is fast.
(2) Import CardboardSDKForUnity. unitypackage
Note that, for the SDK package downloaded earlier, there is only one CardboardSDKForUnity. unitypackage. After the package is imported, it contains support code and an example. The new SDK package downloaded from the official website contains CardboardSDKForUnity. unitypackage and CardboardSDKForUnity. unitypackage: the first package is the library, and the second package is the Demo. You can import the package to run the instance.
First open Unity, a New Project.
(Here I am using the latest Unity5, which has changed a lot compared with the previous version. At present, there are few materials, but many people have already used it .)
Then, use Assets> Import Package> Custom Package...
Introduce the downloaded SDK package. (As the red letter said before, the newly downloaded SDK package needs to be introduced twice)
(3) Run DemoScene
We can see that. after the unitypackage file is imported, a Cardboard folder will be added under the Resource folder of the Project panel. The Cardboard folder contains the SDK plug-in code and Demo sample. view the DemoScene folder in the Cardboard folder, this is one of the examples (there is another example in the Legacy folder, I will talk about it again when commenting on the code in later articles), double-click the scenario file DemoScene and open the example.
Click the run button (Small arrow) on the top to view the running effect of the Demo.
After running the command, press Alt to move the mouse to simulate the rotation of the head, press Ctrl to simulate the angle of view changes when the neck is tilted, and click the mouse to trigger the operation.
This Demo has the following functions:
Turn your eyes on the square with a small yellow dot. Click the mouse and the square will drive to a random position on a sphere with a limited distance.
When you look at the square, the square will change from red to green. When you look away from the square, the square will change from green to red.
There are three buttons Under your feet:
- Reset: place the Square back to its initial position.
- Recenter: re-align the Angle of View to the center
- VR Mode: Turn on or off the VR Mode (split screen or not)
We can see that this Demo code has only one file, and it is still very short. Just a few lines of scripts have achieved this effect (split screen, gyroscope, angle rotation ......), I have to say that the Cardboard SDK is still very powerful. In the future, I will write an article dedicated to analyzing this Demo and code to help you quickly understand how to use the Cardboard SDK.
When reading the code and development process, you can refer to the documentation on the official website. I will also send an English document and a document translated by the way when I read it myself, to help students who are not convenient with Google.
Then, set the AndroidSDK path, package and export it as an android project, and install it on your mobile phone. Then, you can feel it in Cardboard or in the final mirror such as the storm mirror ~ If the cell phone screen resolution is high, it still feels good.
Set AndroidSDK:
I will not elaborate on it here. There are a lot of online tutorials.
Export Android apk:
Note that you need to click the Player Settings under "prepare" and some Settings will appear on the right side. You must reset the package name here. Otherwise, the default package name cannot be packaged. You can also set the application icon, name, and so on.
The following figure shows the effect after the mobile phone is installed:
My mobile phone is relatively low in pixels, but it feels good to put it in the storm mirror. Next time, I will teach you how to create a scenario, put your model into the scenario, and use virtual reality glasses for viewing operations. In the future, I will analyze the Demo code and official documents, list methods that are often called in VR development, and how to further develop them. Coming soon ~
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.