Fixing the altitude issue

You may notice an issue if you live above 500 meters above sea level. This issue happens because our AR camera is fixed at 500 meters altitude. The problem is that we have our AR camera at a fixed height; we now need to adjust that based on the camera's altitude. Open back up the editor and complete the following:

  1. Create a new C# script and replace the code with the following:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Packt.HoloCore
{
public class SceneCameraMover : MonoBehaviour
{
void Awake()
{
var altitude = SceneController.Instance.position.GetAltitude();
transform.position = new Vector3(0f, (float)altitude, 0f);
}
}
}
  1. This script creates a new class called SceneCameraMover. The job of SceneCameraMover is to move the AR camera into position when the view switches to AR / MR.
  2. Save the script and return to Unity.
  3. Open the Main scene from the Assets/HoloCore/Scenes folder.
  4. Expand HoloKitCameraRig and select VideoSeeThroughCamera. Then, add the script to the component using Add Component and searching for SceneCameraMover.
  5. Set the Transform on the HoloKitCameraRig to 0, 0, 0. We will now let the script move the camera to the position we need.
  1. Save the scenes and project.
  2. Connect, build, and run. Go to an area that is well above sea level, say the mountains, and switch to AR / MR view. The camera should now position itself correctly based on the altitude you were viewing the scene at.

Ensure that you explore other areas of interest around the world. In the next section, we will finish up the chapter and our discussion of AR and ARCore with the next steps, and we'll see where you can go to build your own incredible tech demo or commercial app.

The online example demos from WRLD recommend using an alternate streaming camera for AR visuals in ARCore or ARKit apps. However, we found that adding an alternate camera, alongside the already two additional cameras for the HoloKit, caused the app to be more unstable than it already can be. If you don't plan to use MR or HoloKit, you likely want to experiment with the alternate streaming camera.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.93.221