LoginSignup
6
2

More than 5 years have passed since last update.

FirstVRでリセンターをする

Last updated at Posted at 2018-11-02

VRでは、コントローラと連動しているVR内のポインタやオブジェクトがずれていってしまうことってよくありますよね。

そのズレを直すリセンターの機能はHTC VIVEやOculusなどでもつけられていて、VRを快適に利用するためには必要不可欠な機能です。

FirstVRでももちろん、このリセンター機能が実装されています。
今回は、サンプルシーン内のサンプルコードを使って、FirstVRでのリセンターについて説明していきたいと思います。

SDKのダウンロード

FirstVRのSDKのダウンロードは、以下のリンクからできます。
https://dev.first-vr.com/downloads?locale=ja

ダウンロードには開発者サイトの無料会員登録が必要です。

リセンター

開発者サイトに登録すると、APIが見れるようになります。

API一覧によると、FVRConnectionのクラスにある
Recenter ()
という関数で、簡単にリセンター機能を実装することができるようです。

実装

サンプルとして入っているシーンを見てみましょう。

FVR/Samples/Scenesの中のOutputViewerを開きます。

リセンターされているのがわかりやすいように、Cubeを手に入れ替えてみました。
スクリーンショット 2018-10-22 19.28.29.png

SceneManagerにアタッチされているSampleViewerManager.csを読んでみると、
画面をタップするとリセンターされるようにかかれています。

SampleViewerManager.cs
using UnityEngine;
using FVRlib;
/// <summary>
/// This example shows how to use the First VR's rotation and how to set the center or no rotation point
/// </summary>
public class SampleViewerManager : MonoBehaviour {

    // FVR 
    public FVRConnection fvr;

    // vars
    public GameObject hand;
    bool touched = false;

    void Start () {
        hand = GameObject.Find("Hand_right");
    }


    void Update () {
        hand.transform.rotation = fvr.centeredRotation;

        /*** ここで、画面をタップするとリセンターされるようにしています ***/
        if (Input.touchCount == 1 && !touched) {
            fvr.Recenter ();
            touched = true;
        }
        if (Input.touchCount == 0 && touched) {         
            touched = false;
        }
    }
}

スマホで実行してみると、ちゃんとリセンターできているのがわかりますね!
File-from-iOS.gif

簡単に実装できるので、サンプルコードのようにタップだけでなく、いろんなアクションにリセンター機能を実装して活用できそうです。

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2