VR开发--CardboardSDK解析

虚拟成像原理


VR开发--CardboardSDK解析_第1张图片
Paste_Image.png

1、首先SDK里面有什么

VR开发--CardboardSDK解析_第2张图片
Paste_Image.png
VR开发--CardboardSDK解析_第3张图片
来源游戏蛮牛gmq517

Cardboard脚本解析

1-Cardboard.cs

这是提供访问底层方法的类.

VR开发--CardboardSDK解析_第4张图片
Paste_Image.png
VR开发--CardboardSDK解析_第5张图片
Paste_Image.png
VR开发--CardboardSDK解析_第6张图片
Paste_Image.png
VR开发--CardboardSDK解析_第7张图片
Paste_Image.png
VR开发--CardboardSDK解析_第8张图片
Paste_Image.png
VR开发--CardboardSDK解析_第9张图片
Paste_Image.png
2-CardboardEye.cs
using UnityEngine;

/// in order to reset its cache.
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Cardboard/CardboardEye")]
public class CardboardEye : MonoBehaviour {
  /// Whether this is the left eye or the right eye.
  /// Determines which stereo eye to render, that is, which `EyeOffset` and
  /// `Projection` matrix to use and which half of the screen to render to.
  /// 确定要渲染的立体眼睛,就是用EyeOffset和projecttion 矩阵并且去渲染到屏幕的哪一半
  public Cardboard.Eye eye;

  /// Allows you to flip on or off specific culling mask layers for just this
  /// eye.  The mask is a toggle:  The eye's culling mask is first copied from
  /// the parent mono camera, and then the layers specified here are flipped.
  /// Each eye has its own toggle mask.
  /// 允许你为这个眼睛打开或关闭特定的剔除层.是一个触发器,这个层首先从父相机复制,然后在此制定那些层被启用,每只眼睛有它自己的剔除层
  [Tooltip("Culling mask layers that this eye should toggle relative to the parent camera.")]
  public LayerMask toggleCullingMask = 0;

    /// The StereoController in charge of this eye (and whose mono camera
    /// we will copy settings from).
    /// 返回StereoController 控制这个眼睛
    public StereoController Controller {
    // This property is set up to work both in editor and in player.
    get {
      if (transform.parent == null) { // Should not happen.
        return null;
      }
      if ((Application.isEditor && !Application.isPlaying) || controller == null) {
        // Go find our controller.
        return transform.parent.GetComponentInParent();
      }
      return controller;
    }
  }

    /// Returns the closest ancestor CardboardHead.
    /// @note Uses GetComponentInParent(), so the result will be null if no active ancestor is found.
    /// 返回父类CardboardHead
    public CardboardHead Head {
    get {
      return GetComponentInParent();
    }
  }
3-CardboardHead.cs

将此脚本附加到任何与用户头部运动相匹配的游戏对象上。也就是说Head模拟了现实中用户的头,Head下的部分都是头的一部分.
里面有:
Main Camera与GazePointer
Main Camera就是我们的视野,左右眼睛.
GazePointer其实就是视野注视点的实体,将这个注视点作为头部的一部分,跟随头部旋转.

VR开发--CardboardSDK解析_第10张图片
1
VR开发--CardboardSDK解析_第11张图片
2
4-GazeInputModule.cs

提供了一个Unity的BaseInputModule类的实现,使得UGUI可以通过触发与触摸的方式来选择和使用

VR开发--CardboardSDK解析_第12张图片
Paste_Image.png

Cardboard 的UI 系统是基于UGUI制作的.
我们在上一篇项目 http://www.jianshu.com/p/3696bc837551
里面应该已经看到,我们修改并将GazeInputModule.cs脚本添加到EventSystem中

GazeInputModule:

这个脚本控制人眼视角发射的射线并触发相应的事件。

 public override void Process() {
    // Save the previous Game Object
    GameObject gazeObjectPrevious = GetCurrentGameObject();

    CastRayFromGaze();   // 控制射线发射,先将3D坐标转换为2D UI坐标系,发出射线
    UpdateCurrentObject(); // 更新选中物体的状态,比如按钮会设置选中状态等
    UpdateReticle(gazeObjectPrevious); // 

    // Get the camera
    Camera camera = pointerData.enterEventCamera;

    // Handle input
    if (!Cardboard.SDK.TapIsTrigger && !Input.GetMouseButtonDown(0) && Input.GetMouseButton(0)) {
      // Drag is only supported if TapIsTrigger is false.
      HandleDrag();           // 拖动状态
    } else if (Time.unscaledTime - pointerData.clickTime < clickTime) {
      // Delay new events until clickTime has passed.
    } else if (!pointerData.eligibleForClick &&
               (Cardboard.SDK.Triggered || !Cardboard.SDK.TapIsTrigger && Input.GetMouseButtonDown(0))) {
     
      HandleTrigger();           //触发事件
      if (cardboardPointer != null) {
        cardboardPointer.OnGazeTriggerStart(camera);
      }
    } else if (!Cardboard.SDK.Triggered && !Input.GetMouseButton(0)) {
      HandlePendingClick(); // 就是光标选中,啥也没干
    }
  }
5-StereoController.cs
VR开发--CardboardSDK解析_第13张图片
1
VR开发--CardboardSDK解析_第14张图片
2
VR开发--CardboardSDK解析_第15张图片
3
VR开发--CardboardSDK解析_第16张图片
4
VR开发--CardboardSDK解析_第17张图片
5
VR开发--CardboardSDK解析_第18张图片
6

你可能感兴趣的:(VR开发--CardboardSDK解析)