/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
namespace NRKernal
{
using System;
using System.Collections.Generic;
using UnityEngine;
/// A plane in the real world detected by NRInternel.
public class NRTrackablePlane : NRTrackable
{
internal NRPlaneSubsystem PlaneSubsystem
{
get
{
return NRSessionManager.Instance.TrackableFactory.PlaneSubsystem;
}
}
/// Constructor.
/// Handle of the native.
/// The native interface.
internal NRTrackablePlane(UInt64 nativeHandle) : base(nativeHandle)
{
}
/// Type of the trackable plane.
TrackablePlaneType trackablePlaneType;
/// Get the plane type.
/// Plane type.
public TrackablePlaneType GetPlaneType()
{
if (NRFrame.SessionStatus != SessionState.Running)
{
return trackablePlaneType;
}
trackablePlaneType = PlaneSubsystem.GetPlaneType(TrackableNativeHandle);
return trackablePlaneType;
}
/// The center pose.
Pose centerPose;
///
/// Gets the position and orientation of the plane's center in Unity world space.
/// The center pose.
public override Pose GetCenterPose()
{
if (NRFrame.SessionStatus != SessionState.Running)
{
return centerPose;
}
centerPose = PlaneSubsystem.GetCenterPose(TrackableNativeHandle);
return ConversionUtility.ApiWorldToUnityWorld(centerPose);
}
///
/// Gets the extent of plane in the X dimension, centered on the plane position.
/// The extent x coordinate.
public float ExtentX
{
get
{
if (NRFrame.SessionStatus != SessionState.Running)
{
return 0;
}
return PlaneSubsystem.GetExtentX(TrackableNativeHandle);
}
}
///
/// Gets the extent of plane in the Z dimension, centered on the plane position.
/// The extent z coordinate.
public float ExtentZ
{
get
{
if (NRFrame.SessionStatus != SessionState.Running)
{
return 0;
}
return PlaneSubsystem.GetExtentZ(TrackableNativeHandle);
}
}
///
/// Gets a list of points(in clockwise order) in plane coordinate representing a boundary polygon
/// for the plane.
/// polygonList A list used to be filled with polygon points.
public void GetBoundaryPolygon(List polygonList)
{
if (NRFrame.SessionStatus != SessionState.Running)
{
return;
}
var planetype = GetPlaneType();
if (planetype == TrackablePlaneType.INVALID)
{
NRDebugger.Error("Invalid plane type.");
return;
}
PlaneSubsystem.GetBoundaryPolygon(TrackableNativeHandle, polygonList);
}
}
}