Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Only apply default head height if not managed by device #657

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public interface IMixedRealityCameraDataProvider : IMixedRealityDataProvider
/// </summary>
bool IsStereoscopic { get; }

/// <summary>
/// Is the head height, and thus the camera y-position, managed by the device itself?
/// If true, the <see cref="DefaultHeadHeight"/> setting is ignored and has no effect
/// on camera positioning.
/// </summary>
bool HeadHeightIsManagedByDevice { get; }

/// <summary>
/// The <see cref="IMixedRealityCameraRig"/> reference for this data provider.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using UnityEngine;
using UnityEngine.XR;
using XRTK.Definitions.CameraSystem;
using XRTK.Extensions;
using XRTK.Interfaces.CameraSystem;
Expand Down Expand Up @@ -85,6 +86,9 @@ public BaseCameraDataProvider(string name, uint priority, BaseMixedRealityCamera
/// <inheritdoc />
public virtual bool IsStereoscopic => CameraRig.PlayerCamera.stereoEnabled;

/// <inheritdoc />
public virtual bool HeadHeightIsManagedByDevice => XRDevice.isPresent;

/// <inheritdoc />
public IMixedRealityCameraRig CameraRig { get; private set; }

Expand Down Expand Up @@ -239,7 +243,11 @@ public override void Destroy()
/// </summary>
protected virtual void ApplySettingsForDefaultHeadHeight()
{
HeadHeight = DefaultHeadHeight;
if (!HeadHeightIsManagedByDevice)
{
HeadHeight = DefaultHeadHeight;
}

ResetRigTransforms();
SyncRigTransforms();
}
Expand Down Expand Up @@ -274,8 +282,10 @@ protected virtual void ResetRigTransforms()
{
CameraRig.PlayspaceTransform.position = Vector3.zero;
CameraRig.PlayspaceTransform.rotation = Quaternion.identity;
// If the camera is a 2d camera when we can adjust the camera's height to match the head height.

// If the camera is a 2d camera then we can adjust the camera's height to match the head height.
CameraRig.CameraTransform.position = IsStereoscopic ? Vector3.zero : new Vector3(0f, HeadHeight, 0f);

CameraRig.CameraTransform.rotation = Quaternion.identity;
CameraRig.BodyTransform.position = Vector3.zero;
CameraRig.BodyTransform.rotation = Quaternion.identity;
Expand Down