---GEARVR SDK Code Analysis of the VR introductory series tutorial

Source: Internet
Author: User
GEARVR SDK code profiling Next, let's take a look at the underlying code for the GEARVR development package, which is very similar to the Desktop SDK code previously discussed in chapter three, and of course, there are many different places.
First, let's look at how to build a unity scene. In the development package, there is a preset body with a camera rig, which provides a Oculus stereo rendering technique and GEARVR matching head tracking technology.
Expand the Ovrcamerarig object in the hierarchy, which contains a Trackingspace sub object, Trackingspace below contains four sub objects: Lefteyeanchor, Centereyeanchor, Righteyeanchor and Trackeranchor. Where the left and right eye anchor is the key, select one and then the Inspector panel can see that it contains a camera component, this camera component has some default values, some values will be updated in the script code, let's look at these updated code.
Select the Ovrcamerarig object again, and then double hit the inspector in the panel to open the OVR Camera rig script. After the script opens, find the update function, as follows: [C #] Plain text view copy code? #if! unity_android | | Unity_editor private void Lateupdate () #else private void Update () #endif {Ensuregameobjectintegr          ity (); if (!          application.isplaying) return;          Updatecameras (); Updateanchors (); Because we build an application for Android, the #if statement evaluates to False, and the program uses the update function, which is called by unity in every frame that the program runs. In our update function, we first call the Ensuregameobjectintegrity function to ensure that the scene contains all the necessary objects, such as the Ovrcamerarig object is necessary.
    To ensure that the program is running, we begin a real update operation. First update the camera parameters, call the Updatecameras function to update the camera parameters of two eyes, the code is as follows: [c#]  plain text view   copy code? private void Updatecameras () {     if (needscameraconfigure)      {          Lefteyecamera = Configurecamera (ovreye.left);          Righteyecamera = Configurecamera (ovreye.right); #if! unity_android | | Unity_editor          needscameraconfigure = false; #endif     }}     The following code is to obtain the camera parameter function for each eye: [c#]  plain text view   copy code? Private Camera Configurecamera (Ovreye eye) {     Transform anchor = (eye = ovreye.left)? lefteyeanc Hor:righteyeanchor;      Camera cam = anchor. Getcomponent<camera> ();      Ovrdisplay.eyerenderdesc Eyedesc = OVRManager.display.GetEyeRenderDesc (eye);      Cam.fieldofview = eyedESC.FOV.Y;      cam.aspect = EYEDESC.RESOLUTION.X/EYEDESC.RESOLUTION.Y;      cam.rect = new Rect (0f, 0f, OVRManager.instance.virtualTextureScale,           OVRManager.instance.virtualTextureScale);      cam.targettexture = OVRManager.display.GetEyeTexture (eye);      CAM.HDR = OVRMANAGER.INSTANCE.HDR;      ...      return cam; In the     function, get the camera parameters of the left and right eyes accordingly according to the parameters passed in, in which we take a specific look at the following line of code: OVRMANAGER.DISPLAY.GETEYERENDERDESC (eye)         Ovrmanager This class is the main interface class for the Oculus Mobile SDK, which interacts with Android native code, and if you're interested in its internal implementation, you can go back to the Unity editor to select Ovrcamerarig, It then opens its OVR manager script for research. At this point, we use the SDK as the black box to obtain the left and right eye camera parameters, including: FOV, screen size ratio, viewport, render target and whether to support HDR.
The basic parameters of our camera have been set, but its coordinates and orientation must be acquired through the GEARVR header, implemented in the Updateanchors function: [C #] Plain text view copy code?      private void Updateanchors () {bool monoscopic = OVRManager.instance.monoscopic;      Ovrpose tracker = OVRManager.tracker.GetPose ();      Ovrpose Hmdlefteye = OVRManager.display.GetEyePose (ovreye.left);      Ovrpose Hmdrighteye = OVRManager.display.GetEyePose (ovreye.right);      Trackeranchor.localrotation = tracker.orientation; Centereyeanchor.localrotation = hmdlefteye.orientation;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.